20141030-1 选题

This commit is contained in:
DeadFire 2014-10-30 15:33:57 +08:00
parent ac2fb8d8ed
commit 3526fb4c91
3 changed files with 484 additions and 0 deletions

View File

@ -0,0 +1,58 @@
Suse enterprise Linux can take your system back in time
================================================================================
> Suse Linux Enterprise Server 12 features a new system snapshot and rollback capability
The newest enterprise edition of the Suse Linux distribution allows administrators to go back in time, for instance, to immediately before they made that fatal system-crippling mistake.
Suse Linux Enterprise Server 12 (SLES 12) features a system snapshot and rollback capability that allows the user to boot the system to an earlier configuration, should the latest one unexpectedly fail.
Such a capability can be handy for undoing a system configuration change that did not turn out as expected. For instance, an administrator might have the SLES computer in a perfectly fine running state, but then install a botched software update, or make a change that destroys the kernel. Typically, Unix systems have been unforgiving about such mistakes, forcing the administrator to reinstall the system software from scratch, should they not know how to undo the unfortunate change.
"This stuff happens, for whatever reason," said Matthias Eckermann, Suse senior product manager. "So the admin has an emergency exit, so to speak."
Users of Microsoft Windows and Apple Macintosh systems have long enjoyed rollback functionality within their respective OSes, but this capability had been missing in Unix-based systems such as Linux, at least as a native function of the OS.
For this functionality, the Suse team used the [Btrfs][1] file system (B-tree file system, often pronounced as "Butter FS"), an open-source file system developed by Oracle engineer Chris Mason ([now at Facebook][2]). Mason created Btrfs to address emerging enterprise requirements such as the ability to make snapshots and to scale across multiple storage nodes.
Although Btrfs is supported in the mainline Linux kernel, SLES is the first major Linux distribution to use Btrfs as the default file system. "Over the last five years, we specifically focused on making Btrfs enterprise-ready," Eckermann said.
The rollback capability also relies on the open-source tool [Snapper][3], first developed by Suse, to manage the snapshots.
The Suse team integrated Snapper with SLES so that users now have the ability, when the OS is first being loaded, to boot into an earlier snapshot of the system. "Whoever installs SLES 12 gets this capability by default," Eckermann said.
SLES also integrated Btrfs with the [Samba Windows file server][4], which makes Linux files accessible to Windows machines. For Windows users, SLES can now make multiple snapshots of a file appear as different versions of a file, which are all accessible.
Initially, Enterprise Suse supports rollbacks for only system changes, though users can also deploy it to handle changes in a user's home directory, in which data is typically kept. "We already have it running, but it is not supported," Eckermann said. Users can continue to use ext3, ext4 or some other traditional Linux file system as their default.
SLES 12, released Monday, comes with a number of other features as well. Like other distributions, SLES has [caught the fever for Docker containers][5] and now comes with a built-in framework to run this virtualization technology. For the first time, the package also provides geo-clustering, which allows the user to build replicate clusters across different geographic regions.
An organization could use geo-clustering, for instance, to set up multiple copies of a single cluster in data centers around the world, so if one or more regions go offline, the others can continue operations unabated, Eckermann said.
Suse [is among the world's most widely used distributions][6] of Linux, along with Ubuntu/Debian, and Red Hat Enterprise Linux. A free version is available under OpenSuse and Suse Linux offers a commercial edition packaged for enterprise usage.
Suse Linux's parent company, Attachmate, is in the process of merging with Micro Focus. Eckermann expects no major changes in the operations of Suse Linux resulting from the new ownership.
SLES 12 is [offered at an annual subscription][7] of US$349 per server. A free 60-day trial is also available.
![](http://images.techhive.com/images/article/2014/10/sle_12_installed_system_08_snapper_gui-2-100527225-large.idge.png)
Through the combined powers of the Btrfs file system and the Snapper utility, SUSE Enterprise Linux can now take snapshots of the system, and roll back to an earlier configuration if necessary.
--------------------------------------------------------------------------------
via: http://www.computerworld.com/article/2838950/suse-enterprise-linux-can-take-your-system-back-in-time.html
作者:[Joab Jackson][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://www.computerworld.com/author/Joab-Jackson/
[1]:https://btrfs.wiki.kernel.org/index.php/Main_Page
[2]:http://www.phoronix.com/scan.php?page=news_item&px=MTUzNTE
[3]:http://snapper.io/
[4]:http://www.samba.org/
[5]:http://www.pcworld.com/article/2838452/canonical-celebrates-cloud-freedoms-with-new-ubuntu.html
[6]:http://distrowatch.com/table.php?distribution=suse
[7]:https://www.suse.com/products/server/how-to-buy/

View File

@ -0,0 +1,288 @@
8 Tips to Solve Linux & Unix Systems Hard Disk Problmes Like Disk Full Or Cant Write to the Disk
================================================================================
Can't write to the hard disk on a Linux or Unix-like systems? Want to diagnose corrupt disk issues on a server? Want to find out why you are getting "disk full" messages on screen? Want to learn how to solve full/corrupt and failed disk issues. Try these eight tips to diagnose a Linux and Unix server hard disk drive problems.
![](http://s0.cyberciti.org/uploads/cms/2014/10/welcome-0-disk-problems.001.jpg)
### #1 - Error: No space left on device ###
When the Disk is full on Unix-like system you get an error message on screen. In this example, I'm running [fallocate command][1] and my system run out of disk space:
$ fallocate -l 1G test4.img
fallocate: test4.img: fallocate failed: No space left on device
The first step is to run the df command to find out information about total space and available space on a file system including partitions:
$ df
OR try human readable output format:
$ df -h
Sample outputs:
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 117G 54G 57G 49% /
udev 993M 4.0K 993M 1% /dev
tmpfs 201M 264K 200M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 1002M 0 1002M 0% /run/shm
/dev/sda1 1.8G 115M 1.6G 7% /boot
/dev/sda7 4.7G 145M 4.4G 4% /tmp
/dev/sda9 9.4G 628M 8.3G 7% /var
/dev/sda8 94G 579M 89G 1% /ftpusers
/dev/sda10 4.0G 4.0G 0 100% /ftpusers/tmp
From the df command output it is clear that /dev/sda10 has 4.0Gb of total space of which 4.0Gb is used.
#### Fixing problem when the disk is full ####
1.[Compress uncompressed log and other files][2] using gzip or bzip2 or tar command:
gzip /ftpusers/tmp/*.log
bzip2 /ftpusers/tmp/large.file.name
2.Delete [unwanted files using rm command][3] on a Unix-like system:
m -rf /ftpusers/tmp/*.bmp
3.Move files to other [system or external hard disk using rsync command][4]:
rsync --remove-source-files -azv /ftpusers/tmp/*.mov /mnt/usbdisk/
rsync --remove-source-files -azv /ftpusers/tmp/*.mov server2:/path/to/dest/dir/
4.[Find out the largest directories or files eating disk space][5] on a Unix-like systesm:
du -a /ftpusers/tmp | sort -n -r | head -n 10
du -cks * | sort -rn | head
5.[Truncate a particular file][6]. This is useful for log file:
truncate -s 0 /ftpusers/ftp.upload.log
### bash/sh etc ##
>/ftpusers/ftp.upload.log
## perl ##
perl -e'truncate "filename", LENGTH'
6.Find and remove large files that are open but have been deleted on Linux or Unix:
## Works on Linux/Unix/OSX/BSD etc ##
lsof -nP | grep '(deleted)'
## Only works on Linux ##
find /proc/*/fd -ls | grep '(deleted)'
To truncate it:
## works on Linux/Unix/BSD/OSX etc all ##
> "/path/to/the/deleted/file.name"
## works on Linux only ##
> "/proc/PID-HERE/fd/FD-HERE"
### #2 - Is the file system is in read-only mode? ###
You may end up getting an error such as follows when you try to create a file or save a file:
$ cat > file
-bash: file: Read-only file system
Run mount command to find out if the file system is mounted in read-only mode:
$ mount
$ mount | grep '/ftpusers'
To fix this problem, simply remount the file system in read-write mode on a Linux based system:
# mount -o remount,rw /ftpusers/tmp
Another example, from my [FreeBSD 9.x server to remount / in rw mode][7]:
# mount -o rw /dev/ad0s1a /
### #3 - Am I running out of inodes? ###
Sometimes, df command reports that there is enough free space but system claims file-system is full. You need to check [for the inode][8] which identifies the file and its attributes on a file systems using the following command:
$ df -i
$ df -i /ftpusers/
Sample outputs:
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda8 6250496 11568 6238928 1% /ftpusers
So /ftpusers has 62,50,496 total inodes but only 11,568 are used. You are free to create another 62,38,928 files on /ftpusers partition. If 100% of your inodes are used, try the following options:
- Find unwanted files and delete or move to another server.
- Find unwanted large files and delete or move to another server.
### #4 - Is my hard drive is dying? ###
[I/O errors in log file (such as /var/log/messages) indicates][9] that something is wrong with the hard disk and it may be failing. You can check hard disk for errors using smartctl command, which is control and monitor utility for SMART disks under Linux and UNIX like operating systems. The syntax is:
smartctl -a /dev/DEVICE
# check for /dev/sda on a Linux server
smartctl -a /dev/sda
You can also use "Disk Utility" to get the same information
[![](http://s0.cyberciti.org/uploads/l/tips/2007/07/500-GB-Hard-Disk-ATA-TOSHIBA-MK5061GSYF-dev-sda-%E2%80%94-Disk-Utility_014.png)][10]
Fig. 01: Gnome disk utility (Applications > System Tools > Disk Utility)
> **Note**: Don't expect too much from SMART tool. It may not work in some cases. Make backup on a regular basis.
### #5 - Is my hard drive and server is too hot? ###
High temperatures can cause server to function poorly. So you need to maintain the proper temperature of the server and disk. High temperatures can result into server shutdown or damage to file system and disk. [Use hddtemp or smartctl utility to find out the temperature of your hard on a Linux or Unix based system][11] by reading data from S.M.A.R.T. on drives that support this feature. Only modern hard drives have a temperature sensor. hddtemp supports reading S.M.A.R.T. information from SCSI drives too. hddtemp can work as simple command line tool or as a daemon to get information from all servers:
hddtemp /dev/DISK
hddtemp /dev/sg0
Sample outputs:
[![](http://s0.cyberciti.org/uploads/cms/2014/10/hddtemp-on-rhel-300x85.jpg)][12]
Fig.02: hddtemp in action
You can use the smartctl command as follows too:
smartctl -d ata -A /dev/sda | grep -i temperature
#### How do I get the CPU temperature? ####
You can use Linux hardware monitoring tool such as [lm_sensor to get the cpu temperature on a Linux based][13] system:
sensors
Sample outputs from Debian Linux server:
[![](http://s0.cyberciti.org/uploads/cms/2014/10/sensors-command-on-debian-server.jpg)][14]
Fig.03: sensors command providing cpu core temperature and other info on a Linux
### #6 - Dealing with corrupted file systems ###
File system on server may be get corrupted due to a hard reboot or some other error such as bad blocks. You can [repair corrupted file systems with the following fsck command][15]:
umount /ftpusers
fsck -y /dev/sda8
See [how to surviving a Linux filesystem failures][16] for more info.
### #7 - Dealing with software RAID on a Linux ###
To find the current status of a Linux software raid type the following command:
## get detail on /dev/md0 raid ##
mdadm --detail /dev/md0
## Find status ##
cat /proc/mdstat
watch cat /proc/mdstat
Sample outputs:
[![](http://s0.cyberciti.org/uploads/cms/2014/10/linux-mdstat-output.jpg)][17]
Fig. 04: Find the status of a Linux software raid command
You need to replace a failed hard drive. You must u remove the correct failed drive. In this example, I'm going to replace /dev/sdb (2nd hard drive of RAID 6). It is not necessary to take the storage offline to repair the RAID on Linux. This only works if your server support hot-swappable hard disk:
## remove disk from an array md0 ##
mdadm --manage /dev/md0 --fail /dev/sdb1
mdadm --manage /dev/md0 --remove /dev/sdb1
# Do the same steps again for rest of /dev/sdbX ##
# Power down if not hot-swappable hard disk: ##
shutdown -h now
## copy partition table from /dev/sda to newly replaced /dev/sdb ##
sfdisk -d /dev/sda | sfdisk /dev/sdb
fdisk -l
## Add it ##
mdadm --manage /dev/md0 --add /dev/sdb1
# do the same steps again for rest of /dev/sdbX ##
# Now md0 will sync again. See it on screen ##
watch cat /proc/mdstat
See our [tips on increasing RAID sync speed on Linux][18] for more information.
### #8 - Dealing with hardware RAID ###
You can use the samrtctl command or vendor specific command to find out the status of RAID and disks in your controller:
## SCSI disk
smartctl -d scsi --all /dev/sgX
## Adaptec RAID array
/usr/StorMan/arcconf getconfig 1
## 3ware RAID Array
tw_cli /c0 show
See your vendor specific documentation to replace a failed disk.
### Monitoring disk health ###
See our previous tutorials:
1. [Monitoring hard disk health with smartd under Linux or UNIX operating systems][19]
1. [Shell script to watch the disk space][20]
1. [UNIX get an alert when disk is full][21]
1. [Monitor UNIX / Linux server disk space with a shell scrip][22]
1. [Perl script to monitor disk space and send an email][23]
1. [NAS backup server disk monitoring shell script][24]
### Conclusion ###
I hope these tips will help you troubleshoot system disk issue on a Linux/Unix based server. I also recommend implementing a good backup plan in order to have the ability to recover from disk failure, accidental file deletion, file corruption, or complete server destruction:
- [Debian / Ubuntu: Install Duplicity for encrypted backup in cloud][25]
- [HowTo: Backup MySQL databases, web server files to a FTP server automatically][26]
- [How To Set Red hat & CentOS Linux remote backup / snapshot server][27]
- [Debian / Ubuntu Linux install and configure remote filesystem snapshot with rsnapshot incremental backup utility][28]
- [Linux Tape backup with mt And tar command tutorial][29]
--------------------------------------------------------------------------------
via: http://www.cyberciti.biz/datacenter/linux-unix-bsd-osx-cannot-write-to-hard-disk/
作者:[nixCraft][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://www.cyberciti.biz/tips/about-us
[1]:http://www.cyberciti.biz/faq/howto-create-lage-files-with-dd-command/
[2]:http://www.cyberciti.biz/howto/question/general/compress-file-unix-linux-cheat-sheet.php
[3]:http://www.cyberciti.biz/faq/howto-linux-unix-delete-remove-file/
[4]:http://www.cyberciti.biz/faq/linux-unix-bsd-appleosx-rsync-delete-file-after-transfer/
[5]:http://www.cyberciti.biz/faq/how-do-i-find-the-largest-filesdirectories-on-a-linuxunixbsd-filesystem/
[6]:http://www.cyberciti.biz/faq/truncate-large-text-file-in-unix-linux/
[7]:http://www.cyberciti.biz/faq/howto-freebsd-remount-partition/
[8]:http://www.cyberciti.biz/tips/understanding-unixlinux-filesystem-inodes.html
[9]:http://www.cyberciti.biz/tips/linux-find-out-if-harddisk-failing.html
[10]:http://www.cyberciti.biz/tips/linux-find-out-if-harddisk-failing.html
[11]:http://www.cyberciti.biz/tips/howto-monitor-hard-drive-temperature.html
[12]:http://www.cyberciti.biz/datacenter/linux-unix-bsd-osx-cannot-write-to-hard-disk/attachment/hddtemp-on-rhel/
[13]:http://www.cyberciti.biz/faq/howto-linux-get-sensors-information/
[14]:http://www.cyberciti.biz/datacenter/linux-unix-bsd-osx-cannot-write-to-hard-disk/attachment/sensors-command-on-debian-server/
[15]:http://www.cyberciti.biz/tips/repairing-linux-ext2-or-ext3-file-system.html
[16]:http://www.cyberciti.biz/tips/surviving-a-linux-filesystem-failures.html
[17]:http://www.cyberciti.biz/datacenter/linux-unix-bsd-osx-cannot-write-to-hard-disk/attachment/linux-mdstat-output/
[18]:http://www.cyberciti.biz/tips/linux-raid-increase-resync-rebuild-speed.html
[19]:http://www.cyberciti.biz/tips/monitoring-hard-disk-health-with-smartd-under-linux-or-unix-operating-systems.html
[20]:http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html
[21]:http://www.cyberciti.biz/faq/mac-osx-unix-get-an-alert-when-my-disk-is-full/
[22]:http://bash.cyberciti.biz/monitoring/shell-script-monitor-unix-linux-diskspace/
[23]:http://www.cyberciti.biz/tips/howto-write-perl-script-to-monitor-disk-space.html
[24]:http://bash.cyberciti.biz/backup/monitor-nas-server-unix-linux-shell-script/
[25]:http://www.cyberciti.biz/faq/duplicity-installation-configuration-on-debian-ubuntu-linux/
[26]:http://www.cyberciti.biz/tips/how-to-backup-mysql-databases-web-server-files-to-a-ftp-server-automatically.html
[27]:http://www.cyberciti.biz/faq/redhat-cetos-linux-remote-backup-snapshot-server/
[28]:http://www.cyberciti.biz/faq/linux-rsnapshot-backup-howto/
[29]:http://www.cyberciti.biz/faq/linux-tape-backup-with-mt-and-tar-command-howto/

View File

@ -0,0 +1,138 @@
How to run SQL queries against Apache log files on Linux
================================================================================
One of the distinguishing features of Linux is that, under normal circumstances, you should be able to know what is happening and has happened on your system by analyzing one or more system logs. Indeed, system logs are the first resource a system administrator tends to look to while troubleshooting system or application issues. In this article, we will focus on the Apache access log files generated by Apache HTTP web server. We will explore an alternative way of analyzing Apache access logs using [asql][1], an open-source tool that allows one to run SQL queries against the logs in order to view the same information in a more friendly format.
### Background on Apache Logs ###
There are two kinds of Apache logs:
- **Access log**: Found at /var/log/apache2/access.log (for Debian) or /var/log/httpd/access_log (for Red Hat). Contains records of every request served by an Apache web server.
- **Error log**: Found at /var/log/apache2/error.log (for Debian) or /var/log/httpd/error_log (for Red Hat). Contains records of all error conditions reported by an Apache web server. Error conditions include, but are not limited to, 403 (Forbidden, usually returned after a valid request missing access credentials or insufficient read permissions), and 404 (Not found, returned when the requested resource does not exist).
Although the verbosity of Apache access log file can be customized through Apache's configuration files, we will assume the default format in this article, which is as follows:
Remote IP - Request date - Request type - Response code - Requested resource - Remote browser (may also include operating system)
So a typical Apache log entry looks like:
192.168.0.101 - - [22/Aug/2014:12:03:36 -0300] "GET /icons/unknown.gif HTTP/1.1" 200 519 "http://192.168.0.10/test/projects/read_json/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0"
But what about Apache error log? Since error log entries dealing with particular requests have corresponding entries in the access log (which you can customize), you can use the access log file to obtain more information about error conditions (refer to example 5 for more details).
That being said, please note that access log is a system-wide log file. To find the log files of virtual hosts, you may also need to check their corresponding configuration files (e.g., within /etc/apache2/sites-available/[virtual host name] on Debian).
### Installing asql on Linux ###
asql is written in Perl, and requires two Perl modules: a DBI driver for SQLite and GNU readline.
#### Install asql on Debian, Ubuntu or their derivatives ####
asql and its dependencies will automatically be installed with aptitude on Debian-based distributions.
# aptitude install asql
#### Install asql on Fedora, CentOS or RHEL ####
On CentOS or RHEL, you will need to enable [EPEL repository][2] first, and then run the commands below. On Fedora, proceed to the following commands directly.
# sudo yum install perl-DBD-SQLite perl-Term-ReadLine-Gnu
# wget http://www.steve.org.uk/Software/asql/asql-1.7.tar.gz
# tar xvfvz asql-1.7.tar.gz
# cd asql
# make install
### How Does asql Work? ###
As you can guess from the dependencies listed above, asql converts unstructured plain-text Apache log files into a structured SQLite database, which can be queried using standard SQL commands. This database can be populated with the contents of current and past log files - including compressed rotated logs such as access.log.X.gz. or access_log.old.
First, launch asql from the command line with the following command
# asql
You will be entering asql's built-in shell interface.
![](https://farm8.staticflickr.com/7493/15477783969_ebedc61afc_o.png)
Let's type help to list the available commands in the asql shell:
![](https://farm8.staticflickr.com/7471/15478852650_ffed84ddc2_o.png)
We will begin by loading all the access logs in asql, which can be done with:
asql> load </path/to/apache-access-logs>
In case of Debian, the following command will do:
asql> load /var/log/apache2/access.*
In case of CentOS/RHEL, use this command instead:
asql> load /var/log/httpd/access_log*
When asql finishes loading access logs, we can start querying the database. Note that the database created after loading is "temporary," meaning that if you exit the asql shell, the database will be lost. If you want to preserve the database, you have to save it to a file first. We will see how to do that later (refer to examples 3 and 4).
![](https://farm8.staticflickr.com/7489/15044293173_f21e38692b_o.png)
The database contains a table named logs. The available fields in the logs table can be displayed using the show command:
![](https://farm4.staticflickr.com/3955/15664433685_465e8f47bd_o.png)
The .asql hidden file, which is stored in each user's home directory, records the history of the commands that were typed by the user in an asql shell. Thus, you can browse through it using the arrow keys, and repeat previous commands by just pressing ENTER when you find the right one.
### SQL Query Examples with asql ###
Here a few examples of running SQL queries against Apache log files with asql.
**Example 1**: Listing the request sources / dates and HTTP status codes returned during the month of October 2014.
SELECT source, date, status FROM logs WHERE date >= '2014-10-01T00:00:00' ORDER BY source;
![](https://farm8.staticflickr.com/7488/15664433665_dde4ac1319_z.jpg)
**Example 2**: Displaying the total size (in bytes) of requests served per client in descending order.
SELECT source,SUM(size) AS Number FROM logs GROUP BY source ORDER BY Number DESC;
![](https://farm4.staticflickr.com/3938/15478271548_369541b56c_z.jpg)
**Example 3**: Saving the database to [filename] in the current working directory.
save [filename]
![](https://farm8.staticflickr.com/7576/15664433645_16510d8938_o.png)
This allows us to avoid the need for waiting while the log parsing is performed with the load command as shown earlier.
**Example 4**: Restoring the database in a new asql session after exiting the current one.
restore [filename]
![](https://farm4.staticflickr.com/3941/15664433635_737e714780_o.png)
**Example 5**: Returning error conditions logged in the access file. In this example, we will display all the requests that returned a 403 (access forbidden) HTTP code.
SELECT source,date,status,request FROM logs WHERE status='403' ORDER BY date
![](https://farm8.staticflickr.com/7551/15478271518_0444582a3d_z.jpg)
This goes to show that although asql only analyzes access logs, we can use the status field of a request to display requests with error conditions.
### Summary ###
We have seen how asql can help us analyze Apache logs and present the results in a user friendly output format. Although you could obtain similar results by using command line utilities such as cat in conjunction with grep, uniq, sort, and wc (to name a few), in comparison asql represents a Swiss army knife due to the fact that it allows us to use standard SQL syntax to filter the logs according to our needs.
Feel free to leave your questions or comments below. Hope it helps.
--------------------------------------------------------------------------------
via: http://xmodulo.com/sql-queries-apache-log-files-linux.html
作者:[Gabriel Cánepa][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://xmodulo.com/author/gabriel
[1]:http://www.steve.org.uk/Software/asql/
[2]:http://xmodulo.com/how-to-set-up-epel-repository-on-centos.html