niedziela, 11 września 2011

Linux: Configuring cluster VIP (Virtual IP) with keepalived: Part 2

The first part of this article is focusing on the instructions/guide how to setup keepalived with VIP address for a two node configuration. I have enhanced the picture from the previous article with the ARP configuration since the ARPs will be used throughout this part to describe the mechanisms for VIP failover.

Figure 1 Deployment diagram of the keepalived for a two node configuration

In this part there will be two test scenarios described:
  1. The master goes down (Host A)
  2. The master starts up again (Host A)
Other cases involving Backup node (Host B) are not relevant to be described in detail since in these cases there is no VIP failover done.

Case A The master goes down (Host A)

Let's first check how the envrionment looks like from the client station perspective. Both nodes (HostA and HostB) are up and running with the keepalived as described in part 1 or this article. The client station is able to ping the VIP address:

krychu@krystianek:~$ ping 192.168.122.50
PING 192.168.122.50 (192.168.122.50) 56(84) bytes of data.
64 bytes from 192.168.122.50: icmp_req=1 ttl=64 time=0.394 ms
64 bytes from 192.168.122.50: icmp_req=2 ttl=64 time=0.353 ms
64 bytes from 192.168.122.50: icmp_req=3 ttl=64 time=0.270 ms
64 bytes from 192.168.122.50: icmp_req=4 ttl=64 time=0.814 ms
^C
--- 192.168.122.50 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2998ms
rtt min/avg/max/mdev = 0.270/0.457/0.814/0.212 ms

By looking into the arp table:

krychu@krystianek:~$ arp -an
...
? (192.168.122.50) at 52:54:00:03:ba:f2 [ether] on virbr0? (192.168.122.179) at on virbr0
...

we see that the Host A is the one available under the VIP (192.168.122.50) address, which is as we expected it to be since this is the master.
Now let's simulate a crash of the master node as follows:
  1. We constantly ping the VIP address from the client station
  2. We simulate a crash of the keepalived process on the master node (Host A), e.g. kill -9
  3. We check ping output if there was a smooth failover
  4. We check the ARP table which MAC is used
  5. We sniff the interface to get the information what caused the client's machine ARP table update
Ok, so what are the results? First of all the node crash does have effect on ICMP packets being dropped - there is a small increase in the response time to about 20.1 ms (please take a look below). 

krychu@krystianek:~$ ping 192.168.122.50
PING 192.168.122.50 (192.168.122.50) 56(84) bytes of data.
...
64 bytes from 192.168.122.50: icmp_req=37 ttl=64 time=0.336 ms
64 bytes from 192.168.122.50: icmp_req=38 ttl=64 time=0.398 ms
64 bytes from 192.168.122.50: icmp_req=39 ttl=64 time=0.273 ms
64 bytes from 192.168.122.50: icmp_req=40 ttl=64 time=0.298 ms
64 bytes from 192.168.122.50: icmp_req=41 ttl=64 time=20.1 ms
64 bytes from 192.168.122.50: icmp_req=42 ttl=64 time=0.320 ms
64 bytes from 192.168.122.50: icmp_req=43 ttl=64 time=0.379 ms
64 bytes from 192.168.122.50: icmp_req=44 ttl=64 time=0.314 ms
...
^C
--- 192.168.122.50 ping statistics ---
67 packets transmitted, 67 received, 0% packet loss, time 65997ms
rtt min/avg/max/mdev = 0.198/0.742/20.167/2.472 ms

The proof that the failover has happened can be found in the ARP table - which now has the assignment for the VIP address to the HostB's MAC (previousle Backup keepalived server).

krychu@krystianek:~$ arp -an
...
? (192.168.122.50) at 52:54:00:56:c3:f4 [ether] on virbr0
...

In the wireshark we see that the backup node (HostB) has sent the Gratuitous ARP message to a broadcast MAC announcing that he is the one owning now the VIP address. Afterwards the client station has updated it's ARP cache table.
If we check the keepalived logs on the HostB one can see that after the crash of the HostA has been detected the keepalived is transitioning from the BACKUP to MASTER state:

Sep 11 09:50:49 centOS-hostB Keepalived_vrrp: Using LinkWatch kernel netlink reflector...
Sep 11 09:50:49 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
Sep 11 09:50:49 centOS-hostB Keepalived_vrrp: VRRP sockpool: [ifindex(2), proto(112), fd(10,11)]
Sep 11 10:55:04 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Sep 11 10:55:05 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Sep 11 10:55:05 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Sep 11 10:55:05 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.122.50
Sep 11 10:55:10 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.122.50
Sep 11 10:55:45 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Received higher prio advert
Sep 11 10:55:45 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
Sep 11 10:55:45 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) removing protocol VIPs.
Sep 11 10:58:35 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Sep 11 10:58:36 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Sep 11 10:58:36 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Sep 11 10:58:36 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.122.50
Sep 11 10:58:41 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.122.50
Sep 11 11:32:40 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Received higher prio advert
Sep 11 11:32:40 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
Sep 11 11:32:40 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) removing protocol VIPs.
Sep 11 11:39:54 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Sep 11 11:39:55 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Sep 11 11:39:55 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Sep 11 11:39:55 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.122.50
Sep 11 11:40:00 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.122.50


