本次實測使用兩台虛擬機:linux1(192.168.1.122)作為監控主機,linux2(192.168.1.192)作為被監控主機。以下先完成被監控主機端的設定。
延伸閱讀:Nagios 的安裝、基本配置與 PNP 整合等系列文章可參考 https://www.linuxidc.com/Linux/2011-11/47908.htm 等連結。
[root@localhost ~]# ls nagios-plugins-1.4.15.tar.gz nagios-plugins-1.4.15.tar.gz [root@localhost ~]# tar zxvf nagios-plugins-1.4.15.tar.gz [root@localhost nagios-plugins-1.4.15]# useradd -s /sbin/nologin nagios [root@localhost nagios-plugins-1.4.15]# ./configure [root@localhost nagios-plugins-1.4.15]# make;make install [root@localhost nagios-plugins-1.4.15]# cd /usr/local/ [root@localhost local]# chown nagios:nagios nagios/ [root@localhost local]# chown nagios:nagios -R nagios/libexec/
[root@localhost ~]# ls nrpe-2.8b1.tar.gz nrpe-2.8b1.tar.gz [root@localhost ~]# tar zxvf nrpe-2.8b1.tar.gz [root@localhost ~]# cd nrpe-2.8b1 [root@localhost nrpe-2.8b1]# ./configure [root@localhost nrpe-2.8b1]# make all [root@localhost nrpe-2.8b1]# make install-plugin [root@localhost nrpe-2.8b1]# make install-daemon [root@localhost nrpe-2.8b1]# make install-daemon-config
若英文不錯,也可直接參考包內附的 NRPE.pdf 說明文件安裝。
[root@localhost ~]# cd /usr/local/nagios/etc/ [root@localhost etc]# vi nrpe.cfg server_address=192.168.1.192 # 上為被監控主機 IP allowed_hosts=127.0.0.1,192.168.1.122,192.168.1.192 # 此處填入監控主機設定,為方便檢測也把本機 IP 加上
[root@localhost etc]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d [root@localhost etc]# netstat -tulnp|grep 5666 tcp 0 0 192.168.1.192:5666 0.0.0.0:* LISTEN 3384/nrpe [root@localhost etc]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.192 NRPE v2.8b1
當 check_nrpe 回傳版本號 NRPE v2.8b1,即表示 NRPE 已可正常運作,被監控端設定完成。