概述
对重要的服务器和服务进程的监控是系统管理工作的重要组成部分。大多数网络服务进程都有服务性能、可用性的监控,或者两个指标同时监控。这一部分将说明用于可用性监控的Nagios 和用于性能监控的Munin 的安装和配置。
这一部分的例子用到两台服务器,一台服务器名为server01 另一台server02 。Server01 会安装上Nagios 来监控在它自己上面运行的服务进程和在Server02 上运行的服务进程。 Server01 还会安装上munin 软件包来从网络上收集性能数据。在server02 上安装munin-node 软件包并配置成向server01 发送性能数据。
希望这些简单的例子可以能够帮助您实现您网络上的服务器和服务进程的监控。
Nagios
安装
首先,在server01 上安装nagios 软件包。在server01 的terminal上输入:
sudo apt-get install nagios3 nagios-nrpe-plugin
需要为 nagiosadmin 用户设置一个密码。用户密码存放在 /etc/nagios3/htpasswd.users
。要改变 nagiosadmin 的密码,或者为Nagios CGI脚本增加新的用户,可以使用htpasswd ,htpasswd 是apache2-utils 软件包的一部分。
例如,要改变 nagiosadmin 的密码,输入:
sudo htpasswd /etc/nagios3/htpasswd.users nagiosadmin
新增一个用户:
sudo htpasswd /etc/nagios3/htpasswd.users steve
接下来,在server02 上安装nagios-nrpe-server 软件包。在server02 的terminal上输入:
sudo apt-get install nagios-nrpe-server
NRPE 能够让您在远程主机上运行本地的可用性检查指令。 |
配置概览
Nagios 的配置文件和可用性检查文件放置在几个目录中。
-
/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-server 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 server02 , and the MySQL hostgroup will include both server01 and server02 .
See the section called “HTTPD - Apache2 Web Server” for details on setting up Apache, Chapter 7, Domain Name Service (DNS) for DNS, and the section called “MySQL” for MySQL. |
Additionally, there are some terms that once explained will hopefully make understanding Nagios configuration easier:
-
Host : a server, workstation, network device, etc that is being monitored.
-
Host Group : a group of similar hosts. For example, you could group all web servers, file server, 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 server02 . In a terminal enter:
sudo cp /etc/nagios3/conf.d/localhost_nagios2.cfg /etc/nagios3/conf.d/server02.cfg
In the above and following command examples, replace "server01" , "server02" 172.18.100.100 , and 172.18.100.101 with the host names and IP addresses of your servers.
-
Next, edit
/etc/nagios3/conf.d/server02.cfg
:define host{
use generic-host ; Name of host template to use
host_name server02
alias Server 02
address 172.18.100.101
}
# check DNS service.
define service {
use generic-service
host_name server02
service_description DNS
check_command check_dns!172.18.100.101
}
-
Restart the nagios daemon to enable the new configuration:
sudo /etc/init.d/nagios3 restart
-
-
-
Now add a service definition for the MySQL check by adding the following to
/etc/nagios3/conf.d/services_nagios2.cfg
:# check MySQL servers.
define service {
hostgroup_name mysql-servers
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 mysqsl-servers hostgroup now needs to be defined. Edit
/etc/nagios3/conf.d/hostgroups_nagios2.cfg
adding:# MySQL hostgroup.
define hostgroup {
hostgroup_name mysql-servers
alias MySQL servers
members localhost, server02
}
-
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';"
The nagios user will need to be added all hosts in the mysql-servers hostgroup.
-
Restart nagios to start checking the MySQL servers.
sudo /etc/init.d/nagios3 restart
-
-
-
Lastly configure NRPE to check the disk space on server02 .
On server01 add the service check to
/etc/nagios3/conf.d/server02.cfg
:# NRPE disk check.
define service {
use generic-service
host_name server02
service_description nrpe-disk
check_command check_nrpe_1arg!check_all_disks!172.18.100.101
}
-
Now on server02 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-server :
sudo /etc/init.d/nagios-nrpe-server restart
-
Also, on server01 restart nagios :
sudo /etc/init.d/nagios3 restart
-
You should now be able to see the host and service checks in the Nagios CGI files. To access them point a browser to http://server01/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 Nagios website.
-
Specifically the Online Documentation site.
-
There is also a list of books related to Nagios and network monitoring:
-
The Nagios Ubuntu Wiki page also has more details.