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

Tuesday, December 20, 2005

[HOWTO] Postfix + SMTP AUTH + MySQL

Tested on: Fedora Core 4 (2.6.11-1.1369_FC4), MySQL-5.0.16

1.0 Getting the needed resources

Before installing postfix make sure the following packages are installed:


  • openssl-0.9.7f-7
Both packages above was pre-installed in Fedora Core 4. If needed, run

# up2date openssl

Download and install cyrus-sasl from this site, the cyrus-sasl version used in this HOWTO is 2.1.20

# mkdir /usr/src/cyrus-sasl
# cd /usr/src/cyrus-sasl
# wget ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.20.tar.gz
# tar zxvf cyrus-sasl-2.1.20.tar.gz
# cd cyrus-sasl-2.1.20
# ./configure --disable-krb4 --disable-gssapi --disable-otp
# make
# make install
# ln -s /usr/local/lib/sasl2 /usr/lib/sasl2

During the ./configure;make process, an error will occur like below:

client.c:64: error: static declaration of 'global_callbacks' follows non-static declaration

Locate the client.c file at /usr/src/cyrus-sasl-2.1.20/lib/ . Edit the file with your favourite editor find the statement "static sasl_global_callbacks_t global_callbacks;" and subsitute it as below:

# nano /usr/src/cyrus-sasl-2.1.20/lib/client.c

...
# Comment this line, remove the static keyword
#static sasl_global_callbacks_t global_callbacks;

sasl_global_callbacks_t global_callbacks;
...

Save the file, client.c. Re-run the command above.


Next, Postfix installation. Get the Postfix package and execute the following command:

# mkdir /usr/src/postfix/
# cd /usr/src/postfix/
# wget ftp://ftp.planetmirror.com/pub/postfix/official/postfix-2.2.7.tar.gz
# tar zxvf postfix-2.2.7.tar.gz
# cd postfix-2.2.7

The following command is to clean left over files from the previous build

# make tidy

#make makefiles CCARGS="-DUSE_TLS -DUSE_SASL_AUTH -I/usr/local/include/sasl -DHAS_MYSQL -I/usr/include/mysql" AUXLIBS="-lssl -lcrypto -L/usr/local/lib -lsasl2 -L/usr/lib/mysql -lmysqlclient -lz -lm"

Compile and install them

# make
# make install


Upon successful installation, you will be prompted to input some values. Just press 'enter' key to accept the default values.


[HOWTO] A2Billing

Note: Tested on Fedora Core 2( 2.6.5-1.358), MySQL-4.1.16, Asterisk-1.2

1.0 Download A2Billing
Be sure you have successfully installed Asterisk and MySQL before proceeding. This HOWTO will not cover the installation guide for Asterisk and MySQL.
# cd /usr/src
# mkdir a2bill
# cd a2bill
# wget http://www.areski.net/Open_A2Billing_version_Raccoon.tar.gz

Uncompress the package


# pwd
/usr/sr/a2bill/
# tar zxvf Open_A2Billing_version_Raccoon.tar.gz

2.0 Setting up A2Billing's MySQL database
Create the database for A2Billing, the database name is up to your own preference.
In this example the author will use 'a2bill'
( You might want to consider adding a mysql user, this exampleis done using the root user )

# mysql -p
enter password:
mysql> create database a2bill;
mysql> quit

If you database is not protect by password simply ignore the -p parameter. Next, dump the SQL
syntax into MySQL database.

# cd /usr/src/a2bill/
# mysql -p a2bill <>

To verify if database is AOK.

#mysql -p a2bill
password:
mysqlconsole> SELECT * FROM ui_authen;

This table ui_authen, stores the user information for the webUI users. The above command shall
return with two (2) records.

3.0 Installing php-pcntl module
php-pcntl is a php module that controls UNIX process creation, execution, signaling and
termination.This module is used to detect calls termination so asterisk will close
a2billing.php. If this module is not installed, you have have card in-use even though you have
hang up the call

The version might defer, depending on Fedora Version. For more information check
click here. Current version of php-pcntl is 4.3.10 (FC2), there will be dependency
problem if your php version differs.
Do an up2date (The command will download the latest php and assist you in dependencies issues.)
to grab the latest version of php:

