Wednesday, July 20, 2011

Howto:Reduce LVM Root Partition

In this short tutorial I'll demonstrate how to reduce the size of LVM (/dev/VolGroup00/LogVol00) mounted on "/" (aka root partition).
Since the procedure cannot be done on the run (you will need to unmount the root partition...) , you will have to boot your machine either with some sort of Linux LiveCD or either with the original CentOS DVD/ISO which offers special rescue mode.

I didn't have a LiveCD so I used the original CentOS DVD for this task.

Boot the machine with a CentOS DVD/ISO (v 5.5 in my case) and enter the rescue mode by typing:
#linux rescue

CentOS will boot in rescue mode when a menu pops up and asks you if you want to mount your old partitions, chose "SKIP" (otherwise your original disk partitions will be mounted under /mnt/sysimage - in that case umount it before proceeding).

After you made sure your original disk partitions are not mounted you will have to activate the LVM in Rescue Mode:
# lvm vgchange -a y

Check the LVM for any filesystem errors, this is crucial for next step:
# e2fsck -f /dev/VolGroup00/LogVol00

It's time to resize the filesystem to a new size ,note that you should leave enough space for current data on the root partition or you will suffer a data loss.
In our case we are reducing the partition to a new size of 20GB.
Note that the procedure may take some time (depending on your root partition size, so do not panic!):
# resize2fs -f /dev/VolGroup00/LogVol00 20G

Finally, resize the LVM to the new size (20 GB):
#lvm lvreduce -L20G /dev/VolGroup00/LogVol00

You should boot your OS into regular mode and cross your fingers ...

Disclaimer: Do at your own risk, I'm not responsible for any data loss which may be caused to your system.

Tuesday, July 12, 2011

Enable SNMP on Cisco Devices (part 1)

In this short tutorial I'll demonstrate how to quickly configure SNMP on your Cisco appliance and test it's working.


There will be another tutorial dealing with how to configure the SNMP manager side.


1) Let's start by logging in to your Cisco appliance (In my case I used 851 series Cisco router with IOS version 12.3).

2) Enter configuration mode:
cisco851#configure terminal

3) Set your community string and the mode (read only, read write):
cisco851(config)#snmp-server community myComunity1 RW

4) Point the appliance to the SNMP manager (in our case 192.168.2.4) , with the same community string you've set before: 

 cisco851(config)#snmp-server host 192.168.2.4 version 2c myComunity1


5) Enable the trap types you wish to monitor, for example:

cisco851(config)#snmp-server enable traps snmp linkdown linkup coldstart warmstart

6) Save the configuration:
cisco851(config)#do wr

At this point the basic configuration on the Cisco appliance is done, let's see if we able to querry the appliance from our server.

I have used Ubuntu 11.04 x64 box with "snmp" package installed.

Check it's indeed installed with:
root@ubuntu:~#dpkg --list |grep snmp
If not get it with:
root@ubuntu:~#apt-get install snmp

After snmp package has been succefully installed it's time test the configuration.

Issue the following command and see if you're able to retrieve the SNMPv1 agent  or our Cisco appliance (192.168.2.1) MIB tree list :

root@ubuntu:~#snmpwalk -v 1 -c myComunity1 192.168.2.1

At this point you should be able to list the entire tree (output was ommited), means Cisco side is configured successfully.

You can now get the desired info for monitoring purposes, like the system uptime:

root@ubuntu:~#snmpget -v 1 -c myComunity1 192.168.2.1 iso.org.dod.internet.mgmt.mib-2.system.sysUpTime.0


DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (490514418) 56 days, 18:32:24.18
 
Or our appiance hostname:

root@ubuntu:~#snmpget -v 1 -c myComunity1 192.168.2.1 iso.org.dod.internet.mgmt.mib-2.system.sysName.0


SNMPv2-MIB::sysName.0 = STRING: gw1.slsphr.net.il
 
Mission accomplished.
 
In the next SNMP article I will touch the server side configuration.
 
Cheers.

Monday, May 2, 2011

Howto remove old NAT configuration from Cisco router

Recently I came upon a situation where my ISP has assigned me a static IP - instead of L2TP dialer (Virtual PPP Interface in Cisco) I was using before ...
Anyway, I started to remove old and irrelevant NAT settings that were associated with my old dialer ,but when I've tried to configure the new NAT settings I got an error:
%Dynamic mapping in use, cannot change

After scratching my head for awhile I found the solution.

