Prakash Sawarkar: Kernel 3.8 Released, how to Compile in Redhat, CenOS and Fedora..

Kernel 3.8 Released, how to Compile in Redhat, CentOS and Fedora.

Wednesday, 1 April 2009

How to speed up SSH login?

Whenever I login to my Centos Server using SSH, it takes about 6 seconds for me to get the prompt for password, however when I login to my web hosting server it takes about 1 second. What can I do to speed this up?

If you run a lot of terminal tabs or scripts that all need to make OpenSSH connections to the same server, you can speed them all up with multiplexing: making the first one act as the master and letting the others share its TCP connection to the server.

If you don't already have a config file in the .ssh directory in your home directory, create it with permissions 600: readable and writeable only by you.
Speed up SSH 

Step 1 -Add below to /etc/ssh/sshd_config

The number one reason I've seen for this is a configuration option in SSHD UseDNS this option (enabled by default) causes the server to perform DNS resolution on the incoming requests. A time consuming operation. I've seen logins go from one minute plus waiting for password 


#  vi /etc/ssh/sshd_config

UseDNS no
Step 2- Setting up ssh client with compression 

#  vi /etc/ssh/ssh_config

Host *
Ciphers arcfour,blowfish-cbc
Compression yes
AddressFamily inet
ControlMaster auto
ControlPath ~/.ssh/socket-%r@%h:%p

Save and exit !
Step 3- Restart the SSH daemon with service sshd restart

You should see an improvement next time you connect.

Wednesday, 25 March 2009

Linux EXT2/EXT3 Superblock Recovery

Each file system has one superblock, which contains information about file system such as file system type, size, status and information about other metadata structures. If it lost, you would be in trouble so Linux maintains multiple redundant copies of the superblock in every file system.

I read the article “Surviving a Linux Filesystem Failures” on nixCraft, and did the test that destroyed and also recovered the ext2 and ext3 filesystem superblock on RHEL/Centos. The following is the steps.

EXT2 filesystem

In my machine, there is an ext2 filesystem /dev/sda6 which its mount point is /fs2.

Firstly, I should know the location of superblocks and the size of block.
[root@localhost ~]#   dumpe2fs /dev/sda6 | grep –i superblock
dumpe2fs 1.40.8 (23-Mar-2009)
  Primary superblock at 1, Group descriptors at 2-2
  Backup superblock at 8193, Group descriptors at 8194-8194
  Backup superblock at 24577, Group descriptors at 24578-24578
  Backup superblock at 40961, Group descriptors at 40962-40962
  Backup superblock at 57345, Group descriptors at 57346-57346
  Backup superblock at 73729, Group descriptors at 73730-73730
[root@localhost ~]#   dumpe2fs /dev/sda6 | grep –i ‘block size’
dumpe2fs 1.40.8 (23-Mar-2009)
Block size:                               1024 

From the above, I knew there are 5 backup superblocks and the block size is 1024 bytes. The location of primary superblock is at 1. The locations of these 5 backup superblocks are at 8193,24577,40961,57345 and 73729 respectively. If you want to know the filesystem’s block size, there are another two ways that you can use tune2fs and ext3grep commands. For example,
[root@localhost ~]#   tune2fs –l dev/sda6 | grep –i ‘block size’
[root@localhost ~]#   ext3grep /dev/sda6 | grep –i ‘block size’ 

Then, I destroyed the superblock as below.
[root@localhost ~]#   dd if=/dev/zero count=1 bs=1024 seek=1 of=/dev/sda6 

I checked the effect, and found I still could change to /fs2 directory. I could still list its contents. But the system gave me error messages when I tried to create a file or copy files.
[root@localhost ~]#   cd /fs2
[root@localhost ~]#   ll
total 19
drwx—— 2 root root 12288 2009-03-22 08:57 lost+found
-rw-r—r—1 root root   135 2009-03-22 18:15 qaz
 … … 

[root@localhost fs2]#  cp qaz wsx
cp: overwrite  `wsx’? y
cp: writing `wsx’: No space left on device
 [root@localhost fs2]#  cp qaz edc
