setting up Nagios on Ubuntu 8.10 server part 1/3

Building Nagios and configure checks via NRPE on Ubuntu 8.10-Server.
Start with a fresh installation of Ubuntu Server v8.10 i386 or amd64. You can add LAMP services using the next commands

apt-get packages.
Install supporting packages for running apache+php5, postfix, build tools and libraries for compiling plugins.

*NOTE:* If you installed the LAMP services the first 3 packages are redundant. It's safe to run these commands either way.

sudo apt-get update sudo apt-get install apache2 sudo apt-get install php5 sudo apt-get install libapache2-mod-php5 sudo apt-get install snmpd sudo apt-get install snmp       # No this isn't a typo, we need this to compile the check_snmp plugin. sudo apt-get install build-essential sudo apt-get install postfix    # when prompted for install type choose 'internet site'. sudo apt-get install mailx sudo apt-get install libmysql++-dev sudo apt-get install libgd2-xpm-dev sudo apt-get install libssl-dev sudo apt-get install libpq-dev sudo apt-get install postgresql-server-dev-8.3 sudo apt-get install fping sudo apt-get install smbclient

Install useful perl modules. chose 'Yes' to any of the question prompts in cpan.
sudo cpan YAML sudo cpan Net::SNMP

Add nagios user and groups.

When you run 'useradd' command in Linux/Ubuntu a group will be automatically created and associated as the user's primary group.
Make sure to add the user www-data to the nagcmd group otherwise apache can not write to the nagios command channel(fifo file) in /usr/local/nagios/var/rw/nagios.cmd.

sudo groupadd nagcmd sudo groupadd nagios sudo useradd -G nagcmd -g nagios nagios

sudo vi /etc/group

Download, configure & install nagios, plugins, and NRPE
Download and compile nagios, nagios-plugins, and nrpe Add-On.

Download and unpack files.

mkdir nagios-files cd nagios-files wget http://superb-west.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.6.tar.gz wget http://superb-west.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz wget http://superb-west.dl.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz for i in `ls *.gz`; do tar -zxf $i; done

Configure, compile and install nagios.

cd nagios-3.0.6 ./configure --prefix=/usr/local/nagios/ --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd --with-httpd-conf=/etc/apache2/conf.d/ --with-init-dir=/etc/init.d/ make make all make install && make install-init && make install-commandmode && make install-config && make install-webconf

Configure, compile and install nagios plugins. Make sure to watch for errors/warnings during configure for plugins not compiled due to missing dependencies. if the 'snmp' package isn't install you wont get check_snmp. That makes nagios a bit less useful. ;)

cd ../nagios-plugins-1.4.13 ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios make && make all sudo make install

Finally, configure, compile and install the NRPE add-on. This lets us run nagios-plugins on a remote host when they are install. The remote host should have the check_* commands installed as well as the NRPE add-on like we are doing on the server.
Verify that NRPE and nagios user/groups are all nagios, port is 5666 before running 'make.
Read the "README" file for notes on using the check_nrpe command(_you'll need to add this manually to commands.cfg_) and for setting up

cd ../nrpe-2.12/ ./configure --prefix=/usr/local/nagios make all make install printf "nrpe\t\t5666/tcp\t\t# NRPE" >>/etc/services

Fix Postfix configuration
It appears something is broken in the Postfix auto configuration for the "internet site" install option. You will need to edit/etc/postfix/main.cf to fix the auto configuration.

sudo vi /etc/postfix/main.cf

# Uncomment the the line:
myorigin = /etc/mailname

# Remove the root dot "." at the end of your domain on lines beginning with:
myhostname = example.com
mydestination = example.com, localhost

fix /etc/mailname _(if you don't want mail coming from nagios@host0.office.example.com.)_
By default the FQDN of this server will be set in this file. e.g. host0.office.example.com.
This is a debian/ubuntu centric configuration file not normally found on any other UNIX or Linux distro. all mail sent via 'mail' command will use the contents of this file as the sending domain. in some cases this is what you want. In my case I need mail to be sent from user@example.com so we need to change this file to contain only "example.com".
sudo vi /etc/mailname

Finally restart postfix.
sudo service postfix restart

Send a test message
Verify that we will actually receive messages sent from this host.

echo "This is the message body.\n Test from my new nagios server." | /usr/bin/mail -s "Subject of Nagios Server TEST message" you@example.com
*Note: Use the 'mailq' command to view the postfix mail queue on the system and find any errors with sending mail messages.*