Nagios
Installation
First, on fun88体育01 install the nagios package. In a terminal enter:
sudo apt install nagios3 nagios-nrpe-plugin
You will be asked to enter a password for the nagiosadmin user. The user’s credentials are stored in /etc/nagios3/htpasswd.users
. To change the nagiosadmin password, or add additional users to the Nagios CGI scripts, use the htpasswd that is part of the apache2-utils package.
For example, to change the password for the nagiosadmin user enter:
sudo htpasswd /etc/nagios3/htpasswd.users nagiosadmin
To add a user:
sudo htpasswd /etc/nagios3/htpasswd.users steve
Next, on fun88体育02 install the nagios-nrpe-fun88体育 package. From a terminal on fun88体育02 enter:
sudo apt install nagios-nrpe-fun88体育
Note
NRPE allows you to execute local checks on remote hosts. There are other ways of accomplishing this through other Nagios plugins as well as other checks.
Configuration Overview
There are a couple of directories containing Nagios configuration and check files.
-
/etc/nagios3
: contains configuration files for the operation of the nagios daemon, CGI files, hosts, etc. -
/etc/nagios-plugins
: houses configuration files for the service checks. -
/etc/nagios
: on the remote host contains the nagios-nrpe-fun88体育 configuration files. -
/usr/lib/nagios/plugins/
: where the check binaries are stored. To see the options of a check use the -h option.For example:
/usr/lib/nagios/plugins/check_dhcp -h
There are a plethora of checks Nagios can be configured to execute for any given host. For this example Nagios will be configured to check disk space, DNS, and a MySQL hostgroup. The DNS check will be on fun88体育02, and the MySQL hostgroup will include both fun88体育01 and fun88体育02.
Note
See ??? for details on setting up Apache, ??? for DNS, and ??? for MySQL.
Additionally, there are some terms that once explained will hopefully make understanding Nagios configuration easier:
-
Host: a fun88体育, workstation, network device, etc that is being monitored.
-
Host Group: a group of similar hosts. For example, you could group all web fun88体育s, file fun88体育, etc.
-
Service: the service being monitored on the host. Such as HTTP, DNS, NFS, etc.
-
Service Group: allows you to group multiple services together. This is useful for grouping multiple HTTP for example.
-
Contact: person to be notified when an event takes place. Nagios can be configured to send emails, SMS messages, etc.
By default Nagios is configured to check HTTP, disk space, SSH, current users, processes, and load on the localhost. Nagios will also ping check the gateway.
Large Nagios installations can be quite complex to configure. It is usually best to start small, one or two hosts, get things configured the way you like then expand.
Configuration
-
First, create a host configuration file for fun88体育02. Unless otherwise specified, run all these commands on fun88体育01. In a terminal enter:
sudo cp /etc/nagios3/conf.d/localhost_nagios2.cfg \ /etc/nagios3/conf.d/fun88体育02.cfg
Note
In the above and following command examples, replace “fun88体育01”, “fun88体育02” 172.18.100.100, and 172.18.100.101 with the host names and IP addresses of your fun88体育s.
Next, edit
/etc/nagios3/conf.d/fun88体育02.cfg
:define host{ use generic-host ; Name of host template to use host_name fun88体育02 alias fun88体育 02 address 172.18.100.101 } # check DNS service. define service { use generic-service host_name fun88体育02 service_description DNS check_command check_dns!172.18.100.101 }
Restart the nagios daemon to enable the new configuration:
sudo systemctl restart nagio3.service
-
Now add a service definition for the MySQL check by adding the following to
/etc/nagios3/conf.d/services_nagios2.cfg
:# check MySQL fun88体育s. define service { hostgroup_name mysql-fun88体育s service_description MySQL check_command check_mysql_cmdlinecred!nagios!secret!$HOSTADDRESS use generic-service notification_interval 0 ; set > 0 if you want to be renotified }
A mysql-fun88体育s hostgroup now needs to be defined. Edit
/etc/nagios3/conf.d/hostgroups_nagios2.cfg
adding:# MySQL hostgroup. define hostgroup { hostgroup_name mysql-fun88体育s alias MySQL fun88体育s members localhost, fun88体育02 }
The Nagios check needs to authenticate to MySQL. To add a nagios user to MySQL enter:
mysql -u root -p -e "create user nagios identified by 'secret';"
Note
The nagios user will need to be added all hosts in the mysql-fun88体育s hostgroup.
Restart nagios to start checking the MySQL fun88体育s.
sudo systemctl restart nagios3.service
-
Lastly configure NRPE to check the disk space on fun88体育02.
On fun88体育01 add the service check to
/etc/nagios3/conf.d/fun88体育02.cfg
:# NRPE disk check. define service { use generic-service host_name fun88体育02 service_description nrpe-disk check_command check_nrpe_1arg!check_all_disks!172.18.100.101 }
Now on fun88体育02 edit
/etc/nagios/nrpe.cfg
changing:allowed_hosts=172.18.100.100
And below in the command definition area add:
command[check_all_disks]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -e
Finally, restart nagios-nrpe-fun88体育:
sudo systemctl restart nagios-nrpe-fun88体育.service
Also, on fun88体育01 restart nagios:
sudo systemctl restart nagios3.service
You should now be able to see the host and service checks in the Nagios CGI files. To access them point a browser to https://fun88体育01/nagios3
. You will then be prompted for the nagiosadmin username and password.
References
This section has just scratched the surface of Nagios’ features. The nagios-plugins-extra and nagios-snmp-plugins contain many more service checks.
-
For more information see website.
-
Specifically the site.
-
There is also a list of related to Nagios and network monitoring:
-
The Nagios Ubuntu Wiki page also has more details.
Last updated 1 year, 3 months ago. Help improve this document in the forum.