您好,登錄后才能下訂單哦!
1、工作原理:
相比與主動模式中服務器主動去被監控機上輪詢獲取監控數據的方式,被動模式則是在被監控機上面通過插件或腳本獲取監控數據,然后將數據通過send_nsca發往監控機,最后監控機通過Nsca接收并解析數據,并傳遞給Nagios。這樣做的一個很大的優勢就是將除去處理數據的其他工作都放在了被監控機上面(包括了數據的傳輸),這樣就避免了被監控機數量大時,一次輪詢時間過長而導致監控反應延遲,這也是被動模式能承擔更大監控量的關鍵。
在MonitorClient上面,使用nagios-plugins提供的插件,得出監控數據,然后將數據存為一個文件,利用輸入重定向,通過send_nsca將數據發往MonitorServer。MonitorServer上面運行一個nsca的daemon(默認開啟5667端口),用來接收這些數據,然后做一個簡單的處理(會和nagios的service文件進行對應,將多余的監控數據排除),然后將數據進行格式的轉換,發給nagios的“外部命令文件”(默認配置為“/usr/local/nagios/var/rw/nagios.cmd”在nagios.cfg中定義的)。該文件是一個管道文件,也是nagios主程序的一個接口(用來接收監控數據),使用cat查看該文件時候,會出來經nsca處理后的數據格式。然后nagios主程序對數據進行處理(前臺展示,警報)。
2、組成:
Nsca (安裝在MonitorServer上,用來接收并解析MonitorClient發來的監控數據,傳遞給nagios)
Send_nsca(安裝在MonitorClient上,用來發送監控數據。)
3、實現過程:
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)、定義一個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)、定義一臺主機需要被監控的服務
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 (這里務必使用對外表現的IP)
debug=1 (debug選項即log選項,寫入message)
aggregate_writes=1 (能夠支持更大的監控量,建議開啟)
max_packet_age=60 (數據包過期時間,默認30s,但是考慮到網絡因素建議設為60s)
password=xxxxxxx (密碼,最基礎的加密方式,也可以不設置)
service nagios start
service nsca start
7)、在nagios client端安裝nsca服務(其實只需要send_nsca和send_nsca.cfg兩個文件,所以可以從nagios server端直接分發到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設置監控腳本,調用libexec中nagios-plugins提供的插件,內容如下,其中JYS_check_proce是自定義的服務
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中添加任務
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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。