Nrpe是通常用于安装被监控端的,这里在服务端也安装的了nrpe软件,是因为nagios服务器端需要check_nrpe插件做被动检查,如果服务端不安装nrpe插件,那么也就没有这个插件了,其次nagios服务器端本地的资源也需要被监控,因此nagios服务器端也会被认作客户端。
[root@linuxidc tools]# tar zxvf nrpe-2.12.tar.gz
[root@linuxidc tools]# cd nrpe-2.12
[root@linuxidc nrpe-2.12]# ./configure
[root@linuxidc nrpe-2.12]# make all && make inst
6、服务端附件
(1)检查登录nagios的管理账户信息
[root@linuxidc nagios-cn-3.2.3]# grep AuthUserFile /etc/httpd/conf.d/nagios.conf
AuthUserFile /usr/local/nagios/etc/htpasswd.users
AuthUserFile /usr/local/nagios/etc/htpasswd.users
AuthUserFile /usr/local/nagios/etc/htpasswd.users
(2)设置nagios开机自启动
[root@linuxidc nagios-cn-3.2.3]# chkconfig postfix on
[root@linuxidc nagios-cn-3.2.3]# chkconfig postfix --list
postfix 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
(3)邮件报警
[root@linuxidc nagios-cn-3.2.3]# /etc/init.d/httpd reload
[root@linuxidc nagios-cn-3.2.3]# sed -n '35p ' /usr/local/nagios/etc/objects/contacts.cfg
email 741215208@qq.com; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
[root@linuxidc nagios-cn-3.2.3]# /etc/init.d/postfix start
[root@linuxidc nagios-cn-3.2.3]# lsof -i :25
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
master 2094 root 12u IPv4 12921 0t0 TCP localhost:smtp (LISTEN)
master 2094 root 13u IPv6 12923 0t0 TCP localhost:smtp (LISTEN)
[root@linuxidc nagios-cn-3.2.3]# mail -s "test" 741215208@qq.com < /etc/hosts
[root@linuxidc nagios-cn-3.2.3]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
A1C723FFA6 599 Sun May 21 12:23:56 root@linuxidc.localdomain
(lost connection with mx2.qq.com[14.17.41.170] while performing the HELO handshake)
741215208@qq.com
安装客户端端环境
注释:三台客户端同时安装,安装的内容一样。
1、添加用户
[root@yu62 ~]# mkdir -p /home/yu/tools
[root@yu62 ~]# cd /home/yu/tools/
[root@yu62 tools]# yum install perl-devel openssl-devel -y
[root@yu62 tools]# useradd -s /sbin/nologin nagios
[root@yu62 tools]# groupadd nagcmd
[root@yu62 tools]# usermod -G nagcmd nagios
2、安装nagios-plugins插件包
[root@yu62 tools]# tar zxvf nagios-plugins-1.4.16.tar.gz
[root@yu62 tools]# cd nagios-plugins-1.4.16
[root@yu62 nagios-plugins-1.4.16]# ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd --enable-perl-modules --with-mysql
[root@yu62 nagios-plugins-1.4.16]# make -j 4 && make install
3、安装nrpe软件包
[root@yu62 tools]# tar zxvf nrpe-2.12.tar.gz
[root@yu62 tools]# cd nrpe-2.12
[root@yu62 nrpe-2.12]# ./configure && make all && make install
实战:监控外部服务器MySQL服务
1、服务端修改配置文件
root@linuxidc ~]# cd /usr/local/nagios/etc
[root@linuxidc etc]# vim nagios.cfg
改:cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
为:注释localhost这一项,添加以下两行:
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/service.cfg
2、修改配置文件、生成要检测的主机配置文件和服务配置文件:
[root@linuxidc etc]# cd objects/
[root@linuxidc objects]# vim hosts.cfg # 添加以下内容
####################chreck_host###########################
define host{
use linux-server
host_name yu62
alias mysql服务
address 192.168.1.64
icon_image switch.gif
statusmap_image switch.gd2
2d_coords 100,200
3d_coords 100,200,100
}
[root@linuxidc objects]# vim service.cfg # 添加以下内容
###################check_server_mysql#############################
define service{
use local-service
host_name yu62
service_groups mysql服务组
service_description mysql服务
check_command check_mysql
}
##########################check_server_mysql_groups#########################define servicegroup{
servicegroup_name mysql服务组
alias mysql服务器
members yu62,mysql服务
}
[root@linuxidc objects]# vim commands.cfg #在此文件最后添加以下内容:
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H$HOSTADDRESS$ -u nagdb -d nagdb
}
[root@linuxidc nrpe-2.12]# /etc/init.d/nagios checkconfig
3、客户端上安装MySQL服务
[root@xuegod62 ~]# yum install mysql-server -y
[root@xuegod62 ~]# service mysqld restart
[root@xuegod62~]# mysql
mysql>create database nagdb;
mysql> grant select on nagdb.* to yu@'192.168.1.61';
4、重启mysqld、nagios服务
[root@yu62 ~]# /etc/init.d/httpd restart
[root@yu62 ~]# /etc/init.d/mysqld restart
[root@linuxidc ~]# /etc/init.d/nagios restart
[root@linuxidc objects]#/usr/local/nagios/libexec/check_mysql -H 192.168.1.64 -u nagdb -d nagdb
Uptime: 516 Threads: 1 Questions: 6 Slow queries: 0 Opens: 15 Flush tables: 1 Open tables:8 Queries per second avg: 0.11
#上述命令执行后,出现以下信息,表示正常,连接192.168.1.64的mysql里面的用户是正常的
5)测试查看主机和服务: