Nagios監控
<Alvin-zeng-孤獨0-1 >
目錄
1.2、插件 nagios-plugins-1.4.15.tar.gz1
4.6、定義配置hostgroup主機組文件,新增配置文件6
4.7、定義配置serivcegroup服務組文件,新增配置文件6
4.8、定義配置serivce服務文件,以上面所有的主機和組。在此配置文件調用。6
一、 軟件版本
1.1、主程序nagios-3.2.3.tar.gz
下載地址:http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.2.3/nagios-3.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.51cto.com/data/165101#
下載地址:http://bbs.it-adv.net/viewthread.php?tid=1081&extra=page%3D1
[root@test-1 /]# yum -y install httpd gcc glibc glibc-common gd gd-devel php openssl-develxinetd
[root@test-1 nagios]# useradd nagios
[root@test-1 nagios]# passwd nagios
[root@test-1 nagios]# mkdir/usr/local/nagios
[root@test-1 nagios]# chown nagios.nagios /usr/local/nagios
[root@test-1 nagios]# tar -xvf nagios-3.2.3.tar.gz
[root@test-1 nagios]# cd nagios-3.2.3
[root@test-1 nagios]#./configure --prefix=/usr/local/nagios --with-command-group=nagios
[root@test-1 nagios]#make all
[root@test-1 nagios]#make install
[root@test-1 nagios]# make install-init
[root@test-1 nagios]# make install-config
[root@test-1 nagios]# make install-commandmode
[root@test-1 nagios]#make install-webconf
(查看是否有/usr/local/nagios/etc、bin、sbin、share、var、libexec這六個目錄,如果有,表示安裝成功)
[root@test-1 nagios]#tar -xvf nagios-plugins-1.4.15.tar.gz
[root@test-1 nagios]#cd nagios-plugins-1.4.15
./configure--prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
[root@test-1 nagios]#make && make install
ls /usr/local/nagios/libexec(會顯示很多應用腳本)
2.5、將apache的運行用戶加到nagios組裏面
[root@test-1 nagios]#usermod -G nagios apache
[root@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
[root@test-1]#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
[root@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
[root@test-1 nagios]#tar -xvf nrpe-2.12.tar.gz
[root@test-1 nagios]#cd nrpe-2.12
[root@test-1 nagios]# ./configure --enable-ssl --with-ssl-lib
[root@test-1 nagios]#make all
[root@test-1 nagios]# make install-plugin
[root@test-1 nagios]# make install-daemon
[root@test-1 nagios]# make install-daemon-config
[root@test-1 nagios]#make install-xinetd
[root@test-1 nagios]#chkconfig --add nagios
[root@test-1 nagios]#chkconfig nagios on
[root@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,敲入用戶名及密碼,就可以看到如下界面了
[root@test-2 /]# yum -y install httpd gcc glibc glibc-common gd gd-devel php openssl-develxinetd
[root@test-2 nagios]# useradd nagios
[root@test-2 nagios]# passwd nagios
[root@test-1 nagios]#tar -xvf nagios-plugins-1.4.15.tar.gz
[root@test-1 nagios]#cd nagios-plugins-1.4.15
./configure--prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
[root@test-1 nagios]#make && make install
ls /usr/local/nagios/libexec(會顯示很多應用腳本)
[root@test-2 nagios]#tar -xvf nrpe-2.12.tar.gz
[root@test-2 nagios]#cd nrpe-2.12
[root@test-2 nagios]# ./configure --enable-ssl --with-ssl-lib
[root@test-2 nagios]#make all
[root@test-2 nagios]# make install-plugin
[root@test-2 nagios]# make install-daemon
[root@test-2 nagios]# make install-daemon-config
[root@test-2 nagios]#make install-xinetd
[root@test-2 nagios]#cat /etc/services | grep nrpe
nrpe 5666/tcp # nrpe
[root@test-2 nagios]#vim /etc/xinetd.d/nrpe
only_from = 192.168.8.230à監控服務器地址
[root@test-2 nagios]#/etc/init.d/xinetd start
[root@test-2 nagios]#netstat -nap | grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 1284/xinetd
[root@test-1 nagios]# /usr/local/nagios/libexec/check_nrpe -H 192.168.8.231
返回 “NRPE v2.12” 表示部署成功
cgi.cfg---à控制相關的cgi 腳本
resoure.cfg -à系統傳入參數配置文件
commands.cfg-à定義命令配置文件
timeperiods.cfgà監視時段配置文件
配置分組自定義
contacts .cfg-à 定義了故障報警的聯繫人
contactsgroup.cfg---à定義了故障報警聯繫組
hosts--à主機配置文件
hostgroups-à主機組配置文件
services-à服務配置文件
servicesgroupà服務組配置文件
[root@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 聯繫人新增配置文件
[root@test-1 nagios]# mkdir /usr/local/nagios/my
[root@test-1 nagios]# cd /usr/local/nagios/my
[root@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 [email protected]
pager 136xxxxxxx }
4.4、定義配置lxrgroup聯繫組-新增配置文件
[root@test-1my]# vim lxrgroup
define contactgroup{
contactgroup_name lxrgp #:組名隨便定義
alias zeng #:別名隨便定義
members Alvin-zeng #這裏將上面的聯繫人成員。加到這個組裏面
}
4.5、定義配置host主機文件,新增配置文件
[root@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主機組文件,新增配置文件
[root@test-1my]# vim hostgroup
define hostgroup{
hostgroup_name group1 #:組名
alias group
members test-2 #:將test-2 加到這個組裏面來
}
4.7、定義配置serivcegroup服務組文件,新增配置文件
[root@test-1my]# vim serivcegroup
define servicegroup{
servicegroup_name tt #:組名
alias TT #:別名
}
4.8、定義配置serivce服務文件,以上面所有的主機和組。在此配置文件調用。
[root@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 #這裏調用聯繫人組或者單個聯繫人
}
先解壓,解壓完後。找到lib 目錄庫和fetion腳本
[root@test-1my]#mkdir /usr/local/fetion/
[root@test-1my]#mkdir /usr/local/fetion/
[root@test-1my]# cp lib/ /usr/local/fetion/
[root@test-1my]# cp fetion /usr/local/fetion/
[root@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$
}
五、 常用測試命令
[root@test-2 nagios]#vim /usr/local/nagios/etc/nrpe.cfg
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 50% -c 20%
[root@test-1 nagios]#cd /usr/local/nagios/libexec/
[root@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