Add swap on Linux

Thursday, October 1st, 2009

[root@host ~]# dd if=/dev/zero of=/swapfile bs=1024 count=1048576
1048576+0 records in
1048576+0 records out
[root@host ~]# sync
[root@host ~]# mkswap /swapfile
Setting up swapspace version 1, size = 1073737 kB
[root@host ~]# swapon /swapfile
[root@host ~]# echo “/swapfile swap swap defaults 0 0″ >> /etc/fstab

Script to generate interface configs on Linux

Wednesday, September 16th, 2009

Generate ifcfg-eth1 307-366 configs.

touch ifcfg-eth1:{307..366}
for f in ifcfg-eth1:{307..366}; do cat origfile > “$f”; done
for f in eth1:{307..366}; do echo “DEVICE=$f” >> “ifcfg-$f”; done
for f in {307..366}; do echo “IPADDR=aaa.bbb.ccc.$((f-239))” >> “ifcfg-eth1:$f”; done

origfile contains:

GATEWAY=eee.fff.ggg.hhh
TYPE=Ethernet
BOOTPROTO=none
NETMASK=255.255.255.192

How do I find out Linux Disk utilization RHEL/Centos?

Wednesday, September 2nd, 2009

iostat syntax for disk utilization report

iostat -d -x interval count

-d : Display the device utilization report (d == disk)
-x : Display extended statistics including disk utilization

interval : It is time period in seconds between two samples . iostat 2 will give data at each 2 seconds interval.

count : It is the number of times the data is needed . iostat 2 5 will give data at 2 seconds interval 5 times

Display 3 reports of extended statistics at 5 second intervals for disk

Type the following command:

# iostat -d -x 5 3

Output:

[root@vari Desktop]# iostat -d -x 5 3

Linux 2.6.18-128.7.1.el5xen (vari.taashee.com) 08/26/2009 _i686_ (2 CPU)

Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util

sda 2.41 12.42 3.27 5.37 134.84 142.70 32.13 0.12 14.04 1.83 1.58

Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util

sda 0.00 1.60 0.00 0.40 0.00 16.00 40.00 0.00 0.00 0.00 0.00

Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util

sda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

Where,

rrqm/s : The number of read requests merged per second that were queued to the hard disk
wrqm/s : The number of write requests merged per second that were queued to the hard disk
r/s : The number of read requests per second
w/s : The number of write requests per second
rsec/s : The number of sectors read from the hard disk per second
wsec/s : The number of sectors written to the hard disk per second
avgrq-sz : The average size (in sectors) of the requests that were issued to the device.
avgqu-sz : The average queue length of the requests that were issued to the device
await : The average time (in milliseconds) for I/O requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them.

svctm : The average service time (in milliseconds) for I/O requests that were issued to the device
%util : Percentage of CPU time during which I/O requests were issued to the device (bandwidth utilization for the device). Device saturation occurs when this value is close to 100%.

How do I interpret the output result for optimization?

First you need to note down following values from the iostat output:

1. The average service time (svctm)
2. Percentage of CPU time during which I/O requests were issued (%util)
3. See if a hard disk reports consistently high reads/writes (r/s and w/s)

If any one of these are high, you need to take one of the following action:

Get high speed disk and controller for file system (for example move from SATA I to SAS 15k disk)
Tune software or application or kernel or file system for better disk utilization
Use RAID array to spread the file system

How to sort folders by size with one command line in Linux

Thursday, July 30th, 2009

du –max-depth=1 $PWD | sort -n -r
du -H –max-depth=1 $PWD

“-H” – produce human readable format sizes (like: 1K 10M 1G)

A good and short one liner using xargs

du -s ./* | sort -n| cut -f 2-|xargs -i du -sh {}

This will sort the folders according to size and display them in human readable format… to reverse the list
use sort -nr option.

Howto configure vsftpd

Saturday, July 11th, 2009

yum install vsftpd

[root@shifu ~]# cat /etc/vsftpd/vsftpd.conf | grep -v ^#
anonymous_enable=NO # disable anonymous account
local_enable=YES # enable local users
write_enable=YES # enable uploading files
local_umask=022 # mask
dirmessage_enable=YES
xferlog_enable=YES # log messages
connect_from_port_20=YES
xferlog_std_format=YES
idle_session_timeout=600
chroot_list_enable=YES # chroot users into their own dir
listen=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

/etc/vsftpd/chroot_list contains a list of all users that will be in chroot

How to upgrade MySQL 5.0 to MySQL 5.1 cPanel

Sunday, June 14th, 2009

How to upgrade MySQL 5.0 to MySQL 5.1 in a cPanel server

Login as root and edit /var/cpanel/cpanel.config.

Replace :

mysql-server=5.0 with
mysql-server=5.1

Finally run: /scripts/mysqlup

Sysctl Linux

Saturday, June 13th, 2009
net.ipv4.tcp_ecn = 0
net.ipv4.conf.default.rp_filter = 1
#kernel.sysrq = 1
kernel.core_uses_pid = 1

net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.eth0.rp_filter = 0

net.ipv4.neigh.default.gc_thresh1 = 65535
net.ipv4.neigh.default.gc_thresh2 = 65535
net.ipv4.neigh.default.gc_thresh3 = 65535

kernel.core_uses_pid = 1
#Default ttl
net.ipv4.ip_default_ttl = 255

#No uptime
net.ipv4.tcp_timestamps=0

#Forwarding
net.ipv4.ip_forward = 1

net.ipv4.tcp_ecn = 0
net.ipv4.conf.default.rp_filter = 1
kernel.core_uses_pid = 1

#Connection max numer
net.ipv4.ip_conntrack_max = 65535

#Against DDOS //6169=0x1819
net.ipv4.icmp_ratelimit=0
net.ipv4.icmp_ratemask=6169

#Disabling of ICMP echo-reply directed to Broadcast addresses // against scanning
net.ipv4.icmp_echo_ignore_broadcasts=1