搭建基於Nagios的監控系統——之監控遠程Linux伺服器

來源:互聯網
上載者:User

標籤:only   命令   mod   list   這一   遠程服務   http   lib   get   

上一篇介紹了如何安裝Nagios Core,這一篇跟大家分享一下如何將一台遠端Linux伺服器加入納入監控範圍。

 

第一部分:在遠程Linux上安裝Nagios Plugins和NRPE

 

第一步:下載Nagios Plugins和NREP擴充的安裝程式

 

 

[plain] view plain copy 
  1. cd Downloads  
  2. 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 
  1. /usr/sbin/useradd nagios  

 

第三步:安裝Nagios Plugins

 

[plain] view plain copy 
  1. tar xf nagios-plugins-2.0.tar.gz  
  2. cd nagios-plugins-2.0  
  3. export LDFLAGS=-ldl  
  4. 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 
  1. tar xf nrpe-2.15.tar.gz  
  2. cd nrpe-2.15  
  3. ./configure  
  4. make all  
  5.   
  6. make install-plugins  
  7.   
  8. make install-daemon  
  9.   
  10. make install-daemon-config  
  11.   
  12. 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 
    1. nrpe 5666/tcp # NRPE  
  • 啟動服務[plain] view plain copy 
    1. service xinetd restart  
  • 確認現在NRPE連接埠是否在監聽[plain] view plain copy 
    1. netstat -at | grep nrpe  
    2. tcp 0      0 *:nrpe *:*                         LISTEN  
  • 確認NRPE是否正常[plain] view plain copy 
    1. /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 
  1. tar xf nrpe-2.15.tar.gz  
  2. cd nrpe-2.15  
  3. ./configure  
  4. make all  
  5. 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 
  1. /etc/init.d/nagios start  

搭建基於Nagios的監控系統——之監控遠程Linux伺服器

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.