Case B The master is back (Host A)

Now let's focus on the situation when the Host A is brought back after a crash. Just as a reminder the situation is that after a crash HostB took over the Master role, owns the VIP address and the client station has an association to HostB's MAC in its ARP table.
The methodology is similar as in Case A:
  1. We constantly ping the VIP address from the client station
  2. We start the keepalived on the HostA
  3. We check ping output if there was a smooth failover
  4. We check the ARP table which MAC is used
  5. We sniff the interface to get the information what caused the client's machine ARP table update
After issuing step 1 and 2 we see again an increase in the response time in the ICMP traffic but much smaller than in case of the crash.

krychu@krystianek:~$ ping 192.168.122.50
PING 192.168.122.50 (192.168.122.50) 56(84) bytes of data.
...
64 bytes from 192.168.122.50: icmp_req=23 ttl=64 time=0.191 ms
64 bytes from 192.168.122.50: icmp_req=24 ttl=64 time=0.346 ms
64 bytes from 192.168.122.50: icmp_req=25 ttl=64 time=0.331 ms
64 bytes from 192.168.122.50: icmp_req=26 ttl=64 time=0.291 ms
64 bytes from 192.168.122.50: icmp_req=27 ttl=64 time=2.53 ms
64 bytes from 192.168.122.50: icmp_req=28 ttl=64 time=0.315 ms
64 bytes from 192.168.122.50: icmp_req=29 ttl=64 time=0.338 ms
...

However it is still not a proof that a failover actually has happened. Let's take a look at the client station's ARP table:

krychu@krystianek:~$ arp -an
...
? (192.168.122.50) at 52:54:00:03:ba:f2 [ether] on virbr0
...

We see that the original mapping (presented in case A), which was pointing to HostB's MAC now points to HostA's. Which indicates the VIP address is now owned by the HostA again. In the wireshark we again see the Gratuitous ARP message to a broadcast MAC announcing sent by the HostA. On this basis the client station has updated it's ARP cache table.

In the logs on HostB one can find the information that after startup of HostA keepalived on HostB is transitioning to BACKUP state since it has received an announcement with a higher priority (review the configuration files from part 1)

Sep 11 10:55:45 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
Sep 11 10:55:45 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) removing protocol VIPs.
Sep 11 10:58:35 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Sep 11 10:58:36 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Sep 11 10:58:36 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Sep 11 10:58:36 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.122.50
Sep 11 10:58:41 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.122.50
Sep 11 11:32:40 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Received higher prio advert
Sep 11 11:32:40 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
Sep 11 11:32:40 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) removing protocol VIPs.
Sep 11 11:39:54 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Sep 11 11:39:55 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Sep 11 11:39:55 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Sep 11 11:39:55 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.122.50
Sep 11 11:40:00 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.122.50
Sep 11 11:57:32 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Received higher prio advert
Sep 11 11:57:32 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
Sep 11 11:57:32 centOS-hostB Keepalived_vrrp: VRRP_Instance(VI_1) removing protocol VIPs.

Summary

I hope that this exercise gave you a good understaning of the mechanisms controlling the VIP address failover in the keepalived and also some practical knowledge about how to setup such a test environment. For me this activity has been a great experience and fun. I think also it is a good base for further research - about the failure detection mechanisms (happening on the interconnect interface) and providing the application (e.g. HAProxy) on top of keepalived. 

Just to summarize the VIP address failover is controlled by a special ARP message (Gratuitous ARP) which has to be accepted and processed by the client station. By processing I mean that the client's station's ARP table mapping have to be updated accordingly.

From the software perspective - the keepalived daemon allows to configure the VIP failover groups and  assign MASTER, BACKUP roles for hosts within such a group. There is also a failure detection available which works fast (for a genuine keepalived configuration it was not higher than 20 ms) and controls the VIP address ownership.

Linux: Configuring cluster VIP (Virtual IP) with keepalived: Part 1

Some time ago I had a discussion about open source load balancing solutions (e.g. HAProxy)  especially with the focus on HA and VIP address failover (by VIP address failover we meant that the public IP is moved to the second node in case the first one is shutdown). It came to me that I have never in practice done that and I decided to built up such a solution - just to check the second point, namely the VIP address failover. For that I used my Ubuntu box together with two virtualized environments based on CentOS (these I had already available in kvm) - the configuration is shown on the picture below:

