標籤:only 命令 mod list 這一 遠程服務 http lib get
上一篇介紹了如何安裝Nagios Core,這一篇跟大家分享一下如何將一台遠端Linux伺服器加入納入監控範圍。
第一部分:在遠程Linux上安裝Nagios Plugins和NRPE
第一步:下載Nagios Plugins和NREP擴充的安裝程式
[plain] view plain copy
- cd Downloads
- wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz
訪問 http://www.nagios.org/download/addons/,點擊 NRPE,在彈出的頁面中點擊 Download URL 就可以下載了。
第二步:建立使用者
[plain] view plain copy
- /usr/sbin/useradd nagios
第三步:安裝Nagios Plugins
[plain] view plain copy
- tar xf nagios-plugins-2.0.tar.gz
- cd nagios-plugins-2.0
- export LDFLAGS=-ldl
- sudo -s
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaroundmake && make install
chown nagios.nagios /usr/local/nagios<chown -R nagios.nagios /usr/local/nagios/libexec/
第四步:安裝NRPE
[plain] view plain copy
- tar xf nrpe-2.15.tar.gz
- cd nrpe-2.15
- ./configure
- make all
-
- make install-plugins
-
- make install-daemon
-
- make install-daemon-config
-
- make install-xinetd
第五步:將NRPE設定為守護進程(通過作為xinetd的一部分)
- 開啟 /etc/xinetd.d/nrpe 檔案,將負責監控的那台伺服器的IP地址,添加到 only_from 指令後面。多個IP地址之間要用空格隔開;
- 編輯 /usr/local/nagios/etc/nrpe.cfg ,在 allowd_hosts 指令後加上監控伺服器的IP地址,多了地址用逗號隔開;
- 修改 /etc/services 檔案,在檔案末尾添加一行:[plain] view plain copy
- nrpe 5666/tcp # NRPE
- 啟動服務[plain] view plain copy
- service xinetd restart
- 確認現在NRPE連接埠是否在監聽[plain] view plain copy
- netstat -at | grep nrpe
- tcp 0 0 *:nrpe *:* LISTEN
- 確認NRPE是否正常[plain] view plain copy
- /usr/local/nagios/libexec/check_nrpe -H localhost
第六步:修改 /usr/local/nagios/etc/nrpe.cfg
這個檔案中定義的命令決定了該伺服器能被監控的內容,也就是說,真正的監控是通過這個檔案裡的命令指定的程式來執行的。比如:
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
在添加到這個檔案之前,最好在命令列中實際執行一下這個命令:
/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
第二部分:在監控伺服器上增加遠程伺服器的配置
第一步:下載 NRPE 擴充,並且安裝
[plain] view plain copy
- tar xf nrpe-2.15.tar.gz
- cd nrpe-2.15
- ./configure
- make all
- make install-plugins
確認一下NRPE是否能連結到遠程伺服器
/usr/local/nagios/libexec/check_nrpe -H [遠程伺服器IP]
第二步:為遠程監控伺服器添加 HOST 和 Service 配置
只要增加監控的電腦,就要增加這兩部分!
這兩種配置可以分成兩個檔案,也可以放到一個檔案裡面。我在這裡將 /usr/local/nagios/etc/objects/localhost.cfg 複製了一下,並且命名為了 remotehost.cfg。
將 host 塊兒中的 host_name 和 alias 改成相應的遠程伺服器的名字和別名,將 address 改成遠程伺服器的IP地址。
host_group 的定義就可以刪除了,並且將這台遠程伺服器的名字添加到 localhost.cfg 中 host_group 塊兒中,寫在 localhost 後面既可,用逗號隔開。
下面所有的 services 定義中,就把 host 那麼換一下就可以了。
在 /usr/local/nagios/etc/nagios.cfg 當中,增加一條 cfg_file 指令,將新建立的檔案名稱加入到後面。
第三步:重啟Nagios
[plain] view plain copy
- /etc/init.d/nagios start
搭建基於Nagios的監控系統——之監控遠程Linux伺服器