Monday, June 18, 2007

Setting up Cacti monitoring

Firstly, I know there should be a post which covers Nagios and I am in process of making up that one. I will get that on as soon as I am done with that.

Cacti

Cacti is a monitoring tool which has a very impressive User interface and is actually a frontend for the RRDTOOLS. It enhances the capabilities of rrdtools to the fullest. Cacti basically works on data collected by SNMP and graphs are plotted using Rrdtools which gives quite an overview of a system/network. MySql is the database used to store all the data collected.
Prerequisites:
  • Rrdtools
  • Apache with PHP support
  • php
  • snmp
  • net-snmp
  • php-snmp
  • Mysql server
Installation:

RRDTools:

Download RRDTools as per your hardware architecture and OS:
For Debian/Ubuntu:
http://packages.debian.org/stable/utils/rrdtool
For Redhat/CentOS/Fedora:
http://dag.wieers.com/rpm/packages/rrdtool

NOTE: Optionally, if your distro package manager (yum,apt-get,etc.) repositories are well updated you can install the same using the package manager. Most repositories contain rrdtools these days.


Apache with php support:
Note: I am considering the apache installation doesnot exist, if it does skip the apache installation and test if php support is enabled.

Issue the following commands as a root:

root@dork~ # wget -c http://www.hightechimpact.com/Apache/httpd/httpd-2.0.59.tar.gz
- Downloading the Apache source code from apache.org mirror site.

root@dork~ # tar zxpf httpd-2.0.59.tar.gz
- Extracting the downloaded content.

root@dork~ # cd httpd-2.0.59
- Change directory

root@dork~/httpd-2.0.59 # chmod a+x build.sh
- Adding the execute permission for build.sh.

root@dork~/httpd-2.0.59 # sh build.sh
- Executing build.sh, which basically is a shell script used for compiling apache with most of the frequently used and necessary options enabled. Optionally you can run ./configure

root@dork~/httpd-2.0.59 # make && make install
- Upon successfully configuring the sources, 'make' will compile all the data and 'make install' should install apache to /usr/local/apache.


Php:

root@dork~ # wget -c http://us.php.net/get/php-5.2.3.tar.gz/from/us2.php.net/mirror
- Downloading php sources

root@dork~
# tar zxpf php-5.2.3.tar.gz
-Unzipping the content downloaded.

root@dork~
# cd php-5.2.3
- Changing directory

root@dork~/php-5.2.3
# ./configure --with-apxs2=/usr/local/apache/bin/apxs --with-mysql
- Installing PHP for the apache we just installed with MySql support.

root@dork~/php-5.2.3
# make && make install
- This should compile the sources and install them to the default path.

root@dork~/php-5.2.3
# cp php.ini-dist /usr/local/lib/php.ini
- Setting up deafult php parameters in php.ini.

Add the following lines to /usr/local/apache/conf/httpd.conf:

LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php .phtml

Restart the apache service:
root@dork~
# /usr/local/apache/bin/apachectl restart

If apache is already installed check that
'LoadModule php5_module modules/libphp5.so' exists in /etc/httpd/conf/httpd.conf for Redhat based distros or /etc/apache2/httpd.conf for Debian based distros.

Other packages:

For Fedora/Redhat:
root@dork~ # yum install snmp
mysql-server net-snmp php-snmp

(if yum aint installed, RPM packages are easily available or can be installed from the install disks.)

For Debian/Ubuntu:
root@dork~ # apt-get install mysql-server snmp
net-snmp php-snmp

MySql:

root@dork~ # /etc/init.d/mysqld start
- Starting mysql service.

root@dork~ # mysql -u root
- Connecting to mysql database, this will get you to mysql console where type in the following queries:
mysql> create database cacti;
mysql> grant all on cacti.* to root;
mysql> grant all on cacti.* to root@localhost;
mysql> grant all on cacti.* to cacti;
mysql> grant all on cacti.* to cacti@localhost;
mysql> set password for cacti@localhost=password('set_DB_passwd');
mysql> flush privileges;
mysql> commit;
mysql> exit

This should create a cacti database in mysql on which root and user cacti will be having all the grants required for Cacti to function smoothly.


Installing Cacti:

Now comes the fun part :))
Starting off with installing the main package, issue the following commands:

root@dork~ # groupadd cacti
root@dork~ # useradd -g cacti cacti
Note: As the time passes, Cacti generates a lot of data. In case you have structured disk space for application specific environment or for backup purpose, it is always a good idea to have the home directory on some other partition than /home. For me, I have it at /var/home/cacti.

root@dork~ # su - cacti

cacti@dork~ $ wget -c http://internap.dl.sourceforge.net/sourceforge/cacti/cacti-0.8.6j.tar.gz
- Downloading the cacti application.

cacti@dork~ $ tar zxpf cacti-0.8.6j.tar.gz
- Extracting the content.

cacti@dork~ $ ln -sf cacti-0.8.6j cacti
- Creating a softlink for easier access, just quickly run through all the permissions so that there wont be any problems.

cacti@dork~ $ cd cacti
- Changing directory