+
Figure 1 Network deployment of the test environment for
the keepalived's VIP failover
Ok, having the picture in mind let's get to work.

Test envrionment setup

The presented below points show how to configure it:
  1. Define additional Interconnect network. For doing that I used the virt-manager GUI: Edit->Connection Details and there should a window appear (just as the one presented on the Figure 2). In the Virtual Networks tab you should add a new network (a '+' button in the bottom of the window)
    Figure 2 Interconnect virtual network
  2. Install two machines (Host A and B) that will be hosting the keepalived. I already had one CentOS kvm which I cloned to have the Host B (using virt-manager it is very simple and can be done via main GUI)
  3. Install keepalived. CentOS does not have the keepalived in its repos so I had to download the latest sources from the web: http://www.keepalived.org/software/keepalived-1.2.2.tar.gz. After unpacking I did not have to download any additional dependencies and I just followed the INSTALL instructions - as usual steps: configure, make, make install ;) In order to build the keepalived only once (for two hosts) you might also install it before cloning the image (after the image has been cloned it has the keepalived).
  4. Configure sysctl. In the manual I read that one should enhance the sysctl configuration in order to allow the application to bind to non local addresses - add these line to /etc/sysctl.conf:
     net.ipv4.ip_nonlocal_bind = 1
    and execute:
     sysctl -p
  5. Reconfigure firewall. The keepalived utilizes multicast address (224.0.0.18) for exchanging information about the status of the nodes belonging to specific groups. What needs to be done is to allow the multicast traffic to go over the Interconnect network (eth0) interface. In my case for testing purposes I have just disabled the firewall (in Gnome: System->Administration->Security Level and Firewall)
  6. Configure the master host (Host A). One needs to adapt or create the /etc/keepalived/keepalived.conf file as follows:
    [root@localhost ~]# cat /etc/keepalived/keepalived.conf
    vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 102
    virtual_ipaddress {
    192.168.122.50/24 brd 192.168.122.255 dev eth1 label eth1:0
    }
    }

    where eth0 is the interface for interconnect and eth1 is the interface for communication with external world (VIP)
  7. Configure the backup host (Host B). The configuration file /etc/keepalived/keepalived.conf would be mostly the same for both hosts (as for host A) - what one has to remember is to set the Host B into backup mode with lower priority
    [root@centos1-priv ~]# cat /etc/keepalived/keepalived.conf
    vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 101
    virtual_ipaddress {
    192.168.122.50/24 brd 192.168.122.255 dev eth1 label eth1:0
    }
    }

    where eth0 is the interface for interconnect and eth1 is the interface for communication with external world (VIP)

  8. Startup keepalived on both hosts. The best way to start the keepalived is to use the init/startup scripts provided with the source package
    # /etc/init.d/keepalived start
    If you cannot find the script you can get it from the keepalived source package
  9. Proceed to the test (see Part 2)

wtorek, 30 sierpnia 2011

Linux: Bootable USB stick with FreeDOS for upgrading BIOS

Today I was to upgrade a BIOS on one of the laptops (Dell Latitude E5400) that was running Linux Mint 11 distro. I downloaded a single .exe (in fact E5400A16.EXE - E5400 standing for the model, A16 for the version) file from the manufacturer (Dell) website which was to be used together with the bootable floppy. The main problem with that approach was that I did not have a floppy drive (which is not surprising as most of the current laptops do not have a floppy drive) so I had to find an alternative solution. The best idea for me was to create a bootable USB stick with FreeDOS under Linux, which is not that difficult since there is a great wiki that one can use to do it: http://en.gentoo-wiki.com/wiki/FreeDOS_Flash_Drive. I followed the guidelines with one exception namely that I used gparted for partitioning and formating the USB stick (below one can find the guidelines how to do it on Linux Mint 11 distro):
  1. If not already available install gparted from the repo:
    # sudo apt-get install gparted
  2. Start the gparted:
    # gparted
  3. Choose the device corresponding to you USB stick in the main menu gparted->devices - in my case it was /dev/sdb
  4. Remove any partitions if there are any
  5. Create a new partition table: Device->Create Partition Table
  6. Create a new partition: Partition->New and choose fat16 as the filesystem
  7. Format partition with fat16 filesystem: Partition->Format To
  8. Commit all operations: Edit->Apply all operations
  9. Exit gparted and follow guidelines from the wiki starting with the FreeDOS (next MBR, Last Touch etc.)
I hope that the reader will find these information helpful

poniedziałek, 29 sierpnia 2011

Ubuntu: importing Cisco VPN Client connections to vpnc (network manager)

