總網頁檢視次數

星期二, 8月 25, 2009

CENTOS - iostat package

yum install sysstat.x86_64

To Check Disk usage
iostat -x 5
iostat -t 2 -k

Check free memory
free -m

CENTOS - Add Virtual interface

DEVICE=bond0:0
IPADDR=x.x.x.x
ONPARENT=yes

星期三, 8月 19, 2009

CENTOS - RAMDISK

Ramdisk is very good to have if you want something to stay in memory. Files in memory makes it so you can access them with out having to access hard drive all the time. Perfect candidates would be things which do not change eg. web images or downloadable files, etc. If you have Linux Kernel 2.4 or later, you already have support of ramdisk built in. You can check if ramdisk is setup by doing:

# dmesg | grep RAMDISK
RAMDISK driver initialized: 16 RAM disks of 16384K size 1024 blocksize

You should get above output on CentOS and RHEL. Other linux flavors will have similar output as well. If you would like to see how they are named and what you would need to refer to, do the following:

# ls -l /dev/ram*
lrwxrwxrwx 1 root root 4 Apr 24 12:05 /dev/ram -> ram1
brw-rw---- 1 root disk 1, 0 Apr 24 12:05 /dev/ram0
brw-rw---- 1 root disk 1, 1 Apr 24 12:05 /dev/ram1
brw-rw---- 1 root disk 1, 10 Apr 24 12:05 /dev/ram10
brw-rw---- 1 root disk 1, 11 Apr 24 12:05 /dev/ram11
brw-rw---- 1 root disk 1, 12 Apr 24 12:05 /dev/ram12
brw-rw---- 1 root disk 1, 13 Apr 24 12:05 /dev/ram13
brw-rw---- 1 root disk 1, 14 Apr 24 12:05 /dev/ram14
brw-rw---- 1 root disk 1, 15 Apr 24 12:05 /dev/ram15
brw-rw---- 1 root disk 1, 2 Apr 24 12:05 /dev/ram2
brw-rw---- 1 root disk 1, 3 Apr 24 12:05 /dev/ram3
brw-rw---- 1 root disk 1, 4 Apr 24 12:05 /dev/ram4
brw-rw---- 1 root disk 1, 5 Apr 24 12:05 /dev/ram5
brw-rw---- 1 root disk 1, 6 Apr 24 12:05 /dev/ram6
brw-rw---- 1 root disk 1, 7 Apr 24 12:05 /dev/ram7
brw-rw---- 1 root disk 1, 8 Apr 24 12:05 /dev/ram8
brw-rw---- 1 root disk 1, 9 Apr 24 12:05 /dev/ram9
lrwxrwxrwx 1 root root 4 Apr 24 12:05 /dev/ramdisk -> ram0

All those ramdisks listed have same size. In above example, they are all 16MB. Let us change that so we have more space allowed. Note that I say allowed and not allocated. We allocate space in one of the later steps by formatting one of the drives above. Let us set it up so we have 128 MB. Since this has to be in multiples of 1024, we will setup Ramdisk to have 131072K.

vi /etc/grub.conf

Find first line which looks similar to following:

kernel /vmlinuz-2.6.9-42.0.10.EL ro root=/dev/VolGroup00/LogVol00

add ramdisk_size=131072 to the end of the line. Now your line should look like:

kernel /vmlinuz-2.6.9-42.0.10.EL ro root=/dev/VolGroup00/LogVol00 ramdisk_size=131072 Save and exit grub.conf. At this point you have it configured to have ramdisk with new size but it does not take effect until you reboot your system. Once you have rebooted your system, we can start doing rest of configurations.

mke2fs -m 0 /dev/ram0

This will format the ram0 ramdrive for us to use. At this point, kernel will allocate space for you. Let us setup Ramdisk mount point so we can use it. We will also have it be owned by user “sunny” so that user can read/write to that mount.

mkdir /home/ramdisk
mount /dev/ram0 /home/ramdisk
chown sunny.sunny /home/ramdisk

At this point you should be able to type: mount and see your new Ramdisk drive mounted on /home/ramdisk

Remember that everything you put on this drive will be gone if you reboot your server. If you unmounted the Ramdisk drive and remounted it, your files will still be there. It is because your system has that much ram set aside for your Ramdisk and will not use it for anything else. If you would like to setup Ramdisk the same next time you boot up, add these lines to your /etc/rc.local files.

mke2fs -m 0 /dev/ram0
mount /dev/ram0 /home/ramdisk
chown sunny.sunny /home/ramdisk


Source from : http://crazytoon.com/2007/06/01/ramdisk-how-do-you-install-and-set-up-ramdisk-under-linux-centos-rhel-fedora/

星期六, 8月 15, 2009

CENTOS - Update time zone and time

ln -sf /usr/share/zoneinfo/GMT /etc/localtime


crontab -e

0 * * * * /usr/sbin/ntpdate -u stdtime.gov.hk

CENTOS 5.3 bonding ( my own script )

#vi /etc/modprobe.conf

Add following two lines

alias bond0 bonding
options bond0 miimon=80 mode=6

*** backup configuration files for rollback
#cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.bak
#cp /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth1.bak

#vi /etc/sysconfig/network-scripts/ifcfg-eth0

Del all except the hardware mac address (HWADDR=xx:xx.... )
Add the following lines

DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no

#vi /etc/sysconfig/network-scripts/ifcfg-eth0

Del all except the hardware mac address (HWADDR=xx:xx.... )
Add the following lines

DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no

*** Add new bond0 configuration file
#vi /etc/sysconfig/network-scripts/ifcfg-bond0

Add the following lines

DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=x.x.x.x
GATEWAY=x.x.x.1
USERCTL=no
MTU=9000


That's all ... restart network to test

#service network restart

Remember to test reboot and see if all configuration will be up automatically ..

#shutdown -r now

CENTOS - Jumbo Frame

vi /etc/sysconfig/network-script/ifcfg-eth0

Add MTU=9000

service network restart

CENTOS- bonding ( network teaming )

The concept of NIC Bonding (or sometimes called NIC Teaming) is that you have two NICs bonded together to appear as if they are the same physical device. I.e. They will both present the same Hardware (MAC) address. This is accomplished through the ifenslave utility, which enables the kernel to see/use only one device, while it sends out packtes via the two slave devices using a round-robbin scheduler.



System: Debian Sarge 3.1 (vanilla kernel 2.6.12.4)
Modules Involved: bonding, mii, nic_module (e100 in this example)
Utilities: ifenslave, mii-tool


Preparation:



Before attempting to bond two NICs, it is highly recommended that you verify the integrity and functionality of each NIC on its own. This document assumes that you've already done that. Using 'mii-tool' you should see something like the following:

testbox:/# mii-tool
eth0: negotiated 100baseTx-FD, link ok
eth1: negotiated 100baseTx-FD, link ok


In order for this to work, the kernel must have support for bonding
devices. A few ways to check would be:

testbox:/# modprobe --list | grep bonding/lib/modules/2.6.12.4-vs2.0/kernel/drivers/net/bonding/bonding.ko
testbox:/# cat /boot/config-2.6.12.4-vs2.0 | grep -i bonding
CONFIG_BONDING=m




We use the mii-tool (mii.o module) to monitor the interfaces for
failover... though, as most ethernet adapters use an MII (Media
Independant Interface) to autonegotiate link speeds, its pretty standard
that you'd have this.

testbox:/# cat /boot/config-2.6.12.4-vs2.0 | grep -i mii# CONFIG_MPENTIUMII is not set
# CONFIG_MPENTIUMIII is not set
CONFIG_MII=y


testbox:/# modprobe --list | grep -i mii
/lib/modules/2.4.26-2-686/kernel/drivers/net/mii.ko



Second, your going to need to install the ifenslave utility.

testbox:/# apt-get update && apt-get install ifenslave
.......... removed standard output (nothing interesting)


Theres no configuration here, so that is that. Now we are ready for
the configuration files.


Configuration Files:


There are many different variations of this, but for now... this is how I did it to get it working.



vi /etc/modutils/aliases and add/edit the following:

alias bond0 bonding
alias eth0 e100
alias eth1 e100
options bonding mode=0 miimon=100


vi /etc/modutils/actions and add/edit the following:

probeall bond0 eth0 eth1 bonding


After editing the modprobe config files you need to run the command:

testbox# update-modules




vi /etc/network/interfaces and add/edit the following:

auto bond0
iface bond0 inet static
address 10.1.100.63
netmask 255.255.255.0
hwaddress ether 00:02:B3:48:50:2C
gateway 10.1.100.1
up ifenslave bond0 eth0 eth1
down ifenslave -d bond0 eth0 eth1



You do NOT set up entries for 'eth0' or 'eth1' outside of whats listed above under the 'bond0' entry. Bond0 will now be the interface that the kernel works with. running an 'ifconfig' will show all three interface (bond0,eth0,eth1), all with the same MAC and IP addresses.


And thats basically it. Now, all you should need to do is load the 'bonding' module and stop/start networking... and the apropriate modules should load automagically:

testbox:/# modprobe bonding
testbox:/# /etc/init.d/networking stoptestbox:/# /etc/init.d/networking start

You might have to play around with this part for a bit. For me I had to manually ifconfig up the bond0 device:

testbox:/# ifconfig bond0 10.1.15.63 netmask 255.255.255.0 up

Assuming that there were no errors, you should be able to test this out. Try and ping your IP address from another box. You'll notice both NICs responding to the ping requests back and forth (round robin). If you unplug eth0, you'll get an error the console the "eth0 has failed, eth1 becoming primary" or something like that (and visa versa if you unplug eth1). But you shouldn't drop any of the ping requests (or no more than a few), as it now has a redundant network connection.

In a higher end environment, you could plug each NIC into a separate switch (staying on the same VLAN) and further improve your high availability config... and so on and so forth.

Source from : http://www.howtoforge.com/nic_bonding