nagios系統(tǒng)搭建筆記
1.背景
原來(lái)的服務(wù)器和監(jiān)控系統(tǒng)在移動(dòng)機(jī)房(2.14,外網(wǎng)IP120.132.xx.xx),新上家校圈服務(wù)器(17臺(tái))在世紀(jì)互聯(lián)機(jī)房,新舊服務(wù)器不在統(tǒng)一內(nèi)網(wǎng)。
現(xiàn)在家校圈服務(wù)器100.6(120.132.xx.xx)上部署nagios監(jiān)控部署系統(tǒng),通過(guò)nsca傳送到2.14統(tǒng)一進(jìn)行前端頁(yè)面管理。
2.安裝nagios
(1)yum -y install httpd gcc glibc glibc-common gd gd-devel
(2) rpm -ivh nagios-3.2.1-1.el5.rf
rmp -ivh nagios-plugins-1.4.13-1.el5.rf
(3)設(shè)置管理賬號(hào):
/etc/httpd/conf.d/nagios.conf
#AuthName “Nagios Access”
#AuthType Basic
# AuthUserFile /etc/nagios/htpasswd.users
#Require valid-user
cat /etc/nagios/htpasswd.users
139guest:JKvJx00FiMbKo
139admin:d4PvA4FyLnZHM
vi /etc/nagios/cgi.cfg
authorized_for_system_information=139admin
authorized_for_configuration_information=139admin
authorized_for_system_commands=139admin
authorized_for_all_services=139admin,139guest
authorized_for_all_hosts=139admin,139guest
authorized_for_all_service_commands=139admin
authorized_for_all_host_commands=139admin
(4)測(cè)試
默認(rèn)有個(gè)localhost.cfg是對(duì)本機(jī)的監(jiān)控。
/usr/bin/nagios -v /etc/nagios/nagios.cfg 一切正常
/etc/init.d/nagios start 不正常 報(bào)錯(cuò)
Starting nagios:CONFIG ERROR! Start aborted. Check your Nagios configuration.
(5) 排查
a)初步懷疑權(quán)限問(wèn)題,檢查/etc/nagios/權(quán)限、/etc/nagios/nagios.cfg里.cfg文件路徑以及其他權(quán)限,未發(fā)現(xiàn)問(wèn)題。
b)檢查日志,/var/log/message,發(fā)現(xiàn)如下異常信息:
Nov 3 11:41:18 localhost kernel: audit(1288755678.187:52881): arch=c000003e syscall=2 success=no exit=-13 a0=6d61740 a1=10800 a2=feff72736b747264 a3=6d618f3 items=0 ppid=2377 pid=2380 auid=10015 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=25 comm=”nagios” exe=”/usr/bin/nagios” subj=user_u:system_r:nagios_t:s0 key=(null)
懷疑selinux的問(wèn)題,檢查發(fā)現(xiàn)selinux是關(guān)閉的。無(wú)果。。。
cat /etc/selinux/config
SELINUX=disabled
c)繼續(xù)追蹤/etc//init.d/nagios啟動(dòng)腳本
start)
echo -n “Starting nagios:”
$NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
if [ $? -eq 0 ]; then
su – $NagiosUser -c “touch $NagiosVarDir/nagios.log $NagiosRetentionFile”
rm -f $NagiosCommandFile
touch $NagiosRunFile
chown $NagiosUser:$NagiosGroup $NagiosRunFile
$NagiosBin -d $NagiosCfgFile
if [ -d $NagiosLockDir ]; then touch $NagiosLockDir/$NagiosLockFile; fi
echo ” done.”
exit 0
else
echo “CONFIG ERROR! Start aborted. Check your Nagios configuration.”
exit 1
fi
;;
根據(jù)nagios啟動(dòng)時(shí)的報(bào)錯(cuò)信息“CONFIG ERROR! Start aborted. Check your Nagios configuration.”,說(shuō)明在nagios執(zhí)行過(guò)程中,/usr/bin/nagios -v /etc/nagios/nagios.cfg是錯(cuò)誤的,去掉> /dev/null 2>&1,重新啟動(dòng)nagios,果然報(bào)錯(cuò)。提示nagios.cfg line465 配置錯(cuò)誤。
vi /etc/nagios/nagios.cfg –line 465
check_result_path=/var/nagios/spool/checkresults
配置是沒(méi)錯(cuò)的,權(quán)限也沒(méi)錯(cuò)。把/var/nagios/spool/checkresults修改為777也不行。修改為check_result_path=/tmp/checkresults后啟動(dòng)nagios,line465錯(cuò)誤解決。但出現(xiàn)更多的貌似權(quán)限錯(cuò)誤的配置。。。要瘋了。
d)懷疑nagios賬戶有問(wèn)題,果然id nagios也是異常的。
e)懷疑selinux disabled后沒(méi)有重啟機(jī)器,征求重啟機(jī)器,問(wèn)題果斷解決。
(6)done.
瀏覽器打開(kāi)http://120.132.xx.xx/nagios/發(fā)現(xiàn)無(wú)法連接,Y的。
查看了http是正常的。。。。再查原來(lái)http端口被之前他們改為8080了。
瀏覽器重新打開(kāi)http://120.132.xx.xx:8080/nagios/
everything done!!!
3.在所有(17臺(tái))被監(jiān)控服務(wù)器上部署nrpe客戶端
(1)安裝相關(guān)軟件包
rpm -ivh *.rpm
fping-2.4-1.b2.2.el5.rf.i386.rpm
perl-Net-SNMP-5.2.0-1.2.el5.rf.noarch.rpm
perl-Socket6-0.19-3.fc6.x86_64.rpm
perl-Crypt-DES-2.05-3.2.el5.rf.x86_64.rpm
lm_sensors-2.10.0-3.1.x86_64.rpm
perl-Digest-HMAC-1.01-15.noarch.rpm
perl-Digest-SHA1-2.11-1.2.1.x86_64.rpm
nagios-plugins-1.4.13-1.el5.rf.x86_64.rpm
nagios-nrpe-2.5.2-1.el5.rf.x86_64.rpm
sysstat-7.0.2-1.el5.x86_64.rpm
(2)修改nrpe.cfg
vi /etc/nagios/nrpe.cfg
allowed_hosts=192.168.100.6
command[check_cpu]=/usr/lib64/nagios/plugins/check_cpu
command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,12,9 -c 30,25,20
command[check_disk]=/usr/lib64/nagios/plugins/check_disk -w 12% -c 8% -p /
(3)啟動(dòng)nrpe
/etc/init.d/nrpe start
netstat -npl 查看nrpe5666端口是否啟動(dòng)了。
(4)測(cè)試
在100.6執(zhí)行如下命令進(jìn)行測(cè)試
/usr/lib64/nagios/plugins/check_nrpe -H 192.168.100.1 -c check_cpu
4.配置nagios
(1)cat /etc/nagios/objects/service/vianethost.cfg
################ jiaoxiao quan server ##############################[!--empirenews.page--]
define host{
use linux-server
host_name 192.168.100.1
alias 192.168.100.1
address 192.168.100.1
}
define host{
use linux-server
host_name 192.168.100.2
alias 192.168.100.2
address 192.168.100.2
}
(2)cat /etc/nagios/objects/service/vianetgroup.cfg
############## jiaxiao quan server ################
define hostgroup{
hostgroup_name jiaxiao-server
alias jiaxiao quan server
members 192.168.100.1,192.168.100.2
}
(3)cat /etc/nagios/objects/service/vianetservice.cfg
#############Nagios NRPE################
define service {
use generic-service
hostgroup_name jiaxiao-server
service_description Load
check_command check_nrpe!check_load
}
define service {
use generic-service
hostgroup_name jiaxiao-server
service_description Disk_Free
check_command check_nrpe!check_disk
}
define service {
use generic-service
hostgroup_name jiaxiao-server
service_description CPU
check_command check_nrpe!check_cpu
}
(4)啟動(dòng)nagios
/usr/bin/nagios -v /etc/nagios/nagios.cfg 正常
/etc/init.d/nagios restart 正常
瀏覽器打開(kāi)http://120.132.xx.xx:8080/nagios/ 查看, 正常
5.配置nsca
在2.14上起nsca daemon服務(wù),在100.6通過(guò)send_nsca傳送到2.14(120.132.xx.xx)統(tǒng)一進(jìn)行前端頁(yè)面展示管理。
(1)編譯nsca
wget http://nchc.dl.sourceforge.net/sourceforge/nagios/nsca-2.7.2.tar.gz
tar -zxvf nsca-2.7.2.tar.gz
cd nsca-2.7.2
./configure && make all
(2)nsca2.14服務(wù)端配置(之前已配置好)
cp sample-config/nsca.cfg /etc/nagios/
cp src/nsca /usr/sbin/
配置password
vi /etc/nagios/nsca.cfg
password=139com
開(kāi)啟nsca程序
/usr/sbin/nsca -c /etc/nagios/nsca.cfg –daemon
vi /usr/local/nagios/etc/nagios.cfg
check_external_commands=1
accept_passive_service_checks=1
accept_passive_host_checks=1
(3)100.6nsca客服端配置
cp sample-config/send_nsca.cfg /etc/nagios/
cp src/send_nsca /usr/bin/
配置password
vi /etc/nagios/send_nsca.cfg
password=139com
vi /usr/local/nagios/etc/nagios.cfg
enable_notifications=0
obsess_over_services=1
ocsp_command=submit_check_result
obsess_over_hosts=1
ochp_command=submit_host_result
cat submit_check_result
#!/bin/sh
return_code=-1
case “$3″ in
OK)
return_code=0
;;
WARNING)
return_code=1
;;
CRITICAL)
return_code=2
;;
UNKNOWN)
return_code=-1
;;
esac
/usr/bin/printf “%s\t%s\t%s\t%s\n” “$1″ “$2″ “$return_code” “$4″ | /usr/bin/send_nsca -H 120.132.xx.xx -p 15667 -c /etc/nagios/send_nsca.cfg
cat submit_host_result
#!/bin/sh
/usr/bin/printf “%s\t%s\t%s\t%s\n” “$1″ “$2″ “$3″ |/usr/bin/send_nsca -H 120.132.xx.xx -p 15667 -c /etc/nagios/send_nsca.cfg
(3)測(cè)試
echo “192.168.100.8;TEST_NSCA;2;hahajusttest” | /usr/bin/send_nsca -H 120.132.xx.xx-p 15667 -to 10 -d “;” -c /etc/nagios/send_nsca.cfg
1 data packet(s) sent to host successfully.
6.在2.14上配置被動(dòng)監(jiān)控
(1)cat vianethost.cfg
############ jiaoxiao quan server ##################
define host{
use passive-server
host_name 192.168.100.1
alias 100.1(jiaxiao_web)
address 192.168.100.1
}
define host{
use passive-server
host_name 192.168.100.2
alias 100.2(jiaxiao_web)
address 192.168.100.2
}
(2)cat vianetgroup.cfg
############## jiaxiao quan server ################
define hostgroup{
hostgroup_name jiaxiao-server
alias jiaxiao quan server
members 192.168.100.1,192.168.100.2
}
(3)cat vianetservice.cfg
#############Nagios NRPE################
define service {
use passive-service
hostgroup_name jiaxiao-server
service_description Load
}
define service {
use passive-service
hostgroup_name jiaxiao-server
service_description Disk_Free
}
define service {
use passive-service
hostgroup_name jiaxiao-server
service_description CPU
}
(4)啟動(dòng)nagios
/usr/bin/nagios -v /etc/nagios/nagios.cfg 正常
/etc/init.d/nagios restart 正常
瀏覽器打開(kāi)http://120.132.xx.xx:10000/nagios/查看, 正常
over!!