Zeng Yang a.k.a H o w T o

Google

Sunday, January 22, 2006

[HOWTO] Heartbeat

Tested on: Fedora Core 2 (2.6.5-1.358-smp) running heartbeat-1.2.3
Note: Both Servers running the same hardware specification


1.0 Connecting & Setting Two Nodes (Servers)

Figure 1.0: Connecting primary and secondary servers with null modem cable and cat-5 cross over cable

Heartbeat is one of the program used to provide high availability (HA) to servers. It is a IP fail-over program. Where two servers, one primary and one secondary, when the primary server fails, the secondary server will take over the primary server's IP address. Hence, it will not caused downtime due to primary server failure. The above figure, represents how both servers are connected and ensure IP fail-over works.

Primary server will take back its IP address once it's booted up.

1.1 Set the local IP address for Heartbeat to communicate.

Primary Server * using eth1

# vi /etc/sysconfig/network-script/ifcfg-eth1
IPADDR=10.0.0.1
NETMASK=255.255.255.0

Secondary Server * using eth1
# vi /etc/sysconfig/network-script/ifcfg-eth1
IPADDR=10.0.0.2
NETMASK=255.255.255.0

Next, ping both IP address from both servers, make sure there are replies.


1.2 Test the Null Modem Serial Cable

Do the following simultanously to monitor the connection:

(receiver) Primary Srv shell: $ cat < /dev/ttyS0 (sender) Secondary Srv shell: $ echo hello > /dev/ttyS0
(receiver) Primary Srv shell: $
(receiver) Primary Srv shell: hello

The primary server which is a receiver ( cat < /dev/ttyS0 ) must be able to receive the message 'hello' from secondary server. Try again, primary become sender and secondary become receiver.


2.0 Installation

2.1 Installing...

Install libnet.tar.gz
Download heartbeat stable version and two (2) dependency files from:

Heartbeat-1.2.3
Heartbeat-pils-1.2.3
Heartbeat-stonith-1.2.3

Download to /usr/src

# cd /usr/src
# rpm -iUvh heartbeat-pils-1.2.3-2.fr.c.1.i386.rpm
# rpm -iUvh heartbeat-stonith-1.2.3-2.fr.c.1.i386.rpm
# rpm -iUvh heartbeat-1.2.3-2.fr.c.1.i386.rpm

2.2 Post Installation

Move the configuration files to /usr/local/etc/ha.d

# cd /usr/share/doc/heartbeat-1.2.3
# cp ha.cd /etc/ha.d
# cp haresources /etc/ha.d
# cp authkeys /etc/ha.d

3.0 Configuring Heartbeat.
* NOTE: Performed the SAME configuration on BOTH primary and secondary server.

3.1 /etc/ha.d/ha.cf

Edit the ha.cf with the following configuration.

# vi /etc/ha.d/ha.cf
serial /dev/ttyS0
baud 19200
bcast eth1
udpport 694
keepalive 2
deadtime 30
node uname -n>
node uname -n>
logfile /var/log/ha-log
initdead 120
auto_failback on
respawn hacluster /usr/lib/heartbeat/ipfail

3.2 /etc/ha.d/haresouces

Edit the virtual IP (cluster IP) in this file, /etc/ha.d/haresources

# vi /etc/a.d/haresources
eg: radius1 202.171.50.10

3.3 /etc/ha.d/authkeys

# chmod 600 /etc/ha.d/authkeys
# vi /etc/ha.d/authkeys
auth 3
3 md5

The following command to start and stop heartbeat

# /etc/rc.d/init.d/heartbeat start
# /etc/rc.d/init.d/heartbeat stop
# /etc/rc.d/init.d/heartbeat status


Wednesday, January 18, 2006

[HOWTO] STUN

Tested on: Fedora Core 2 2.6.5-1.358smp, Vovida stund_0.96

What is STUN?
STUN or Simple Traversal of UDP over NAT is a type of network protocol that helps clients behind NAT to identify their public IP. This is one of the solutions used to overcome the famous VoIP NAT issue.

The STUN server gonna be used is provided by Vovida , it requires two NIC (each NIC with different IP) for the STUN server to work.

1.0 Getting the package

Download stun from here

# mkdir -p /usr/src/stun
# cd /usr/src/stun
# wget http://switch.dl.sourceforge.net/sourceforge/stun/stund_0.96_Aug13.tgz


This is a pretty simple stand alone program, all you need to do is just untar, compile and run it.

# tar zxvf stund_0.96_Aug13.tgz
# cd stund
# make


At this point, there should be two executable files in /usr/src/stun/stund/ name `client` and `server`. `server` is the program going to do translation job whereas, `client` is meant to test if the `server` is working fine.


2.0 Firing up the server

To run the server execute the command below:

# /usr/src/stun/stund/server -b -h [primary ip]
-a [secondary ip]

You will probably be annoyed by the * that keeps popping up on the console. What I did was exiting the console and firing it up again.

Replace the primary and secondary IP with the IPs you set in your NICs. Here are some explanation of parameters used in the command above

-b to tell stun server to run on background mode after console closed
-h primary IP
-a secondary IP

For further explanation you can execute --help parameter.

3.0 Is it really working?

You can test whether or not is working with the `client` program you have compile when executing the `make` command. Here is how you should run the `client` program

# /usr/src/stun/stund/client
STUN client version 0.96
Primary: Open
Return value is 0x000001


The result should be as above. If the STUN server ain't running you will get the result below

STUN client version 0.96
Primary: Blocked or could not reach STUN server
Return value is 0x00001c


Alternatives you can use programs like `netstat` and `ngrep` to check the connections to the STUN server. Example:

# netsat -an | grep 3478

This is to check whether the port 3478 ( STUN default port ) is open or not

# ngrep port 3478

This will monitor incoming STUN connections ( Required to install `ngrep`)