cp: cannot create regular file `edc’: Input/output error 

When I run the dumpe2fs command, it told me the superblock had been destroyed.
[root@localhost fs2]#  dumpe2fs /dev/sda6
dumpe2fs 1.40.8 (23-Mar-2009)
dumpe2fs: Bad magic number in super-block while trying to open /dev/sda6
Couldn’t find valid filesystem superblock. 

I recovered the superblock.
[root@localhost ~]#   dd if=/dev/sda6 count=1 bs=1024 skip=8193 seek=1 of=/dev/sda5

After that, I checked if I can create and copy files. I found they worked. And the command dumpe2fs could display normally. 

EXT3 filesystem

In my machine, there is another ext3 filesystem /dev/sda5 which its mount point is /fs3.

Check the location of superblocks and the size of block.
[root@localhost ~]#   dumpe2fs /dev/sda5 | grep –i superblock
dumpe2fs 1.40.8 (23-Mar-2009)
  Primary superblock at 0, Group descriptors at 1-1
  Backup superblock at 32768, Group descriptors at 32769-32769
  Backup superblock at 98304, Group descriptors at 98305-98305
  Backup superblock at 163840, Group descriptors at 163841-163841
  Backup superblock at 229376, Group descriptors at 229377-22937
[root@localhost ~]#  dumpe2fs /dev/sda5 | grep –i ‘block size’
dumpe2fs 1.40.8 (23-Mar-2009)
Block size:                               4096 

From the above, I knew there are 4 backup superblocks and the block size is 4096 bytes. The location of primary superblock is at 0. The locations of these 4 backup superblocks are at 32768, 98304, 163840, and 229376.

Destroy the superblock.
[root@localhost ~]#   dd if=/dev/zero count=1 bs=4096 seek=0 of=/dev/sda5 

I found I still can change to /fs3 directory. But when I listed its contents, there is nothing. I used dumpe2fs command to check, it told me the superblock has problem. Then I tried to recover the superblock like the above approach, however, it did not work. I restarted the system. The system displayed it unable to resolve the filesystem and could not boot up. I entered the maintenance mode and tried to recover using the method as below. It did not work.
(Repair filesystem) 1 #   e2fsck –f –b 32768 /dev/sda5
e2fsck 1.40.8 (23-Mar-2009)
e2fsck: Device or resource busy while trying to open /dev/sda5
Filesystem mounted or opened exclusively by another program? 

Then I used another method, after I reboot the system it worded.
(Repair filesystem) 2 #   e2fsck –f  /dev/sda5
(Repair filesystem) 3 #   reboot 

From the test, I realized that the information of the filesystem’s superblock is very important. We’d better backup it to the root because we can still read it through maintenance mode even if the system can not boot up normally. Don’t forget run the following command.
#  dumpe2fs /dev/sda5 > /dumpe2fs-sda5 

Thursday, 19 February 2009

How To Convert VMWare Image (.vmdk) to VirtualBox Image (.vdi) on Linux

QEMU is free software written by Fabrice Bellard that implements a fast processor emulator, allowing a user to run one operating system within another one. It is similar to projects such as Bochs and VMware Workstation
First we need to install QEMU
# yum install qemu
Now using qemu, first we need to convert a .vmdk (VMware image) to a .bin format, which can then be converted to a Virtualbox native .vdi format.
# qemu-img convert /path/to/original.vmdk converted.bin
VirtualBox is a free, powerful and versatile virtualization program which is available for Linux, Mac, and Windows hosts, and can virtualize many different Operating Systems.
VirtualBox was originally developed by Innotek, but was purchased by Sun and renamed Sun xVM VirtualBox.
Now using VBoxManage utility that comes with Virtualbox we can easily convert the .bin file that we have generated using qemu to a native .vdi format:
#VBoxManage convertdd converted.bin converted.vdi

Sunday, 28 December 2008

Basic MySQL performance tuning using Query Cache

The query cache stores the text of a SELECT statement together with the corresponding result that was sent to the client. If an identical statement is received later, the server retrieves the results from the query cache rather than parsing and executing the statement again. The query cache is shared among sessions, so a result set generated by one client can be sent in response to the same query issued by another client.
The query cache can be useful in an environment where you have tables that do not change very often and for which the server receives many identical queries. This is a typical situation for many Web servers that generate many dynamic pages based on database content.
NOTE: The query cache always contains current and reliable data. Any insert, update, delete, or other modification to a table causes any relevant entries in the query cache to be flushed.
Query Cache Configuration:
To set the size of the query cache, set the query_cache_size system variable.
For the query cache to actually be able to hold any query results, its size must be set larger:
                   mysql> SET GLOBAL query_cache_size = 1000000;
If the query cache size is greater than 0, the query_cache_type variable influences how it works. This variable can be set to the following values:
0 or OFF prevents caching or retrieval of cached results.
1 or ON enables caching except of those statements that begin with SELECT SQL_NO_CACHE.
2 or DEMAND causes caching of only those statements that begin with SELECT SQL_CACHE.
                   mysql> SET SESSION query_cache_type = ON;
Using Select statement using Query Cache:
SQL_CACHE: The query result is cached if it is cacheable and the value of the query_cache_type system variable is ON or DEMAND.
SQL_NO_CACHE: The query result is not cached.
Examples:
                  SELECT SQL_CACHE id, name FROM customer;
                  SELECT SQL_NO_CACHE id, name FROM customer;
Setting the GLOBAL query_cache_type value determines query cache behavior for all clients that connect after the change is made. Individual clients can control cache behavior for their own connection by setting the SESSION query_cache_type value.

Sunday, 23 November 2008

How to Import / Export (Backup / Restore) MySQL Database

It is important to back up your databases so that you can recover your data and be up and running again in case problems occur. MySQL offers a variety of backup strategies from which you can choose the methods that best suit the requirements for your installation.
Export / Backup MySQL database: 
The mysqldump client can be used to dump a database or a collection of databases for backup or for transferring the data to another SQL server (not necessarily a MySQL server). The dump contains SQL statements to create the table and/or populate the table.
If you are doing a backup on the server, and your tables all are MyISAM tables, you could consider using the mysqlhotcopy instead since faster backups and faster restores can be accomplished with the latter
Here is the most simple way to export the database to a sql file
      # mysqldump -u USER -p DATABASE > FILENAME.sql
USER is the MySQL admin user
DATABASE is the name of the database that need to be exported
FILENAME.sql is the name of the file where your data will be exported
When you issue this command you will be prompted for the MySQL admin password. Enter that password and hit the Enter key. In the directory you issued the command you will now have a file with the FILENAME.sql file you then need to copy to your secure drive.
You can dump all databases by doing:
      # mysqldump -u root -p --all-databases > all_dbs.sql
Import/Restore MySQL database:
Below is the simple command through which you can restore / import the already exported MySQL database file (.sql)
     # mysql -u USER -p DATABASE < FILENAME.sql
USER is the MySQL admin user
DATABASE is the name of the database where data need to be imported / restore
FILENAME.sql is the dump that was exported.
You will be prompted for the MySQL administrator password.