Nagios監控linux服務器

平臺及所用組件,
監控服務器:RHEL5(192.168.0.20)+nagios-3.0.5+ nagios-plugins-1.4.11+ nrpe_2.8.1
被監控端RHEL5 (192.168.0.21)+ nagios-plugins-1.4.11+ nrpe_2.8.1
內容簡介
本文檔介紹nagios監控linux服務器, 因爲監控都是依靠插件去完成的,而監控linux主要使用NRPE插件,本文首先簡單介紹一下NRPE監控基礎,及監控過程,然後一步步的配置一個實例實現監控linux服務器

1.NRPE監控插件基礎

NRPE總共由兩部分組成:

check_nrpe插件,運行在監控主機上。
NRPE daemon,運行在遠程的linux主機上(通常就是被監控機)
整個的監控過程:(如下圖)

Nagios需要監控某個遠程linux主機的服務或者資源情況時:
1).nagios運行check_nrpe插件,我們要在nagios配置文件中告訴它要檢查什麼.
2).check_nrpe插件會通過SSL連接到遠程的NRPE daemon.
3).NRPE daemon會運行相應的nagios插件來執行檢查本地資源或服務.
4).NRPE daemon將檢查的結果返回給check_nrpe插件,插件將其遞交給nagios做處理.
注意:NRPE daemon需要nagios插件安裝在遠程被監控linux主機上,否則,daemon不能做任何的監控. 別外因爲它們間的通信是加密的SSL,所以在編譯安裝時都要加上選項, ./configure --enable-ssl --with-ssl-lib=/lib/,否則也會出錯.
 

2.配置監控端

1.安裝nagios

rpm -qa |grep gd
rpm -ql gd-devel-2.0.28-5.4E.el4_6.1
cd nagios-3.0.5
./configure --prefix=/usr/local/nagios --with-command-group=nagcmd --with-gd-lib=/usr/lib --with-gd-inc=/usr/include
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf #可以自動配置httpd.conf
2.安裝nagios-plugins

cd nagios-plugins-1.4.11
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround
make
make install
3.安裝NRPE

cd nagios-nrpe_2.8.1
./configure #默認自動添加了openssl
#因爲傳送過程要加密,如果後面make報錯,加如下參數

rpm -qa| grep ssl
openssl-devel-0.9.7a-43.17.el4_6.1
rpm -ql openssl-devel-0.9.7a-43.17.el4_6.1 | more
./configure --enable-ssl --with-ssl-lib=/lib/(當然前提要有openssl)
make all
make install-plugin
4.commands.cfg定義外部構件nrpe

vi /usr/local/nagios/etc/objects/commands.cfg
#添加

#check nrpe
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
5.配置要監控的linux主機

vi /usr/local/nagios/etc/nagios.cfg
#中間添加

cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg
6.新建mylinux.cfg 設置監控內容

vi /usr/local/nagios/etc/objects/mylinux.cfg
define host{
use linux-server
host_name mylinux
alias mylinux
address 192.168.0.21(客戶端IP既被監控的IP)
}
define service{
use generic-service
host_name mylinux
service_description check-swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name mylinux
service_description check-load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name mylinux
service_description check-disk
check_command check_nrpe!check_had1
define service{
use generic-service
host_name mylinux
service_description check-users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name mylinux
service_description otal_procs
check_command check_nrpe!check_total_procs
}
6.其它設置

chkconfig --add nagios #配置機器啓動時自動啓動Nagios
chkconfig nagios on
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #檢查Nagios配置文件
vi /etc/selinux/config #關閉SELinux
SELINUX=disabled
service iptables stop #關閉SELinux,或打開80,5666端口

service nagios start

3.配置被監控端

1.安裝nagios-plugin

useradd nagios
passwd nagios
tar -zxvf nagios-plugins-1.4.12.tar.gz
cd nagios-plugins-1.4.12
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround
Make
make install
2.改變主目錄權限

chown –R nagios.nagios /usr/local/nagios
[root@client nagios]# ll
drwxr-xr-x 2 nagios nagios 4096 Jun 1 00:07 libexec
drwxr-xr-x 3 nagios nagios 4096 Jun 1 00:07 share
3.安裝客戶端的nrpe

tar -zxvf nagios-nrpe_2.8.1.orig.tar.gz
cd nagios-nrpe_2.8.1
./configure (會自動加載SSL)
#如果後面make報錯,加如下參數

./configure --enable-ssl --with-ssl-lib=/usr/lib/(當然前提要有openssl)
make all
make install-plugin
make install-daemon
make install-daemon-config

4.配置nrpe信息

vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=192.168.0.20,127.0.0.1,192.168.0.99
5.啓動nrpe

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d

#

vi /etc/rc.d/rc.local
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d

6.驗證nrpe

netstat -an | grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v2.8.1
#服務端測試

/usr/local/nagios/libexec/check_nrpe -H l92.168.0.21
NRPE v2.8.1
#常見錯誤

/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
CHECK_NRPE: Error - Could not complete SSL handshake.
配置allowed_hosts=192.168.0.20,127.0.0.1,192.168.0.99,然後kill進程再重啓就OK
2./usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
Connection refused by host
Nrpe進程沒有啓動

7.配置監控對像(關鍵)

由監控原理可知被監控端做監控然後傳給監控服務器繪總,設置監控詳細參數主要是設置被監控端的nrpe.cfg文件
可以看到裏面監控對象
vi /usr/local/nagios/etc/nrpe.cfg
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
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
這一步是關鍵,如果nagios服務器想要監控客戶機swap分區,但客戶機nrpe.cfg文件沒有swap監控對像,這時監控服務器就是報錯(NRPE command ‘check_swap’no defined).如下圖:其實平時自己寫腳本,也是主要配這個地方
到此,就可以監控linux客戶機的Disk,swap,users,memory.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章