Today I had to connect to my company's network via VPN and all I had from my windows workstation were the definition of the Cisco VPN Client connections in the .pcf format. Below I describe the steps to import these definitions into the network manager (vpnc).

  1. In the network-manager click on the VPN connections option 
  2. You should see a window with a list of configured VPN connections and there should be a button 'Import' to import an existing definition, e.g. in .pcf format
  3. Choose the .pcf file and the new connection shall be available

Problems



  1. vpnc plugin for network-manager - Please check if you have network-manager-vpnc package installed - which brings the plugin for the vpnc into the network manager. Otherwise you will face strange looking errors during import: Error: unknown PPTP file extension.
  2. Missing description - although I have not encountered this problem I found it in some articles on the internet and decided to mention it here. It concerns network-manager-vpnc versions below 0.7.1 - and it occurs when the .pcf file lacks the Description variable in the [main] section
  3. Routing configuration - please check if the routing is properly configured. In my case I had to define additional routes to company's servers which is not difficult and can be done either via script or via GUI - when you edit your VPN connection it is located in the IPv4 settings and routes (screenshot of the window can be found below)



sobota, 27 sierpnia 2011

Ubuntu: Nokia E52 as 3G modem on Natty 11.04 box

Last week I had some problems with the signal strength of the default 3G modem delivered by the operator (which appeared to be Huawei Technologies Co., Ltd. E220 HSDPA Modem / E270 HSDPA/HSUPA Modem) together with the so called Blueconnect offer (offered by the polish T-Mobile former ERA) while the signal strength on my mobile phone Nokia E52 seemed to be perfect. That is why I decided to try to connect with the Blueconnect using my mobile. The idea was to connect the phone to the laptop using the bluetooth and toward the radio network via 3G/GSM.


First of all I did a reference speed measurement on the using the original Huwaei modem (http://www.speedtest.net/) - the results are presented below:

 
Ok, as soon as I had the results I switch the card to my Nokia E52 mobile and started to configure the bluetooth connection. On Gnome there is a wizard for managing the bluetooth devices – it can be found System->Preferences->Bluetooth or as in my case if you are using gnome-do just type bluetooth in the gnome-do window and just follow the instructions as on the screenshots below (please remember to enable the DUN):











 Last but not least I did the bandwidth check and the results are slightly better than in case of Huawei modem but the most important is that the signal strength is more stable than before. The measurements were done at polish seaside (Gaski - 54.241018,15.892321)

środa, 3 sierpnia 2011

Ubuntu: sysstat chart generator utility

There is a new OSS utility that provides mechanisms for generating gnuplot charts out of the sysstat utilities (currently sar and pidstat are supported): http://code.google.com/p/yapcg/. Feel free to contribute and extend this project.
In the nearest future there shall be user guide added and UML model generated out of the code (currently it is enclosed the html api documentation - separate for each module).

Ubuntu: startup process respawn

Today I had a discussion with one of my colleagues about mechanisms for monitoring the process and respawning it if it dies. We discussed the approach via inittab or home made solution with external process monitor. I decided to check it on my ubuntu 11.04 Natty box and to my surprise there was not /etc/inittab file. After deeper investigation it seems that the upstart init daemon in ubuntu is configured via files located in the /etc/init director. Moreover it seems to offer a great piece of functionality that we needed, e.g. limiting the number of respawns in specific period of time.
The startup of services is controlled via the start command, which actually is a symbolic link to the initctl - please check the man for details.
I decided to check also if the number of respawns functionality really works - for that purpose I prepared a configuration file as below:

root@krystianek:/etc/init.d# cat /etc/init/test_respawn.conf 
description "Test respawn"


start on filesystem or runlevel [2345]
stop on runlevel [!2345]


respawn
respawn limit 10 5
umask 022


pre-start script
end script


exec /etc/init.d/test_respawn.sh
root@krystianek:/etc/init.d# 

Limiting the number of respawns to 10 in timeframe of 5 seconds. Next I prepared the test_respawn.sh script to count the actual number of restarts as below:

root@krystianek:/etc/init.d# cat /etc/init.d/test_respawn.sh 
#!/bin/sh


declare -i VALUE
echo "Testing respawn feature"
TMP_FILE=/tmp/count
if [ -f "$TMP_FILE" ]; then
  VALUE=`cat ${TMP_FILE}`
else
  VALUE=0
fi


VALUE=`expr $VALUE + 1`
echo $VALUE > ${TMP_FILE}
exit 1

The result shall be stored in the /tmp/count file. Now as everything is ready for the test it is time to do it:

root@krystianek:/etc/init.d# file /tmp/count
/tmp/count: ERROR: cannot open `/tmp/count' (No such file or directory)
root@krystianek:/etc/init.d# start test_respawn
test_respawn start/pre-start, process 8293
root@krystianek:/etc/init.d# cat /tmp/count
11

Voila the result is 11 (1 start attempt + 10 respawns).