To remove old NAT settings on Cisco router you need to 

1)Clear all old NAT translations
router#clear ip nat translatiom *

2)Disable old NAT pool settings
router(config)#no ip nat pool public_access 200.100.10.33 netmask 255.255.255.252

3)And finally, disable the translation:
router(config)#no ip nat inside source list 1 pool public_access overload

From this point you can safely configure the new NAT settings.
Cheers.

Thursday, April 14, 2011

Howto Connect NetApp iSCSI to XenServer 5.6 FP1


Since iSCSI is a great choice as a SR for your XenServer, in terms of performance and scalability, I've decided to created a straight forward and easy to understand guide of how to connect NetApp iSCSI based storage to XenServer, read on...
On the NetApp side:
1) Enable iSCSI service on the filer:











2) Create the desired LUN:
·        










3) Dedicate a separate NIC for iSCSI traffic, be sure the filer iSCSI dedicated NIC is assigned with a proper IP address:

·        









4)From the XenServer copy it's iscsi FQN:














5)Add the new initiator:













6)Map the new LUN to the new initiator:














On the XenServer side:
1)      Be sure you have a NIC assigned to iSCSI traffic.


2)      Right click on the XenServer -> New storage-> Software iSCSI












Click on Discover IQNs, it should find the NetApp IQN.
Next, click on Discover LUN's, it should find the available LUN's.

Click "Finish" to attach the SR.

Your newly created LUN should be successfully attached to XenServer at this point.


Wednesday, April 6, 2011

Howto rescan NICs on XenServer

1. First list the physical NIC's:
#xe pif-list

2. After making a note of the information, run the following command for each one of the new NIC's that appear as disconnected:
#xe pif-forget uuid=UUID


3. Next, have the system scan for the correct uuids, you will need the uuid of your server (find it with "xe host-list" ):
#xe pif-scan host-uuid=UUID

4. List the NICs again to see what we have found:
#xe pif-list

5. You should see the correct UUID's of your NICs. 
Then, run the following command for each one of the new NIC's to add them back:
#xe pif-plug UUID

At this point your new NICs should appear as connected.

Sunday, April 3, 2011

Howto Backup VM's in XenServer

I found this technique to be the easiest and most efficient, importing the whole virtual machine to *xva file. Though it's not the quickest method it worked flawlessly for me.

1. At XenServer console as root, mount some SR (CIFS or NFS) to a folder:
#mount -t cifs //myfiler01/ntfs_share /backup/

2. Check the mount:
#mount |grep backup

3. To find the VM you want to export Run:
#xe vm-list


4. Run the export VM command:
#xe vm-export vm=centos5 filename=/backup/centos5_backup.xva

That's it, the VM exported as *.xva file which is easy to import in case of failure. 

In case you want to import the VM, run:

#xe vm-import vm=centos5 filename=/backup/centos5_backup.xva

Saturday, February 19, 2011

Howto Configure Heartbeat Cluster

