Search This Blog

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Thursday, 16 May 2013

Linux IP Multipath configuration (bonding)


Check all your network interfaces using ethtool command

[root@MyLinux ~]# ethtool eth0
Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised auto-negotiation: Yes
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: g
        Wake-on: g
        Link detected: yes
[root@MyLinux ~]# ethtool eth1
Settings for eth1:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised auto-negotiation: Yes
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: g
        Wake-on: g
        Link detected: yes

Check all the requiured kernel modules are available(bonding and mii)
[root@MyLinux ~]# modprobe -l | grep bonding
/lib/modules/2.6.18-308.el5/kernel/drivers/net/bonding/bonding.ko

[root@MyLinux ~]# modprobe -l | grep mii
/lib/modules/2.6.18-308.el5/kernel/drivers/net/mii.ko

Editing the modprobe.conf file. Append below line in modprobe.conf
[root@MyLinux etc]# cat modprobe.conf
alias bond0 bonding
options bond0 mode=1 miimon=100

Where

mode=0 (balance-rr)
Round-robin policy: Transmit packets in sequential order from the first available slave through the last. This mode provides load balancing and fault tolerance.

mode=1 (active-backup)
Active-backup policy: Only one slave in the bond is active. A different slave becomes active if, and only if, the active slave fails. The bond's MAC address is externally visible on only one port (network adapter) to avoid confusing the switch. This mode provides fault tolerance. The primary option affects the behavior of this mode.