# up2date php

Download and install php-pcntl

# cd /usr/src
# mkdir php-pcntl
# cd php-pcntl
# wget http://optusnet.dl.sourceforge.net/sourceforge/phprpms/php-pcntl-4.3.10-2.4.2.i386.rpm
# rpm -iUvh php-pcntl-4.3.10-2.4.2.i386.rpm


4.0 Installing A2Billing

Installing A2Billing is pretty simple, all you need to do is copy files to designated
directories. First copy the main configuration file, a2billing.conf (located at /usr/src/a2bill/)
to /etc/asterisk/.

# cd /usr/src/a2bill/
# cp a2billing.conf /etc/asterisk/.

This config, a2billing.conf, consist of several main sections:

[database]
~Mainly specifies database connection

[webUI]
~Web Interface customization

[recprocess]
~configuration for the recurring process(cront job) *i've not used it*

[agi-confX]
~Define the behaviour of AGI script (a2billing.php). This section can be customize according
to end-customer's preferences.
*Note: X is replace with numbers you can have multiple agi-conf eg: agi-conf1, agi-conf2


Next, copy the 'rate.inc' file to /etc/asterisk. The file contains the currency rates of most countries

# pwd
/usr/src/a2bill/
# cp rates.inc /etc/asterisk/.

Now, we shall copy the web interface files to httpd document root. There are types of web
user interface, one for admin the other for customers, copy both to httpd document root. httpd
document root for fedora is located at /var/www/html/ may vary depending on operating system.

Copy the admin web interface to /var/www/html/ and rename the directory to a2bill/

# pwd
/usr/src/a2bill/
# cp -rf A2Billing_UI /var/www/html/.
# mv /var/www/html/A2Billing_UI/ /var/www/html/a2bill/

Copy the customer web interface to /var/www/html/ and rename the directory to a2billcust/

# pwd
/usr/src/a2bill/
# cp -rf A2BCustomer_UI /var/www/html/
# mv /var/www/html/A2BCustomer/ /var/www/html/a2billcust/

Lastly, copy the content in A2Billing_AGI/ directory to /var/lib/asterisk/agi-bin/

# cd /usr/src/a2bill/A2Billing_AGI
# cp a2billing.php /var/lib/asterisk/agi-bin/.
# cp -rf libs_a2billing/ /var/lib/asterisk/agi-bin/.
# chmod +x /var/lib/asterisk/agi-bin/a2billing.php

Copy the required sound files to /var/lib/asterisk/sounds/

# cp sound/* /var/lib/asterisk/sounds/.
# cp sound/en/* /var/lib/asterisk/sounds/.

5.0 Configuring A2Billing


Thursday, December 15, 2005

[HOWTO] FreeRadius

NOTE: Tested on Fedora Core 2(2.6.5-1.358), MySQL 4.1.14 and FreeRadius-1.0.4

1. Download FreeRadius and MySQL


You need to first obtain radius and MySQL


# mkdir /usr/src/freeradius
# cd /usr/src/
# wget ftp://ftp.freeradius.org/pub/radius/old/freeradius-1.0.4.tar.gz


For mysql you need to download the following packages:
  • MySQL-server
  • MySQL-client
  • MySQL-devel
  • MySQL-shared-compat
2. Install MySQL

To install MySQL, execute the command below according to sequence:
# rpm -iUvh MySQL-shared-compat-4.1.14-0.i386.rpm
# rpm -iUvh MySQL-server-4.1.14-0.i386.rpm
# rpm -iUvh MySQL-client-4.1.14-0.i386.rpm
# rpm -iUvh MySQL-devil-4.1.14-0.i386.rpm

3. Install FreeRadius

Go to the directory where you downloaded FreeRadius-1.0.X.tar.gz

# cd /usr/src/freeradius
# tar zxvf freeradius-1.0.4.tar.gz
# cd freeradius-1.0.4
# ./configure --with-experimental-modules
# make
# make install

The options --with-experimental-modules is to load rlm_sqlcounter module which enable you to use 'Session-Timeout' attribute for prepaid system.

Once accomplished, the configuration files can be found at /usr/local/etc/raddb/ the main config file will be radiusd.conf, clients.conf and sqlcounter.conf (for prepaid system)