Server clustering gains more and more popularity these days.
One of the leading open-source products for HA is called "Heartbeat" (http://www.linux-ha.org/wiki/Heartbeat).

Heartbeat offers great (and free!) way to achieve HA on a Linux machine.
While configuring Heartbeat may not be the easiest thing , it's surely worth the effort, especially when we talking about some fancy production machine which requires HA.

In this article I will demonstrate how to configure Heartbeat and achieve full HA, read on.

For my test I have used 2 virtual stations (both installed CentOS v5.5 x64) - node1 & node2.

Pay attention that every step needs to be done on both hosts.
Also pay attention that your firewall is configured properly (port 694 udp needs to be allowed).

Step 1:
The first thing you want to do is to edit your /etc/hosts, in my case it looks like this:


192.168.0.133 node1
192.168.0.134 node1-e1
192.168.0.139 node2
192.168.0.140 node2-e1

When node1-e1 & node2-e2 are virtual interfaces on both of the machines (more explanation ahead).

Step 2:
Configure virtual interfaces on both of the nodes:

root@node1# ifconfig eth0:1 192.168.0.134 netmask 255.255.255.0
root@node2# ifconfig eth0:1 192.168.0.140 netmask 255.255.255.0

Step 3: 
Install heartbeat on both of the nodes:
# yum install heartbeat

Step 4:
Edit "authkeys" file (/etc/ha.d/authkeys) to include:

auth 1
1 crc

Step 5:
Edit "haresources" file (/etc/ha.d/haresources) to include:

node1 IPaddr2::192.168.0.133/24/eth0:2
node2 IPaddr2::192.168.0.139/24/eth0:1

Step 6:
Edit "ha.cf" file (/etc/ha.d/ha.cf)to include:

logfile /var/log/ha-log
debugfile /var/log/ha-debug
logfacility local0
udpport 694
ucast eth0  192.168.0.133
ucast eth0  192.168.0.134
ucast eth0  192.168.0.139
ucast eth0  192.168.0.140
ping node1-e1 node2-e1
node node1 node2
respawn hacluster /usr/lib64/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
auto_failback on
keepalive 2
deadtime 10
warntime 3
deadping 10
realtime on
initdead 50
debug 1


Step 7:
Restart Heartbeat:
# /etc/init.d/heartbeat restart

That's should be it, now let's test the HA.
I'm pinging node1 from 3rd (Windows) machine, then rebooting it, pay attention that after short time node2 takes over and I'm getting response:


 

Thursday, February 3, 2011

Howto enable passwordless SSH on NetApp filer

When working in an environment with lots of filer servers, you might consider enable password less SSH on the filer for easier administration (from some administration host).
The concept stays the same, public keys exchange, but as you know the NetApp OnTapp OS uses slightly different syntax, so I decided to write this small guide that will help you out:

OK, let's get busy , I'll assume that the filer has already has networking configured correctly.


1) The filer does not have SSH enabled by default, so login via telnet:
admin_host> telnet filer01


2) Set up root password:
filer01> passwd


3) Next, you need to enable SSH (preferably version 2 - as it's more secure):
filer01> secureadmin enable ssh2
filer01> secureadmin setup ssh


4) Make sure you exports file is edited correctly and vol0 is exported to admin_host
admin_host> showmount -e filer01

You can edit exports file from the filer with "wrfile" command, if you have modified the file remmember to re-export the new exports with:

filer01 >exportfs -av

5) Next, mount  vol0 from the NetApp filer on the amdministration host:

admin_host> mkdir -p /nfs/filer01/vol0
admin_host> mount -t nfs filer01:/vol/vol0 /nfs/filer01/vol0

Check that you see the mounted volume:

admin_host> ls /nfs/filer01/vol0

If not you're probably having some issue with your firewall, or exports on the filer side.

6) This is the most critical part, here you will create the ssh directory and append your root public key to authorized_keys of the filer:

admin_host> mkdir -p /nfs/filer01/vol0/etc/sshd/root/.ssh/

admin_host> cat /root/.ssh/id_rsa.pub >> /nfs/filer01/vol0/etc/sshd/root/.ssh/authorized_keys


7) Last, you may want to turn down rsh and telnet services (for obvious security reasons):

filer01> options rsh.enable off
filer01> options telnet.enable off


Your are done.

Saturday, January 15, 2011

Bash getops - Quick & Easy

Ever wanted to create this super script with tonns of flags and parameters?
In this short tutorial I will show you how to do it in bash shell.

Let's say we have a script named:script.sh
That has 3 flags (-v for verbouse, -h for help, -i for ip address as input).
The two first parameters do not really get input, but more "tell the script how to behave", while the third parameter actually gets a value from user (ip address).

The "getopts" function is a very handful function when you’re working with script where parameters and flags have to be set.

Our script will be executed as (for example):
#./script.sh -v -i 10.100.1.2

This is the content of our short script:
#!/bin/bash 
usage() {
cat << EOF
-h help
-v verbouse mode
-i new ip address
EOF
} 
while getopts "i:hv" flag ; do
        case $flag in
                i ) IPADDR=$OPTARG;;
                h ) usage;;
                v ) VERB=1;exit 0;;
        esac
done
 
Pay attention to the options with a colon (“:”) after them need to have an argument set.
Yet if there is no column, then no argument is needed (-h, -v).

We combine while loop with "getopts" function, that will use case to determine which flags were used and what values has been assigned.

Monday, December 6, 2010

Howto - Find broken symbolic links

2 cool ways to find broken symbolic links on your system:
Bash:
for i in `find /`; do if (test -h $i); then file $i|grep broken; fi; done

Output:
./bar_link: broken symbolic link to `/etc/foo'



Any Shell:
find / -type l ! -exec test -r {} \; -print

Output:
./bar_link

When measuring the results with "time" command - the 2nd command wins, so if performance is critical in your case, use the 2nd one :)