Nagios installation worksheet
Afnog 2011 sse
Install the nagios package
pkg_add -r nagios nagios plugins
or failing that do the install using the ports collection from
/usr/ports/net-mgmt/nagios
and
/usr/ports/net-mgmt/nagios plugins
you will be prompted to create new a new group and user account
pw: unknown group `nagios'
You need a "nagios" group.
Would you like me to create it [YES]? yes
Done.
pw: no such user `nagios'
You need a "nagios" user.
Would you like me to create it [YES]? Yes
The following instructions will helpfully be relayed (by the installer) when installation is complete.
Enable Nagios in /etc/rc.conf with the following line:
nagios_enable="YES"
Configuration templates are available in /usr/local/etc/nagios as
*.cfg-sample files. Copy them to *.cfg files where required and
edit to suit your needs. Documentation is available in HTML form
in /usr/local/www/nagios/docs.
If you don't already have a web server running, you will need to
install and configure one to finish off your Nagios installation.
When used with Apache, the following should be sufficient to publish
the web component of Nagios (modify the allow list to suit):
<Directory /usr/local/www/nagios>
Order deny,allow
Deny from all
Allow from 127.0.0.1
php_flag engine on
php_admin_value open_basedir /usr/local/www/nagios/:/var/spool/nagios/
</Directory>
<Directory /usr/local/www/nagios/cgi-bin>
Options ExecCGI
</Directory>
ScriptAlias /nagios/cgi-bin/ /usr/local/www/nagios/cgi-bin/
Alias /nagios/ /usr/local/www/nagios/
so to deploy an appropriate variation of those instructions we need to do the following.
we need to enable nagios in the /etc/rc.conf, edit that file.
Add the line:
nagios_enable="YES"
We need to add local configuration to apache to point at the nagios instance.
cd /usr/local/etc/apache22/Includes/
Create the new nagios specific configuration for apache.
vi nagios.conf
Add:
<Directory /usr/local/www/nagios>
Order deny,allow
Deny from all
Allow from 127.0.0.1
Allow from 196.200.216.0/23
php_flag engine on
php_admin_value open_basedir /usr/local/www/nagios/:/var/spool/nagios/
</Directory>
<Directory /usr/local/www/nagios/cgi-bin>
Options ExecCGI
</Directory>
ScriptAlias /nagios/cgi-bin/ /usr/local/www/nagios/cgi-bin/
Alias /nagios/ /usr/local/www/nagios/
Then start apache:
/usr/local/etc/rc.d/apache22 start
rename the sample configuration files in the nagios configuartion directory remove sample from the name you can do this manually or using some shell scripting magic like:
cd /usr/local/etc/nagios
for i in *-sample; do
cp $i `basename $i -sample`
done
do that also in the objects sub-directory
edit the contacts config file and add the following user
define contact {
contact_name admin
alias Nagios Admin
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
}
we need to edit the cgi.conf in /usr/local/etc/nagios/
Edit `cgi.cfg` and uncomment the following line: #default_user_name=guest Change the following lines, adding the word ",guest" at the end of each: authorized_for_system_information=nagiosadmin,guest authorized_for_configuration_information=nagiosadmin,guest authorized_for_all_services=nagiosadmin,guest authorized_for_all_hosts=nagiosadmin,guest edit the nagios.cfg uncomment the line #cfg_dir=/usr/local/etc/nagios/servers save the file create the servers directory create a configuration file for the measurement of your server pcXX.cfg lets measure two services and the availability of the machine.
define host {
host_name 196.200.219.1
alias 196.200.219.1
address 196.200.219.1
contacts admin
max_check_attempts 10
use generic-host
check_command check-host-alive
}
define service {
use generic-service
host_name 196.200.219.1
service_description PING
check_command check_ping!100.0,20%!500.0,60%
check_interval 1
contacts admin
}
define service {
use generic-service
host_name 196.200.219.1
service_description ssh
check_command check_ssh
}
save the file.
Now start the nagios service.
/usr/local/etc/rc.d/nagios start