2.远程监控服务端2mysql及测试
A) 安装mysql及添加授权
服务端2
[root@server2 ~]# yum install mysql-server -y #安装mysql
[root@server2 ~]# /etc/init.d/mysqld start #开启mysql
[root@server2 ~]# mysql_secure_installation #初始化,添加密码RedHat
[root@server2 ~]# mysql -predhat #进入mysql
mysql> create database nagdb; #添加nagdb库
Query OK, 1 row affected (0.00 sec)
mysql> grant select on nagdb.* to nagios@'172.25.25.1'identified by 'redhat';
Query OK, 0 rows affected (0.00 sec) #给nagios用户授予nagdb库的查看权限
mysql> Bye #退出
#服务端1,测试
[root@server1 objects]# ./check_mysql -H 172.25.25.2 -u nagios-p redhat -d nagdb
B) 将mysql服务(服务端2)添加到nagios(服务端1)
服务端1
[root@server1 objects]# vim hosts.cfg #定义主机
define host{
use linux-server #调用的模版
host_name server2.example.com #主机名(command.cfg中要调用的参数)
alias MYSQL #别名
address 172.25.25.2 #ip
icon_image server.gif
statusmap_image server.gd2 #坐标的定义
2d_coords 400,200
3d_coords 400,200,100
}
[root@server1 objects]# vim services.cfg #定义服务
####################check_mysql#######################
define service{
use local-service
host_name server2.example.com(调用hosts.cfg中的host_name)
service_description MYSQL
check_command check_mysql!nagios!redhat!nagdb #command.cfg中要调用的参数(命令名字!主机名!密码!数据库的名称)
}
[root@server1 objects]# vim commands.cfg #定义命令
# 'check_mysql' command definition
define command{
command_name check_mysql #命令的名字
command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u$ARG1$ -p $ARG2$ -d $ARG3$ #调用的脚本绝对路径 -H 主机名(调用hosts.cfg中的host_name) -u mysql的用户名 -p 用户密码 -d 数据库的名称
}
[root@server1 objects]# /usr/local/nagios/bin/nagios -v/usr/local/nagios/etc/nagios.cfg #检查是否有语法错误
Total Warnings: 0
Total Errors: 0 #无语法错误
Things look okay - No serious problems were detected during thepre-flight check
[root@server1 objects]# /etc/init.d/nagios reload #刷新
Running configuration check...done.
Reloading nagios configuration...done
C)测试
点击拓扑图,添加server2.example.com成功
点击主机,查看两台主机
点击服务,如图