nagios平台搭建
需要3个软件包
http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.2.1/nagios-3.2.1.tar.gz/download
http://down1.chinaunix.net/distfiles/nagios-plugins-1.4.14.tar.gz
http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz
nagios服务端需要安装nagios服务端软件,nagios-plugins,nrpe。
1) Nagios 服务端安装
/usr/sbin/useradd nagios
tar zxvf nagios-3.2.1.tar.gzcd nagios-3.2.1./configure --prefix=/usr/local/nagios --with-command-group=nagiosmake allmake install ;make install-init;make install-config;make
install-commandmode ;make install-webconf
make install //来安装主程序,CGI 和 HTML 文件make install-init //在/etc/rc.d/init.d 安装启动脚本make install-config //来安装示例配置文件,安装的路径是/usr/local/nagios/etcmake install-commandmode //来配置目录权限make install-webconf // 配置 nagios 跟 apache 整合2) 安装 Nagios-plugins
tar zxvf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14./configure --prefix=/usr/local/nagios --with-nagios-user=nagios--with-nagios-group=nagiosmake && make install
3) nagios 访问控制设置
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin输入两次密码即可,登录页面的时候会用到这个密码. 4) Nagios 测试访问重启 nagios ,/etc/init.d/nagios restart ;/etc/init.d/httpd restart ;登陆http://localhost/nagios/ 出图表示安装成功
客户端安装nagios-plugins,nrpe中间件
useradd nagios
tar -xzf nagios-plugins-1.4.14.tar.gz &&cd nagios-plugins-1.4.14 &&./configure – prefix=/usr/local/nagios &&make &&make install
tar -xzf nrpe-2.14.tar.gz && cd nrpe-2.14 &&./configure --enable-ssl --with-ssl-lib &&make all && make install-plugin && make install-daemon && make install-daemon-config
chown -R nagios:nagios /usr/local/nagios/
开启服务
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
验证nrpe是否开启
1.ps -ef|grpe nrpe 查看进程2.netstat -tnl 查看端口56663./usr/local/nagios/libexec/check_nrpe -H localhost 出现版本号(客户端)/usr/local/nagios/etc/nrpe.cfg下加一行
allowed_hosts=127.0.0.1,192.168.188.0/24
在服务端机器上验证:/usr/local/nagios/libexec/check_nrpe -H client_address
出版本号表示服务端客户端联通。
服务配置
客户端:vim /usr/local/nagios/etc/nrpe.cfg 修改默认配置段的内容如下:
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/sda2
command[check_procs]=/usr/local/nagios/libexec/check_procs -w 50 -c 100
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20 -c 10
服务端:command.cfg最后加入
define command{
command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$}
在192.168.188.17.cfg中引用客户端crpe.cfg配置的 check_load 命令,命令一般格式为:check_nrpe!command
cd /usr/local/aginos/etc/objects
cp localhost.cfg 192.168.188.17.cfg
define service{
use local-service
host_name 192.168.188.17
service_description Current Load
check_command check_nrpe!check_load
}
监控客户端 5 个步骤:
1、在服务器端和客户端都安装 nrpe,在客户端安装 nagios-plugins2、在客户端定义监控的具体项目,修改 allow 允许的 ip(服务器的 ip)3、分别启动客户端、服务器 nrpe。4、在服务器端 commands.cfg 中定义 check_nrpe 命令:(加入如下这段)define command{ command_name check_nrpe command_line $USER1$/check_nrpe -Hip $HOSTADDRESS$ -c $ARG1$}5、在服务器端对应 IP 的配置文件中,加入需要监控的项目:define service{ use local-service (服务端templates.cfg里定义的services) host_name 192.168.1.12(客户端ipip) service_description Sda1_Monitor(自定义页面上显示的名称) check_command check_nrpe!check_u(客户端nrpe.cfg里定义的command)}
HTTP关键字搜索
/usr/localhost/command.cfg 加入一下内容
define command{
command_name check_http_word
command_line $USER1$/check_http -I $HOSTADDRESS$ -u $ARG1$ -s $ARG2$ -p $ARG3$
}
/usr/localhost/ip.cfg 加入相关引用
define service{
use local-service host_name 192.168.188.17 service_description HTTP-WEB-在线会员 check_command check_http_word!/forum.php!在线会员!80 notifications_enabled 1 }
监控mysql主从
被监控机安装nrpe,nagios-plugins
本机测试。
/usr/local/nagios/libexec/check_mysql -H192.168.188.18 -uroot -p000000 -S
测试通过如下:
Uptime: 31826 Threads: 1 Questions: 1465 Slow queries: 0 Opens: 47 Flush tables: 1 Open tables: 33 Queries per second avg: 0.46 Slave IO: Yes Slave SQL: Yes Seconds Behind Master: 0
nrpe.cfg里添加
allowed_hosts=127.0.0.1,192.168.188.0/24
command[check_mysql]=/usr/local/nagios/libexec/check_mysql -H192.168.188.18 -uroot -p000000 -S
开启nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
监控机
测试连接
/usr/local/nagios/libexec/check_nrpe -H192.168.188.18 client_address 出版本号连接成功
/usr/local/nagios/etc/objects/192.168.188.18.cfg添加以下内容
define service{
use local-service host_name 192.168.188.18 service_description mysql-slave-status check_command check_nrpe!check_mysql}重新加载配置
/etc/init.d/nagios reload
如果报错,通过 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg查看报错信息。