This post originated from an RSS feed registered with Python Buzz
by Phillip Pearson.
Original Post: Configuring Nagios 3 on Debian 5.0 (Lenny)
Feed Title: Second p0st
Feed URL: http://www.myelin.co.nz/post/rss.xml
Feed Description: Tech notes and web hackery from the guy that brought you bzero, Python Community Server, the Blogging Ecosystem and the Internet Topic Exchange
I've configured a few Nagios installations now, and just finished helping a friend configure another, so it's about time I wrote down some instructions for getting started from scratch.
The key thing to understand about Nagios is that hosts live in hostgroups, that services run on hosts and are checked by commands, and that services can be associated with hosts or (usually) hostgroups. If a service is associated with a hostgroup, all hosts in the group are checked. If a service is associated with a host, only that host is checked.
I'm running through a basic Nagios 3 installation now on a new Debian Lenny EC2 instance (ami-10d73379). I'm using the mg text editor, because it works like emacs but is quicker to download, but you can use vim, nano, emacs, or whatever you prefer.
apt-get update && apt-get install nagios3 mg less
First I make a user entry for myself:
cd /etc/nagios3; htpasswd -c htpasswd.users nagiosadmin
Now I hit /nagios3 on the public IP address of the EC2 instance in a web browser (http://something.compute-1.amazonaws.com/nagios3/) and log in as nagiosadmin with the password I just supplied.
Let's create some hostgroups - say web and db.
mg conf.d/hostgroups_nagios2.cfg
Replace that file with this:
define hostgroup {
hostgroup_name all
alias All servers
members *
}
define hostgroup {
hostgroup_name web
alias Web servers
members web1, web2
}
define hostgroup {
hostgroup_name db
alias Database servers
members db1
}
Now let's define those hosts:
mg conf.d/hosts.cfg
Add this in there:
define host {
use generic-host;
host_name web1;
address web1.example.com;
}
define host {
use generic-host;
host_name web2;
address web2.example.com;
}
define host {
use generic-host;
host_name db1;
address db1.example.com;
}
Now we can define services that run in the new hostgroups, and disable the ones we aren't using any more:
mg conf.d/services_nagios2.cfg
Change the hostgroup_name in the first service (HTTP) to web, and comment out the next two services. Then add the following:
define service {
hostgroup_name db
service_description MySQL
check_command check_mysql
use generic-service
notification_interval 0
}
Finally, we can get rid of some example configuration that we don't need, verify that the configuration is sound, and restart the nagios3 service:
If all that went well, you should be able to go back to the Hostgroup Overview page on your Nagios install and see the new hostgroups and hosts. The Service Detail page will show a row for each service configured. You'll probably find that the MySQL check won't work because your Nagios host doesn't have access to the MySQL server. If so, you can pass it a login name and password using the check_mysql_cmdlinecred check like this (inside the MySQL service block in conf.d/services_nagios2.cfg):
Don't forget to run nagios3 -v /etc/nagios3/nagios.cfg to check your configuration, then /etc/init.d/nagios3 restart to restart the daemon, before checking the web interface.
And... you're pretty much done. If you add a new database server, just change the members db1 line in conf.d/hostgroups_nagios2.cfg to members db1, db2, check, and restart. To add a new service to a hostgroup, add a new define service block in conf.d/services_nagios2.cfg. All the default check commands (check_http, check_mysql_database etc) are configured in /etc/nagios/plugins/config/*.cfg, so take a look in there for inspiration on what you can check without needing to write your own check plugin.