mode=2 (balance-xor)
XOR policy: Transmit based on [(source MAC address XOR'd with destination MAC address) modulo slave count]. This selects the same slave for each destination MAC address. This mode provides load balancing and fault tolerance.

mode=3 (broadcast)
Broadcast policy: transmits everything on all slave interfaces. This mode provides fault tolerance.

mode=4 (802.3ad)
IEEE 802.3ad Dynamic link aggregation. Creates aggregation groups that share the same speed and duplex settings. Utilizes all slaves in the active aggregator according to the 802.3ad specification.


Load both kernel modules and confirm the file edit by below commands

[root@MyLinux etc]# modprobe bonding
[root@MyLinux etc]# modprobe mii


Create a new network configuration file for bond0 and edit eth0 and eth1 accordingly under /etc/sysconfig/network-scripts/ directory

ifcfg-bond0

[root@MyLinux network-scripts]# cat ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
NETMASK=255.255.254.0
IPADDR=192.168.10.139
USERCTL=no
GATEWAY=192.168.10.1
TYPE=Ethernet
IPV6INIT=no
PEERDNS=yes
[root@MyLinux network-scripts]#

ifcfg-eth0

[root@MyLinux network-scripts]# cat ifcfg-eth0
# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth0
BOOTPROTO=none
#HWADDR=e4:1f:13:1e:c4:00
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
TYPE=Ethernet

ifcfg-eth1

[root@MyLinux network-scripts]# cat ifcfg-eth1
# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
TYPE=Ethernet

Restart network services now.
[root@MyLinux etc]# cd /etc/sysconfig/network-scripts/
[root@MyLinux network-scripts]# /etc/init.d/network restart
Shutting down interface eth0:                              [  OK  ]
Shutting down interface eth1:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface bond0:                               [  OK  ]

Check the bond status using below commands

[root@MyLinux ~]#  cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0-1 (October 7, 2008)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: e4:1f:13:1e:c4:00

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: e4:1f:13:1e:c4:02


[root@MyLinux ~]# ifconfig -a
bond0     Link encap:Ethernet  HWaddr E4:1F:13:1E:C4:00
          inet addr:192.168.10.139  Bcast:10.64.209.255  Mask:255.255.254.0
          inet6 addr: fe80::e61f:13ff:fe1e:c400/64 Scope:Link
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:2420 errors:0 dropped:0 overruns:0 frame:0
          TX packets:530 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:210110 (205.1 KiB)  TX bytes:351640 (343.3 KiB)

eth0      Link encap:Ethernet  HWaddr E4:1F:13:1E:C4:00
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:545 errors:0 dropped:0 overruns:0 frame:0
          TX packets:530 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:53341 (52.0 KiB)  TX bytes:351640 (343.3 KiB)
          Interrupt:98 Memory:f2000000-f2012800

eth1      Link encap:Ethernet  HWaddr E4:1F:13:1E:C4:00
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:1875 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:156769 (153.0 KiB)  TX bytes:0 (0.0 b)
          Interrupt:193 Memory:f4000000-f4012800

Tuesday, 19 April 2011

Extending VMWARE guest linux OS Filesystem

1.Rescan SCSI Bus to detect newly added disk using below command.

[root@RHEL ~]# echo "- - -">/sys/class/scsi_host/host*/scan

2. Tail system message file for checking the newly added disk is probed.
[root@RHEL ~]# tail -f /var/log/messages
Mar  6 16:34:56 RHEL kernel: SCSI device sdc: 545259520 512-byte hdwr sectors (279173 MB)
Mar  6 16:34:56 RHEL kernel: sdc: cache data unavailable
Mar  6 16:34:56 RHEL kernel: sdc: assuming drive cache: write through
Mar  6 16:34:56 RHEL kernel: SCSI device sdc: 545259520 512-byte hdwr sectors (279173 MB)
Mar  6 16:34:56 RHEL kernel: sdc: cache data unavailable
Mar  6 16:34:56 RHEL kernel: sdc: assuming drive cache: write through
Mar  6 16:34:57 RHEL kernel:  sdc: unknown partition table
Mar  6 16:34:57 RHEL kernel: Attached scsi disk sdc at scsi0, channel 0, id 2, lun 0
Mar  6 16:34:57 RHEL scsi.agent[31318]: disk at /devices/pci0000:00/0000:00:10.0/host0/target0:0:2/0:0:2:0
Mar  6 16:34:57 RHEL udevd[1418]: udev done!

3. Now the new disk (/dev/sdc) is  visible in fdisk output (With a invalid disk label for new disks)
[root@RHEL ~]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        3916    31350847+  8e  Linux LVM

Disk /dev/sdb: 75.1 GB, 75161927680 bytes
255 heads, 63 sectors/track, 9137 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1        9138    73400319+  8e  Linux LVM

Disk /dev/sdc: 279.1 GB, 279172874240 bytes
255 heads, 63 sectors/track, 33940 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdc doesn't contain a valid partition table

4. Create physical volume on new disk
#pvcreate /dev/sdc
5. Extend the VG(VgBSL) to new disk (/dev/sdc)
[root@RHEL ~]# vgextend VgBSL /dev/sdc
  /dev/cdrom: open failed: No medium found
  Volume group "VgBSL" successfully extended
5. List the existing Physical Volumes
[root@RHEL ~]# pvs
  PV         VG         Fmt  Attr PSize   PFree
  /dev/sda2  VolGroup00 lvm2 a-    29.88G      0
  /dev/sdb1  VgBSL     lvm2 a-    69.97G   1.53G
  /dev/sdc   VgBSL     lvm2 a-   259.97G 259.97G

6. Extend logical Volume to new size (old size + newly available)
[root@RHEL ~]# lvextend -L 299G /dev/mapper/VgBSL-LogVol02
  Extending logical volume LogVol02 to 299.00 GB
  Logical volume LogVol02 successfully resized

7. Extend the Volume using ext2online command.
[root@RHEL ~]# ext2online /dev/mapper/VgBSL-LogVol02
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b
8. Now the Volume is resized to new size
[root@RHEL ~]# df -h /apps
Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VgBSL-LogVol02
                      295G   37G  247G  13% /apps

Tuesday, 12 April 2011

Script for Deleting a Specific day older files

 

#Source Directory
SRC=/apps/temp
#Specify size of file system in percentage when the script work. Nothing will happen if the FS utilization is below this.
CUTOFF=15
#Specify the age of file to be moved (older than this)
OLD=14
TS=`date "+%Y_%m_%d_%H:%M:%S"`
#location of Logfile
LOG=/tmp/mvfile.$TS
X=`df $SRC |grep -v Used|awk '{print $4}'|cut -c1-2|grep -v ^$`

if [ -f  $LOG ]
        then
        rm  $LOG
fi

if [[ $X -gt $CUTOFF ]]
then
        echo "/usr/bin/find $SRC -mtime +$OLD -print >>/tmp/mvfiles.$TS"
        /usr/bin/find $SRC -mtime +$OLD -print >>$LOG
                for i in `cat $LOG`
                do
                rm $i
                done
                echo "Log file Available:  $LOG"
fi

Thursday, 5 August 2010

Creating more than 8 loop back devices in Linux

By default Linux  supports only 8 loop back devices which means we can mount maximum 8 loop back devices(for Eg: 8 iso images)and maximum supported loop back devices by OS is 64.  If you tried to mount the 9 th devices, you may get an error "mount could not find a spare loop device" error.  Below script create the loop back devices from 8 to 64 

for ((i=8;i<64;i++)); do
[ -e /dev/loop$i ] || mknod -m 0600 /dev/loop$i b 7 $i
done


Enjoy.... Now you can mount up to 64

Monday, 5 July 2010

sudo to run as another non root user

sudo command is a program for some Unix and Unix-like computer operating systems that allows users to run programs with the security privileges of another user (normally the superuser, or root)

Here I explain how to edit sudoers file for granting access to another user (say monitor) to stop and start database (its a part of dba user privilege)

Stop and start scripts (/usr/local/bin/dbstop.sh and /usr/local/bin/dbstart.sh) are owned by dba user and only dba has the privileges to run it.



This is the sudo settings for monitor user to run above script as dba user.

Cmnd_Alias DBcmd=/usr/local/bin/dbstop.sh,/usr/local/bin/dbstart.sh
Runas_Alias  DBAUSER=dba 
monitor     ALL   = (DBAUSER) NOPASSWD: DBcmd

Now monitor user can run above command as dba

$sudo -u dba /usr/local/bin/dbstop.sh