Nagios 3.0如何監(jiān)控Linux服務(wù)器?
nagios監(jiān)控Linux服務(wù)器的過程如下所述:
客戶端配置:
建用戶:
useradd nagios (可以在 /etc/password 里修改此帳戶的shell為 /sbin/nologin)
passwd nagios
安裝插件:
- tar zxvf nagios-plugins-1.4.11.tar.gz
- cd nagios-plugins-1.4.11
- ./configure--prefix=/usr/local/nagios --enable-redhat-pthread-workaround
- make all
- make install
修改權(quán)限:
chown nagios:nagios /usr/local/nagios –R
安裝Nrpe服務(wù):
- tar zxvf nrpe-2.8.1.tar.gz
- cd nrpe-2.8.1
- ./configure –prefix=/usr/local/nagios [./configure --enable-ssl --enable-command-args]
- make all (編譯)
- make install-plugin (安裝插件)
- make install-daemon (安裝 nrpe daemon)
- make install-daemon-config (安裝配置文件)
- make install-xinetd (安裝xinetd 腳本文件)
添加服務(wù)器IP:
vi /etc/xinetd.d/nrpe
only_from = 127.0.0.1 192.168.0.108
添加 nrpe 服務(wù):
vi /etc/services
Nrpe 5666/tcp # nrpe
重新啟動Xinetd服務(wù):
service xinetd restart
查看Nrpe服務(wù)是否開啟:
netstat -ant|grep 5666
測試Nrpe是否能正常工作:
/usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.8.1 (這表示在本地用check_nrpe連接nrpe daemon是正常的)
服務(wù)端配置:
A 拷貝 localhost.cfg 模板文件,對192.168.112.101進行監(jiān)控:
cp /usr/local/nagios/etc/localhost.cfg /usr/local/nagios/etc/192.168.112.101.cfg
vi 192.168.112.101.cfg
修改配置(主機名、IP、別名)
B 將192.168.112.101.cfg 加入nagios 主配置文件:
vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/192.168.112.101.cfg
C 驗證配置文件是否正確,并重啟:
/usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/object/nagios.cfg
Service nagios restart (重啟nagios 使配置生效)
D 查看naigios監(jiān)控頁面,發(fā)現(xiàn)主機已經(jīng)被正常添加。
服務(wù)端增加監(jiān)控服務(wù)(非必須):
在Command.cfg文件中增加check_nrpe的功能:
- vi /usr/local/nagios/etc/commands.cfg
- define command{
- command_name check_nrpe
- command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
- }
注意:-c后面帶的$ARG1$參數(shù)是傳給nrpe daemon執(zhí)行的檢測命令,在services.cfg中使用check_nrpe的時候要用!帶上這個參數(shù)。
額外知識點:
vi /usr/local/nagios/etc/nrpe.cfg
找到以下這段內(nèi)容:
- # The following examples use hardcoded command arguments...
- command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
- command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
- command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hda1
- command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
- command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
[] 中是命令名,也就是check_nrpe 的-c參數(shù)可以接的內(nèi)容,=后面是實際執(zhí)行的插件程序commands.cfg中定義命令的形式十分相似,只不過是寫在了一行.也就是說check_users就是等號后面/usr/local/nagios/libexec/check_users -w 5 -c 10的簡稱.
我們可以很容易知道上面這5行定義的命令分別是檢測登陸用戶數(shù),cpu負載,hda1的容量,僵尸進程,總進程數(shù).用法: ./check_load --help,由于-c后面只能接nrpe.cfg中定義的命令,也就是說現(xiàn)在我們只能用上面定義的這五條命令。
nagios的其他配置請讀者閱讀:
安裝配置nagios、修改Apache配置、Nagios 3.0初步安裝配置、監(jiān)控Windows服務(wù)器和十個Nagios故障解決技巧