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 :)

Tuesday, September 14, 2010

Change ILO settings via CLI from Linux

ILO - aka "Integrated Lights Out" is an advanced console technology that HP has implemented in most of their servers, it includes dozens of cool features and allows total remote control on the server in all kinds of aspects. ILO includes lot's of advanced configurations such as IP configuration, DNS, SNMP, LDAP integration, Users, Permissions and many more.

The "traditional" way to change these settings is via server downtime and booting it to ILO BIOS (usually by pressing F8 at boot time) and changing it there.

But what if we have hundreds of servers that require immediate change, going the first way would be a huge waste of time, therefore HP introduced a cool scripting tool (for both Linux & Windows) called  - "hponcfg". In this short tutorial we will understand how to use it - read on:


To use "hpconfg" we first have to make sure a service called "hprsm" is installed properly & running and that the needed modules are loaded into kernel:

linux01 #rpm -q hprsm hponcfg
hprsm-7.9.0-108.sles10
hponcfg-1.6.0-1

linux01 #/etc/init.d/hprsm start

The service is running and we are ready to configure our ILO settings, to see the current settings we can generate an XML template with our current settings, to achieve this execute:

linux01 #hponcfg -w /tmp/ilo_cfg_`uname -n`.xml
Firmware Revision = 1.81 Device type = iLO 2 Driver name = cpqci
RILOE II/iLO configuration successfully written to file "/tmp/ilo_config_linux01.xml"


Now, we can see our current ILO configuration represented in the XML template we saved to /tmp, let's see what it contains:

linux01 #cat /tmp/ilo_config_linux01.xml



















Ok, now you can edit whatever parameter you like and upload the updated XML template to ILO via "hpocnfg tool".

To upload the XML template, execute:
linux01 #hponcfg -f /tmp/ilo_config_`uname -n`.xml

Please note that  restart of ILO is needed for changes to take effect.

Sunday, August 29, 2010

Check Hyper Threading - Linux

When you need to know whether hyper-threading is enabled without rebooting your system (and checking BIOS/UEFI), you can simply look at the output of /proc/cpuinfo and compare the siblings with the cpu cores fields.
Even though /proc/cpuinfo shows you all the logical CPUs (processor field) in the system, the siblings field holds the number of logical CPUs for the physical CPU this entry belongs to (including both the cores and the hyper-threaded LCPUs).

For example, if you see:
processor : 7
physical id : 9
siblings : 4
cpu cores : 2

That means that LCPU #7 (the eight logical CPU in your system) is one of the 4 logical CPUs on the physical CPU that has 2 cores. So - hyper-threading is enabled.

Thursday, June 17, 2010

Change MTU size in Linux

Maximum Transmission Unit(MTU), the largest physical packet size, measured in bytes, that a network can transmit. Any messages larger than the MTU are divided into smaller packets before being sent .
By optimizing the MTU setting you can gain substantial network performance.
In IPv4 the values range between 576 and 1500 bytes being the max size.

The general syntax is: ifconfig "interface" mtu "size"

For example:ifconfig eth0 mtu 1420


Will change MTU to 1420 bytes.

For permanent change, you can add the MTU parameter into your interface configuration file,
For example in Debian the configuration will look like this:



iface eth0 inet static
address 192.168.0.100
network 192.168.0.0
gateway 192.168.0.254
netmask 255.255.255.0
mtu 1420

Friday, February 19, 2010

Generate hosts file with Perl

A sweet way to add couple of servers to your hosts file/NIS map using a tiny perl script:

#!/usr/bin/perl -w

use strict;
use warnings;
print `clear`;
my $j=10;

open (HOSTS ,">>/etc/hosts.txt") or die $!;
for (my $num=0;$num <= 10; $num++) {
printf(HOSTS "server$j \t server$j.domain.org \t 192.168.0.$num\n");
$j++;
}
close (HOSTS) or die $! ;

#END


The output will be:

server10 server10.domain.org 192.168.0.0

server11 server11.domain.org 192.168.0.1
server12 server12.domain.org 192.168.0.2
server13 server13.domain.org 192.168.0.3
server14 server14.domain.org 192.168.0.4
server15 server15.domain.org 192.168.0.5
server16 server16.domain.org 192.168.0.6
server17 server17.domain.org 192.168.0.7
server18 server18.domain.org 192.168.0.8
server19 server19.domain.org 192.168.0.9
server20 server20.domain.org 192.168.0.10

Monday, January 11, 2010

Howto change NIC order in Linux (SUSE 10)

I recently had an issue with a mother board that was replaced on some server, after renaming the configuration file to the correct MAC address (ifcfg-eth-id-00:1a:64:7a:d0:be), the new NIC was recognized as eth4, (and not eth0 as previously),after digging abit in the depths of the OS I have found a solution:

/etc/udev/rules.d/30-net_persistent_names.rules

Through this file you can configure the NIC order by MAC address.
For example:

SUBSYSTEM=="net", ACTION=="add", SYSFS{address}=="00:1a:64:7a:d0:be", IMPORT="/lib/udev/rename_netiface %k eth0"

To change take place you will probably need to reboot the machine so udev will re-read it's configurations(restarting networking service is not enough).