您好,登錄后才能下訂單哦!
1、工作原理:
相比與主動(dòng)模式中服務(wù)器主動(dòng)去被監(jiān)控機(jī)上輪詢獲取監(jiān)控?cái)?shù)據(jù)的方式,被動(dòng)模式則是在被監(jiān)控機(jī)上面通過插件或腳本獲取監(jiān)控?cái)?shù)據(jù),然后將數(shù)據(jù)通過send_nsca發(fā)往監(jiān)控機(jī),最后監(jiān)控機(jī)通過Nsca接收并解析數(shù)據(jù),并傳遞給Nagios。這樣做的一個(gè)很大的優(yōu)勢(shì)就是將除去處理數(shù)據(jù)的其他工作都放在了被監(jiān)控機(jī)上面(包括了數(shù)據(jù)的傳輸),這樣就避免了被監(jiān)控機(jī)數(shù)量大時(shí),一次輪詢時(shí)間過長(zhǎng)而導(dǎo)致監(jiān)控反應(yīng)延遲,這也是被動(dòng)模式能承擔(dān)更大監(jiān)控量的關(guān)鍵。
在MonitorClient上面,使用nagios-plugins提供的插件,得出監(jiān)控?cái)?shù)據(jù),然后將數(shù)據(jù)存為一個(gè)文件,利用輸入重定向,通過send_nsca將數(shù)據(jù)發(fā)往MonitorServer。MonitorServer上面運(yùn)行一個(gè)nsca的daemon(默認(rèn)開啟5667端口),用來接收這些數(shù)據(jù),然后做一個(gè)簡(jiǎn)單的處理(會(huì)和nagios的service文件進(jìn)行對(duì)應(yīng),將多余的監(jiān)控?cái)?shù)據(jù)排除),然后將數(shù)據(jù)進(jìn)行格式的轉(zhuǎn)換,發(fā)給nagios的“外部命令文件”(默認(rèn)配置為“/usr/local/nagios/var/rw/nagios.cmd”在nagios.cfg中定義的)。該文件是一個(gè)管道文件,也是nagios主程序的一個(gè)接口(用來接收監(jiān)控?cái)?shù)據(jù)),使用cat查看該文件時(shí)候,會(huì)出來經(jīng)nsca處理后的數(shù)據(jù)格式。然后nagios主程序?qū)?shù)據(jù)進(jìn)行處理(前臺(tái)展示,警報(bào))。
2、組成:
Nsca (安裝在MonitorServer上,用來接收并解析MonitorClient發(fā)來的監(jiān)控?cái)?shù)據(jù),傳遞給nagios)
Send_nsca(安裝在MonitorClient上,用來發(fā)送監(jiān)控?cái)?shù)據(jù)。)
3、實(shí)現(xiàn)過程:
1)、修改nagios配置文件
vim /usr/local/nagios/etc/nagios.cfg
check_external_commands = 1 (enable commands file)
command_check_interval = -1 (check the external command file as often as possible )
2)、添加模板
vim /usr/local/nagios/etc/objects/template.cfg
define service{
name passive_service
use generic-service
max_check_attempts 3
active_checks_enabled 0
passive_checks_enabled 1
normal_check_interval 5
retry_check_interval 1
notifications_enabled 1
notification_interval 5
notification_period 24x7
contact_groups admins
register 0
}
3)、定義一個(gè)command
vim /usr/local/nagios/etc/objects/command.cfg
define command{
command_name check_dummy
command_line /usr/local/nagios/libexec/check_dummy $ARG1$
}
4)、定義一臺(tái)主機(jī)需要被監(jiān)控的服務(wù)
vim /usr/local/nagios/etc/objects/XH_DemoTrade.cfg
define service{
use passive_service
host_name XH_DemoTrade
service_description load
check_command check_dummy
contact_groups admins
}
define service{
use passive_service
host_name XH_DemoTrade
service_description disk
check_command check_dummy
contact_groups admins
}
define service{
use passive_service
host_name XH_DemoTrade
service_description logonService_aufront_common
check_command check_dummy
contact_groups admins
}
define service{
use passive_service
host_name XH_DemoTrade
service_description http
check_command check_dummy
contact_groups admins
}
5)、下載安裝nsca
wget http://nchc.dl.sourceforge.net/project/nagios/nsca-2.x/nsca-2.9.1/nsca-2.9.1.tar.gz
tar zxvf nsca-2.9.1.tar.gz
./configure
make all
cp ./src/nsca /usr/local/nagios/bin/
cp ./sample-config/nsca.cfg /usr/local/nagios/etc
chown nagios.nagios /usr/local/nagios/bin/nsca
chown nagios.nagios /usr/local/nagios/etc/nsca.cfg
cp init-script /etc/init.d/nsca
chmod a+x /etc/init.d/nsca
chkconfig --add nsca
6)、編輯nsca配置文件
vim /usr/local/nagios/etc/nsca.cfg
server_address=10.0.100.32 (這里務(wù)必使用對(duì)外表現(xiàn)的IP)
debug=1 (debug選項(xiàng)即log選項(xiàng),寫入message)
aggregate_writes=1 (能夠支持更大的監(jiān)控量,建議開啟)
max_packet_age=60 (數(shù)據(jù)包過期時(shí)間,默認(rèn)30s,但是考慮到網(wǎng)絡(luò)因素建議設(shè)為60s)
password=xxxxxxx (密碼,最基礎(chǔ)的加密方式,也可以不設(shè)置)
service nagios start
service nsca start
7)、在nagios client端安裝nsca服務(wù)(其實(shí)只需要send_nsca和send_nsca.cfg兩個(gè)文件,所以可以從nagios server端直接分發(fā)到nagios client)
wget http://nchc.dl.sourceforge.net/project/nagios/nsca-2.x/nsca-2.9.1/nsca-2.9.1.tar.gz
tar zxvf nsca-2.9.1.tar.gz
./configure
make all
cp ./src/send_nsca /usr/local/nagios/bin/
cp ./sample-config/send_nsca.cfg /usr/local/nagios/etc
chown nagios.nagios /usr/local/nagios/bin/nsca
chown nagios.nagios /usr/local/nagios/etc/nsca.cfg
8)、在nagios client設(shè)置監(jiān)控腳本,調(diào)用libexec中nagios-plugins提供的插件,內(nèi)容如下,其中JYS_check_proce是自定義的服務(wù)
vim /usr/local/nagios/nsca.sh
#!/bin/sh
host_name=$1
svc_name=$2
load_ARG="-w 5 -c 10"
http_ARG="-H 172.18.11.30 -u http://172.18.11.30/index.html"
disk_ARG="-w 20% -c 10% -p /dev/sda"
#echo "$host_name\t$svc_name\n"
case "$2" in
check_load)
output=`/usr/local/nagios/libexec/$2 $load_ARG`
status=`echo $?`
echo "$host_name;load;$status;$output">/tmp/nsca_load.out
cat /tmp/nsca_load.out | /usr/local/nagios/bin/send_nsca -H 10.0.100.32 -d ";" -c /usr/local/nagios/etc/send_nsca.cfg
;;
check_http)
output=`/usr/local/nagios/libexec/$2 $http_ARG`
status=`echo $?`
echo $status
echo "$host_name;http;$status;$output">/tmp/nsca_http.out
cat /tmp/nsca_http.out | /usr/local/nagios/bin/send_nsca -H 10.0.100.32 -d ";" -c /usr/local/nagios/etc/send_nsca.cfg
;;
check_disk)
output=`/usr/local/nagios/libexec/$2 $disk_ARG`
status=`echo $?`
echo "$host_name;disk;$status;$output">/tmp/nsca_disk.out
cat /tmp/nsca_disk.out | /usr/local/nagios/bin/send_nsca -H 10.0.100.32 -d ";" -c /usr/local/nagios/etc/send_nsca.cfg
;;
JYS_check_proce)
output=`/usr/local/nagios/libexec/$2 $3`
status=`echo $?`
echo "$host_name;$3;$status;$output">/tmp/nsca_JYS.out
cat /tmp/nsca_JYS.out | /usr/local/nagios/bin/send_nsca -H 10.0.100.32 -d ";" -c /usr/local/nagios/etc/send_nsca.cfg
;;
esac
9)、在crontab中添加任務(wù)
crontab -e
*/5 * * * * /bin/sh /usr/local/nagios/nsca.sh XH_DemoTrade JYS_check_proce logonService_aufront_common
*/5 * * * * /bin/sh /usr/local/nagios/nsca.sh XH_DemoTrade check_http -H 127.0.0.1
*/5 * * * * /bin/sh /usr/local/nagios/nsca.sh XH_DemoTrade check_disk
*/5 * * * * /bin/sh /usr/local/nagios/nsca.sh XH_DemoTrade check_load
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。