cacti@dork~ $ mysql --user=cacti --password cacti < style="font-weight: bold;">/home/cactiuser/cacti/include/config.php


$database_default ="cactidb;"
$database_hostname ="localhost;"
$database_username ="cacti;"
$database_password ="set_DB_passwd"


Add the following line to /etc/crontab:

*/5 * * * * cactiuser php /home/cactiuser/cacti/poller.php > /dev/null 2>&1


Add an alias
or virtual host in your apache configuration file:

Alias /cacti/ "/home/cactiuser/cacti/"


Save and restart the
apache and mysql service.

After restarting the service, open your browser and type the URL as
http://localhost/cacti or http://server_IP/cacti and follow the installation instructions wizard that is launched. Upon successful completion of this, when prompted for login the default user/pass is admin/admin.

Hope this gets you started :))


Monday, May 28, 2007

Setting up Ubuntu common stuff

Repositories:

First of all, a basic know how about the application manager. Ubuntu is Debian based and has an excellent integration of "apt-get" or "aptitude" which is the default application manager.
Now we will add software repositories for aptitude to download and install various applications as per our need, for which visit http://www.ubuntu-nl.org/source-o-matic where you select the version of Ubuntu you are using and the architecture. This will generate the list of all the valid available repositories from where we can download the applications that we require. Copy all the lines that are generated and follow these steps:

uniks@uranium:~$ sudo mv /etc/apt/sources.list /etc/apt/sources.list.ORIG
uniks@uranium:~$ sudo gedit /etc/apt/sources.list

This should backup the current sources.list and open a copy of the same for editing in GEDIT editor. Paste all the lines generated by SOURCE-O-MATIC in this file and

uniks@uranium:~$ sudo apt-get update
uniks@uranium:~$ sudo apt-get upgrade

Optionally, if you are using Ubuntu 7.04 (Fiest) you can add these to sources.list:
deb http://us.archive.ubuntu.com/ubuntu fiesty main restricted
deb-src http://us.archive.ubuntu.com/ubuntu fiesty main restricted

## MAJOR BUG FIX UPDATES produced after the final release
deb http://us.archive.ubuntu.com/ubuntu fiesty-updates main restricted
deb-src http://us.archive.ubuntu.com/ubuntu fiesty-updates main restricted

## UBUNTU SECURITY UPDATES
deb http://security.ubuntu.com/ubuntu fiesty-security main restricted
deb-src http://security.ubuntu.com/ubuntu fiesty-security main restricted

deb http://security.ubuntu.com/ubuntu fiesty-security universe
deb-src http://security.ubuntu.com/ubuntu fiesty-security universe

## UNIVERSE AND MULTIVERSE REPOSITORY (Unsupported by Ubuntu. Use at own risk.)
deb http://archive.ubuntu.com/ubuntu fiesty universe multiverse
deb-src http://archive.ubuntu.com/ubuntu fiesty universe multiverse

## PLF REPOSITORY (Unsupported. May contain illegal packages. Use at own risk.)
deb http://packages.freecontrib.org/ubuntu/plf fiesty free non-free
deb-src http://packages.freecontrib.org/ubuntu/plf fiesty free non-free
Now we are all set to get things running. You can install packages using
sudo apt-get install like

uniks@uranium:~$ sudo apt-get install gftp
where, gftp is the package name.

Installing Multimedia Codecs

Issue the following commands:

uniks@uranium:~$ sudo apt-get install gstreamer0.10-plugins gstreamer0.10-lame gstreamer0.10-ffmpeg gstreamer0.10-lame lame sox ffmpeg mjpegtools vorbis-tools w32codecs gst-register-0.10 libmad0

DVD Playback:

uniks@uranium:~$ sudo apt-get install libdvdcss2




Monday, May 14, 2007

Linux High Availablity CLUSTER

Hardware configuration that I used for making a cluster:

clusternode1: Intel P4 2.66 GHz., 256 MB RAM, Two ethernet adapters.
clusternode2: Intel P4 2.4 GHz., 512 MB RAM, Two ethernet adapters.

I assigned clusternode1 which I will be calling CN1's eth0 with an IP 10.31.15.221 and clusternode2 which I will be calling CN2's eth0 with 10.31.15.222. I have kept 10.31.15.223 reserved for later use as we will be using this IP as our cluster IP, which of course will be a virtual IP :)

Now I assign eth1 interface for the 2 CNs i.e. CN1's eth1: 192.168.0.1 and CN2's eth1: 192.168.0.2.

The eth1 interface will be used for heartheat check and will be having its seperate network which will not be talking to the LAN in any way, where as the eth0 will be connected to the LAN.

Installation:

Prerequisites:

The following packages are required before we can start with the installation for the heartbeat application:
(Note: you will require to check the versions compatible with you current operating system and install as per your operating system recommendations, the versions mentioned below are the ones that were compatible with the OS I was using and they need not be the same)
  • perl-Authen-SASL-2.08
  • perl-Convert-ASN1-0.18
  • perl-Crypt-SSLeay-0.51
  • perl-Digest-HMAC-1.01
  • perl-Digest-SHA1-2.01
  • perl-IO-Socket-SSL-0.96
  • perl-ldap-0.3202
  • perl-Mail-IMAPClient-2.2.9
  • perl-Net-DNS-0.31-3
  • perl-Net-SSLeay-1.22-2
  • perl-Parse-RecDescent-1.94
  • perl-XML-NamespaceSupport-1.08
  • perl-XML-SAX-0.12

We will now require to install the following packages:
  • heartbeat
  • heartbeat-ldirectord
  • heartbeat-pils
  • heartbeat-stonith
For Fedora:
# yum install heartbeat
#
yum install heartbeat pils stonith ldirectord

For Debian/Ubuntu:
# apt-get install heartbeat pils stonith ldirectord

For RHEL-compatible:
RPMs are available for download at:
i386: http://mirror.centos.org/centos/4/extras/i386/RPMS/
x86_64: http://mirror.centos.org/centos/4/extras/x86_64/RPMS/

For Gentoo:
#
emerge heartbeat


Configuration of Heartbeat and Apache:

Post installation, edit /etc/ha.d/authkeys and add the following two lines:

auth 1
1 crc

Also, edit the /etc/ha.d/ha.cf to include the following lines:

debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
deadtime 5 # how long before the host is declared down
udpport 694 # UDP port used for broadcasting
bcast eth1 # interfaces to broadcast heartbeats
auto_failback on
node CN1 # Defining which machine is a part of cluster
node CN2 # Defining which machine is a part of cluster

Now edit the /etc/ha.d/ha.cf/haresources which will look like:

mycluster 10.31.15.223 httpd # here, mycluster is the clustername that will appear when I issue uname -n.

After which, start/restart httpd:

# /etc/ha.d/httpd start
OR
# /etc/init.d/httpd

When done with the configuration of CN1, you can copy the files to CN2. In /etc/ha.d/rc.d you will find the script called ip-request which will do the job of assigning the ip address etc.
now start /etc/rc.d/init.d/heartbeat on both machines.

Install a different index page on the machines to be served by the http server, using below commands.

echo hello world from CN1 > index.html

echo hello world from CN2 > index.html

Note: Ensure that on both nodes, httpd does not start when the OS boots

Testing the failover cluster:

Ensure that you are able to browse the page http://10.31.15.223 and it shows “index.html” of CN1.

Now, shut down or remove both the network cables of clusternode1 and try to browse the page http://10.31.15.223 and it should show the “index.html” of CN2. You can also verify the IP 10.31.15.223 assigned to CN2 by using ifconfig command or also by reading the log file /var/log/ha-debug.

To keep a synchronization you can setup a cronjob to copy the data from CN1 of /var/www/html to CN2 /var/www/html. I would recommend using rsync for this ;))

Friday, April 27, 2007

Setting up firefox32 with flash plugins and avant-window-manager (OSX) on AMD64

You need to make sure that universe and multiverse repositories are enabled in your /etc/apt/sources.list before doing anything.

First we need to make sure some packages are installed.Open a terminal and enter the following:

uniks@uranium:~$ sudo apt-get install ia32-libs lib32asound2 lib32ncurses5 ia32-libs-sdl ia32-libs-gtk gsfonts gsfonts-x11 linux32

Download Firefox32 and ialib32-firefox-amd64 and enter the following command:
uniks@uranium:~$ sudo dpkg -i ia32-lib-firefox-amd64.deb firefox32-1.5.0.7-2-ubuntu-amd64.deb

Now to make sure we always run 32bit version instead of AMD64 (of course you can run your AMD64 version too if you miss it too much :P )

uniks@uranium:~$ sudo mv /usr/bin/firefox /usr/bin/firefox64
uniks@uranium:~$ sudo ln -sf /usr/local/bin/firefox32 /usr/bin/firefox

If you decide you want to run 64bit firefox, press ALT+F2 and type there firefox64 and that should get you going.

Download Flashplayer and type the following commands:

uniks@uranium:~$ tar -zxpvf install_flash_player_9_linux.tar.gz
uniks@uranium:~$ cd install_flash_player_9_linux
uniks@uranium:~$ cp -rf libflashplayer.so /usr/lib32/firefox32/plugins/
uniks@uranium:~$ cp -rf flashplayer.xpt /usr/lib32/firefox32/plugins/

Restart your browser ;)

Avant:

Note: To run this window manager, you require either Beryl or Compiz running or the visual effect is not really good with an unpleasant black shadow bar occupying the bottom of your screen.

This one is quite simple, download Avant-Window-manager and Affinity-search and issue the following commands:
uniks@uranium:~$ sudo dpkg -i avant-window-navigator_0.1.1-svn-1_amd64.deb
uniks@uranium:~$ sudo dpkg -i affinity_0.1-1_amd64.deb

After installation, make sure either Beryl or Compiz is running and run the following command after pressing ALT+F2:
avant-window-manager

This should get you the Mac OS X like window manager, you can prefferably delete the bottom panel which manages your windows ;))