溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Nagios 實(shí)現(xiàn)多臺(tái)監(jiān)控

發(fā)布時(shí)間:2020-07-22 15:17:07 來(lái)源:網(wǎng)絡(luò) 閱讀:722 作者:凋零的回憶 欄目:移動(dòng)開(kāi)發(fā)
 1.Nagios監(jiān)控linux服務(wù)器平臺(tái)及所用組件,
    監(jiān)控服務(wù)器:CentOS 5.3x64(192.168.1.202)+nagios-3.2.1+ nagios-plugins-1.4.15+ nrpe_2.8.1
    被監(jiān)控端: CentOS 5.3x64(192.168.1.203)+ nagios-plugins-1.4.15+ nrpe_2.8.1

注意:兩端nrpe的版本要一致,不然無(wú)法相連接

 

NRPE總共由兩部分組成:

    check_nrpe插件,運(yùn)行在監(jiān)控主機(jī)上。

    NRPE daemon,運(yùn)行在遠(yuǎn)程的linux主機(jī)上(通常就是被監(jiān)控機(jī))


2.配置監(jiān)控端
安裝nagios
useradd nagios
passwd nagios
cd nagios-3.2.1
./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        #可以自動(dòng)配置httpd.conf
安裝nagios-plugins
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround
make
make install
安裝NRPE

#yum install openssl-devel (安裝 openssl包)

cd nagios-nrpe_2.8.1
./configure   #默認(rèn)自動(dòng)添加了openssl
#因?yàn)閭魉瓦^(guò)程要加密,如果后面make報(bào)錯(cuò),加如下參數(shù)
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/(當(dāng)然前提要有openssl)
make all
make install-plugin
commands.cfg定義外部構(gòu)件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$
        }
配置要監(jiān)控的linux主機(jī)
vi /usr/local/nagios/etc/nagios.cfg
#中間添加
cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg
新建mylinux.cfg 設(shè)置監(jiān)控內(nèi)容
vi /usr/local/nagios/etc/objects/mylinux.cfg
define host{
           use             linux-server
          host_name     mylinux
          alias            mylinux
          address        192.168.1.203(客戶端IP既被監(jiān)控的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
}
#這5個(gè)是默認(rèn)的監(jiān)控服務(wù),如需自定義服務(wù)可在這里添加
自定義服務(wù)可參考:http://saplingidea.javaeye.com/blog/514013
如有必要?jiǎng)t需更改check閾值,在被監(jiān)控端的/usr/local/nagios/etc/nrpe.cfg,下面會(huì)提到

其它設(shè)置
chkconfig --add nagios    #配置機(jī)器啟動(dòng)時(shí)自動(dòng)啟動(dòng)Nagios
chkconfig nagios on
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #檢查Nagios配置文件
vi /etc/selinux/config      #關(guān)閉SELinux
SELINUX=disabled
service iptables stop  #關(guān)閉SELinux,或打開(kāi)80,5666端口
service nagios start


2.配置被監(jiān)控端
1.安裝nagios-plugin
useradd nagios
passwd nagios
tar -zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround
Make
make install
改變主目錄權(quán)限
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
安裝客戶端的nrpe

yum install openssl-devel (安裝 openssl包)

tar -zxvf nagios-nrpe_2.8.1.orig.tar.gz
cd nagios-nrpe_2.8.1
./configure  (會(huì)自動(dòng)加載SSL)
#如果后面make報(bào)錯(cuò),加如下參數(shù)
./configure --enable-ssl --with-ssl-lib=/usr/lib/(當(dāng)然前提要有openssl)
make all
make install-plugin
make install-daemon
make install-daemon-config
配置nrpe信息
vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,192.168.1.202
啟動(dòng)nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
#上面這一步在本機(jī)上可以運(yùn)行,如通過(guò)ssh連接,則需用:/usr/local/nagios/bin/nrpe -d
vi /etc/rc.d/rc.local
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
驗(yàn)證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
#服務(wù)端測(cè)試
/usr/local/nagios/libexec/check_nrpe -H l92.168.1.203
NRPE v2.8.1
#常見(jiàn)錯(cuò)誤
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
CHECK_NRPE: Error - Could not complete SSL handshake.
配置allowed_hosts=127.0.0.1,192.168.1.202然后kill進(jìn)程再重啟就OK
2./usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
Connection refused by host
Nrpe進(jìn)程沒(méi)有啟動(dòng)

配置監(jiān)控對(duì)像(關(guān)鍵)
    由監(jiān)控原理可知被監(jiān)控端做監(jiān)控然后傳給監(jiān)控服務(wù)器繪總,設(shè)置監(jiān)控詳細(xì)參數(shù)主要是設(shè)置被監(jiān)控端nrpe.cfg文件
    可以看到里面監(jiān)控對(duì)象
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%
#這里就是上面提到的check閾值,如需更改,加減后面的數(shù)值即可

 



 
向AI問(wèn)一下細(xì)節(jié)

免責(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)容。

AI