一、软件版本1 1.1、主程序nagios-3.2.3.tar.gz1 1.2、插件 nagios-plugins-1.4.15.tar.gz1 1.3、插件 nrpe-2.12.tar.gz1 1.4、飞信报警库及脚本 lib/ fetion1 二、Nagios监控服务器端/8.230,程序安装1 2.1、Yum安装以下软件1 2.2、创建nagios 用户和组1 2.3、编译安装Nagios 主程序1 2.4、安装nagios-plugins插件2 2.5、将apache的运行用户加到nagios组里面2 2.6、增加web访问账号2 2.7、查看cgi.cfg文件2 2.8、编译安装nrpe插件2 2.9、nagios随系统启动3 三、Nagios 被监控客户端/8.2313 3.1、增加用户nagios3 3.2、编译安装nagios-plugins插件3 3.3、编译安装nrpe插件3 3.4、修改services配置文件,在最后末尾增加4 3.5、修改nrpe配置文件4 3.6、启动基于xinetd 的nrpe服务4 3.7、测试回到8.230主监控服务器上4 四、Nagios监控服务器端/8.230 主程序配置4 4.1、配置文件分组简介4 4.2、在定义配置文件路经,这里可以自定义配置文件.5 4.3、定义配置lxr 联系人新增配置文件5 4.4、定义配置lxrgroup联系组-新增配置文件5 4.5、定义配置host主机文件,新增配置文件6 4.6、定义配置hostgroup主机组文件,新增配置文件6 4.7、定义配置serivcegroup服务组文件,新增配置文件6 4.8、定义配置serivce服务文件,以上面所有的主机和组。在此配置文件调用。6 4.9、定义飞信短信报警机器人7 5.0、定义飞信短信报警代码,在末行增加7 五、常用测试命令7 5.1、定义被监控端的命令比如swap7 5.2、监控服务端nrpe测试,swap命令8
一、 软件版本 1.1、主程序nagios-3.2.3.tar.gz 下载地址:http://sourceforge.net/projects/ ... 2.3.tar.gz/download 1.2、插件 nagios-plugins-1.4.15.tar.gz http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz/download 1.3、插件 nrpe-2.12.tar.gz 下载地址:http://down./data/165101# 1.4、飞信报警库及脚本 lib/ fetion 下载地址:http://bbs.it-adv.net/viewthread.php?tid=1081&extra=page%3D1
二、 Nagios监控服务器端/8.230,程序安装 2.1、Yum安装以下软件 [iyunv@test-1 /]# yum -y install httpd gcc glibc glibc-common gd gd-devel php openssl-develxinetd
2.2、创建nagios 用户和组 [iyunv@test-1 nagios]# useradd nagios [iyunv@test-1 nagios]# passwd nagios [iyunv@test-1 nagios]# mkdir/usr/local/nagios [iyunv@test-1 nagios]# chown nagios.nagios /usr/local/nagios 2.3、编译安装Nagios 主程序 [iyunv@test-1 nagios]# tar -xvf nagios-3.2.3.tar.gz [iyunv@test-1 nagios]# cd nagios-3.2.3 [iyunv@test-1 nagios]#./configure --prefix=/usr/local/nagios --with-command-group=nagios [iyunv@test-1 nagios]#make all [iyunv@test-1 nagios]#make install [iyunv@test-1 nagios]# make install-init
[iyunv@test-1 nagios]# make install-config [iyunv@test-1 nagios]# make install-commandmode [iyunv@test-1 nagios]#make install-webconf (查看是否有/usr/local/nagios/etc、bin、sbin、share、var、libexec这六个目录,如果有,表示安装成功) 2.4、安装nagios-plugins插件 [iyunv@test-1 nagios]#tar -xvf nagios-plugins-1.4.15.tar.gz [iyunv@test-1 nagios]#cd nagios-plugins-1.4.15 ./configure--prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios [iyunv@test-1 nagios]#make && make install ls /usr/local/nagios/libexec(会显示很多应用脚本) 2.5、将apache的运行用户加到nagios组里面 [iyunv@test-1 nagios]#usermod -G nagios apache 2.6、增加web访问账号 [iyunv@test-1 nagios]#cat /etc/httpd/conf.d/nagios.conf | grep htpasswd AuthUserFile /usr/local/nagios/etc/htpasswd.users AuthUserFile /usr/local/nagios/etc/htpasswd.users [iyunv@test-1]#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin 2.7、查看cgi.cfg文件 [iyunv@test-1 nagios]# grep nagiosadmin /usr/local/nagios/etc/cgi.cfg authorized_for_system_information=nagiosadmin authorized_for_configuration_information=nagiosadmin authorized_for_system_commands=nagiosadmin authorized_for_all_services=nagiosadmin authorized_for_all_hosts=nagiosadmin authorized_for_all_service_commands=nagiosadmin authorized_for_all_host_commands=nagiosadmin 2.8、编译安装nrpe插件 [iyunv@test-1 nagios]#tar -xvf nrpe-2.12.tar.gz [iyunv@test-1 nagios]#cd nrpe-2.12 [iyunv@test-1 nagios]# ./configure --enable-ssl --with-ssl-lib [iyunv@test-1 nagios]#make all [iyunv@test-1 nagios]# make install-plugin [iyunv@test-1 nagios]# make install-daemon [iyunv@test-1 nagios]# make install-daemon-config [iyunv@test-1 nagios]#make install-xinetd 2.9、nagios随系统启动 [iyunv@test-1 nagios]#chkconfig --add nagios [iyunv@test-1 nagios]#chkconfig nagios on [iyunv@test-1 nagios]#/etc/init.d/httpd start 验证配置是否配置正确:/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 如果不报错,可以启动nagios服务:service nagios start IE浏览器地址栏输入:192.168.8.230/nagios,敲入用户名及密码,就可以看到如下界面了 
三、 Nagios 被监控客户端/8.231 3.1、增加用户nagios [iyunv@test-2 /]# yum -y install httpd gcc glibc glibc-common gd gd-devel php openssl-develxinetd
[iyunv@test-2 nagios]# useradd nagios [iyunv@test-2 nagios]# passwd nagios
3.2、编译安装nagios-plugins插件 [iyunv@test-1 nagios]#tar -xvf nagios-plugins-1.4.15.tar.gz [iyunv@test-1 nagios]#cd nagios-plugins-1.4.15 ./configure--prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios [iyunv@test-1 nagios]#make && make install ls /usr/local/nagios/libexec(会显示很多应用脚本)
3.3、编译安装nrpe插件 [iyunv@test-2 nagios]#tar -xvf nrpe-2.12.tar.gz [iyunv@test-2 nagios]#cd nrpe-2.12 [iyunv@test-2 nagios]# ./configure --enable-ssl --with-ssl-lib [iyunv@test-2 nagios]#make all [iyunv@test-2 nagios]# make install-plugin [iyunv@test-2 nagios]# make install-daemon [iyunv@test-2 nagios]# make install-daemon-config [iyunv@test-2 nagios]#make install-xinetd 3.4、修改services配置文件,在最后末尾增加 [iyunv@test-2 nagios]#cat /etc/services | grep nrpe nrpe 5666/tcp # nrpe
3.5、修改nrpe配置文件 [iyunv@test-2 nagios]#vim /etc/xinetd.d/nrpe only_from = 192.168.8.230à监控服务器地址 3.6、启动基于xinetd 的nrpe服务 [iyunv@test-2 nagios]#/etc/init.d/xinetd start [iyunv@test-2 nagios]#netstat -nap | grep 5666 tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 1284/xinetd 3.7、测试回到8.230主监控服务器上 [iyunv@test-1 nagios]# /usr/local/nagios/libexec/check_nrpe -H 192.168.8.231 返回 “NRPE v2.12” 表示部署成功 四、 Nagios监控服务器端/8.230 主程序配置 4.1、配置文件分组简介 cgi.cfg---à控制相关的cgi 脚本 resoure.cfg -à系统传入参数配置文件 commands.cfg-à定义命令配置文件 timeperiods.cfgà监视时段配置文件
配置分组自定义 contacts .cfg-à 定义了故障报警的联系人 contactsgroup.cfg---à定义了故障报警联系组
hosts--à主机配置文件 hostgroups-à主机组配置文件
services-à服务配置文件 servicesgroupà服务组配置文件
4.2、 在定义配置文件路经,这里可以自定义配置文件. [iyunv@test-1 nagios]#vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg 注释掉。 cfg_file=/usr/local/nagios/etc/objects/contacts.cfg 注释掉 末尾增加以下内容 cfg_file=/usr/local/nagios/my/lxr cfg_file=/usr/local/nagios/my/lxrgroup cfg_file=/usr/local/nagios/my/host cfg_file=/usr/local/nagios/my/hostgroup cfg_file=/usr/local/nagios/my/serivcegroup cfg_file=/usr/local/nagios/my/service
4.3、定义配置lxr 联系人新增配置文件 [iyunv@test-1 nagios]# mkdir /usr/local/nagios/my [iyunv@test-1 nagios]# cd /usr/local/nagios/my [iyunv@test-1my]# vim lxr define contact{ contact_name Alvin-zeng use generic-contact alias Alvin-zeng-admin service_notification_commands notify-service-by-email,service-notify-by-fetion host_notification_commands notify-host-by-email,host-notify-by-fetion email alvin.zyong@gmail.com pager 136xxxxxxx }
4.4、定义配置lxrgroup联系组-新增配置文件 [iyunv@test-1my]# vim lxrgroup define contactgroup{ contactgroup_name lxrgp #:组名随便定义 alias zeng #:别名随便定义 members Alvin-zeng #这里将上面的联系人成员。加到这个组里面 }
4.5、定义配置host主机文件,新增配置文件 [iyunv@test-1my]# vim host define host{ host_name test-2 #被监空端真实的主机名,主要不要留空格。 alias test max_check_attempts 5 address 192.168.8.231 } #:被监客户端IP地址 4.6、定义配置hostgroup主机组文件,新增配置文件 [iyunv@test-1my]# vim hostgroup define hostgroup{ hostgroup_name group1 #:组名 alias group members test-2 #:将test-2 加到这个组里面来 } 4.7、定义配置serivcegroup服务组文件,新增配置文件 [iyunv@test-1my]# vim serivcegroup define servicegroup{ servicegroup_name tt #:组名 alias TT #:别名 } 4.8、定义配置serivce服务文件,以上面所有的主机和组。在此配置文件调用。 [iyunv@test-1my]# vim service define service{ hostgroup_name group1 #这里调用主机组或者单个主机 servicegroups tt #这里调用服务组或者单个服务 service_description check_swap #检查swap check_period 24x7 #检查24小时 max_check_attempts 1 normal_check_interval 1 retry_check_interval 1 notification_options w,u,c,r notification_interval 1 notification_period 24x7 check_command check_nrpe!check_swap contact_groups lxrgp #这里调用联系人组或者单个联系人 } 4.9、定义飞信短信报警机器人 先解压,解压完后。找到lib 目录库和fetion脚本 [iyunv@test-1my]#mkdir /usr/local/fetion/ [iyunv@test-1my]#mkdir /usr/local/fetion/ [iyunv@test-1my]# cp lib/ /usr/local/fetion/ [iyunv@test-1my]# cp fetion /usr/local/fetion/
5.0、定义飞信短信报警代码,在末行增加 [iyunv@test-1my]#vim /usr/local/nagios/etc/objects/commands.cfg
define command { command_name host-notify-by-fetion ; command_line LD_LIBRARY_PATH=/usr/local/fetion/lib /usr/local/fetion/fetion --mobile=13692216**** --pwd=feishu8 --to=13692216**** --msg-utf8="Host $HOSTSTATE$ alert for $HOSTNAME$! on '$LONGDATETIME$'" $CONTACTPAGER$ }
# 'notify-service-by-fetion' command definition define command { command_name service-notify-by-fetion command_line LD_LIBRARY_PATH=/usr/local/fetion/lib /usr/local/fetion/fetion --mobile=13692216**** --pwd=feishu8 --to=13692216**** --msg-utf8="$HOSTADDRESS$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ on $LONGDATETIME$" $CONTACTPAGER$ } # ' check_nrpe ' command definition define command{ command_name check_nrpe command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ } 五、 常用测试命令 5.1、定义被 监控端的命令比如swap [iyunv@test-2 nagios]#vim /usr/local/nagios/etc/nrpe.cfg
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 50% -c 20% 5.2、监控服务端nrpe测试,swap命令 [iyunv@test-1 nagios]#cd /usr/local/nagios/libexec/ [iyunv@test-1 libexec]#./check_nrpe -H 192.168.8.231 -c check_swap SWAP OK - 100% free (1983 MB out of 1983 MB) |swap=1983MB;991;396;0;1983
|