linux下安裝配置nagios監控

來源:互聯網
上載者:User

標籤:linux   nagios   centos   警示   

nagios安裝配置:

Nagios官網 http://www.nagios.org

環境搭建:

centos6.6 192.168.11.30    做服務端

centos6.6 192.168.11.100   做用戶端


1. Nagios安裝 - 服務端(192.168.11.30)

Centos6預設的yum源裡沒有nagios相關的rpm包,但是我們可以安裝一個epel的擴充源:

yum install -y epel-release

安裝nagios相關的包

yum install -y httpd nagios nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe

設定登入nagios背景使用者和密碼:

htpasswd -c /etc/nagios/passwd nagiosadmin

nagios -v /etc/nagios/nagios.cfg 檢測設定檔是否有錯誤

啟動服務:

service httpd startservice nagios start

瀏覽器訪問: http://192.168.11.30/nagios/

彈出認證對話方塊,需要輸入nagiosadmin及密碼,登入nagios介面;

左側hosts列出服務端或監控主機列表;

650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/6E/88/wKioL1V_jmuwJO2JAAKpNHR0eHE721.jpg" title="nagios1.jpg" alt="wKioL1V_jmuwJO2JAAKpNHR0eHE721.jpg" />

services列出監控的8個服務項目(系統負載、使用者、HTTP、ping、磁碟分割、SSH、swap交換分區、系統進程)

650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/6E/8C/wKiom1V_jNahB0RLAALQ0ms9gcg887.jpg" title="nagios2.jpg" alt="wKiom1V_jNahB0RLAALQ0ms9gcg887.jpg" />


2. Nagios安裝 - 用戶端(192.168.11.100)

在用戶端機器上

yum install -y epel-releaseyum install -y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe

編輯設定檔:

vim /etc/nagios/nrpe.cfg  

找到“allowed_hosts=127.0.0.1” 改為 “allowed_hosts=127.0.0.1,192.168.11.30” 後面的ip為服務端ip

找到” dont_blame_nrpe=0” 改為  “dont_blame_nrpe=1”

啟動用戶端

 /etc/init.d/nrpe start

3. 監控中心服務端(192.168.11.30)添加被監控主機(192.168.11.100)

服務端進行下面的操作:

cd /etc/nagios/conf.d/

vim 192.168.11.100.cfg                   //加入:

define host{        use                     linux-server                    host_name          192.168.11.100        alias                   11.100        address                 192.168.11.100        }define service{        use                     generic-service        host_name               192.168.11.100        service_description     check_ping        check_command           check_ping!100.0,20%!200.0,50%        max_check_attempts 5        normal_check_interval 1}define service{        use                     generic-service        host_name               192.168.11.100        service_description     check_ssh        check_command           check_ssh        max_check_attempts      5#    ;當nagios檢測到問題時,一共嘗試檢測5次都有問題才會警示,如果該數值為1,那麼檢測到問題立即警示        normal_check_interval 1#   ;重新檢測的時間間隔,單位是分鐘,預設是3分鐘        notification_interval           60# ;在服務出現異常後,故障一直沒有解決,nagios再次對使用者發出通知的時間。單位是分鐘。如果你認為,所有的事件只需要一次通知就夠了,可以把這裡的選項設為0。}define service{        use                     generic-service        host_name               192.168.11.100        service_description     check_http        check_command           check_http        max_check_attempts      5        normal_check_interval 1}

以上服務不依賴於用戶端nrpe服務,我們可以想象,我們在自己電腦上可以使用ping或者telnet探測遠程任何一台機器是否存活、是否開啟某個連接埠或服務。 而當我們想要檢測用戶端上的某個具體服務的情況時,就需要藉助於nrpe了,比如想知道用戶端機器的負責或磁碟使用方式。


4.  繼續添加服務

服務端:vim /etc/nagios/objects/commands.cfg

增加:

define command{        command_name    check_nrpe        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$        }

繼續編輯 vim /etc/nagios/conf.d/192.168.11.100.cfg

增加如下內容:

define service{        use     generic-service        host_name       192.168.11.100        service_description     check_load        check_command           check_nrpe!check_load        max_check_attempts 5        normal_check_interval 1}define service{        use     generic-service        host_name       192.168.11.100        service_description     check_disk_hda1        check_command           check_nrpe!check_hda1        max_check_attempts 5        normal_check_interval 1}define service{        use     generic-service        host_name       192.168.11.100        service_description     check_disk_hda2        check_command           check_nrpe!check_hda2        max_check_attempts 5        normal_check_interval 1}

說明:  check_nrpe!check_load :這裡的check_nrpe就是在commands.cfg剛剛定義的,check_load是遠程主機上的一個檢測指令碼;


在監控客戶機機上vim /etc/nagios/nrpe.cfg 搜尋check_load,這行就是在服務端上要執行的指令碼了,我們可以手動執行這個指令碼

把check_hda1更改一下:/dev/hda1 改為 /dev/sda1

再加一行command[check_hda2]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda2

用戶端上重啟一下nrpe服務: service nrpe restart

服務端也重啟一下nagios服務: service nagios restart


重啟之後在web介面會出現192.168.11.100的監控資訊:

service是指令碼定義的服務名;DISK(87% inode=99%)表示磁碟剩餘空間比例87%,inode剩餘99%;

650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/6E/8C/wKiom1V_jYfSlvfKAAISlTJtPlY533.jpg" title="nagios3.jpg" alt="wKiom1V_jYfSlvfKAAISlTJtPlY533.jpg" />


5.   配置警示

vim /etc/nagios/objects/contacts.cfg //增加:

define contact{        contact_name               123        use                             generic-contact        alias                           aaa        email              [email protected]        }define contact{        contact_name               456        use                             generic-contact        alias                            bbb        email              [email protected]        }define contactgroup{        contactgroup_name           common        alias                                  common        members                          123,456        }

然後在要需要警示的服務裡面加上contactgroup

vi /etc/nagios/conf.d/192.168.11.100.cfg    增加下面的內容:

define service{        use     generic-service,srv-pnp        host_name       192.168.11.100        service_description     check_load        check_command           check_nrpe!check_load        max_check_attempts 5        normal_check_interval 1        contact_groups        common        notifications_enabled  1#    ;是否開啟提醒功能。1為開啟,0為禁用。一般,這個選項會在主設定檔(nagios.cfg)中定義,效果相同。        notification_period   24x7#   ;發送提醒的時間段。非常重要的主機(服務)我定義為7×24,一般的主機(服務)就定義為上班時間。如果不在定義的時間段內,無論什麼問題發生,都不會發送提醒。        notification_optionsc#   ;這個是service的狀態。w為waning, u為unknown, c為critical, r為recover(恢複了),可以寫多個狀態,使用逗號隔開,類似的還有一個  host對應的狀態:d,u,r   d = 狀態為DOWN, u = 狀態為UNREACHABLE , r = 狀態恢複為OK,需要加入到host的定義配置裡。}


配置警示郵件:

要想收到郵件,需要安裝sendmail包 yum install -y sendmail;

安裝後啟動sendmail服務;/etc/init.d/sendmail start 

並且關閉postfix    # /etc/init.d/postfix stop

netstat -nlp 查看sendmail服務是否被監聽

警示郵箱地址不能寫QQ郵箱,因為會攔截sendmail發出的郵件,顯示550錯誤;可以填寫163的郵箱;


/var/log/maillog    查看mail日誌


並且保持hostname一致;可以自訂一個網域名稱;

/etc/sysconfig/networkHOSTNAME=localhost.localdomain
# cat /etc/hosts127.0.0.1   localhost localhost.localdomain::1         localhost localhost.localdomain192.168.11.30 rfyy.net rfyy127.0.0.1 rfyy.net rfyy


登入163郵箱——設定——反垃圾\黑白名單——白名單 添加[email protected]  自己定義的尾碼網域名稱;


重啟機器,啟動各項服務,發現hostname變為rfyy.net,查看日誌發送郵件名也變為自訂的;163也收到警示郵件了;

[[email protected] ~]# hostnamerfyy.net
Jun 16 17:16:43 rfyy sendmail[1225]: t5G9GdAd001223: to=<[email protected]>, ctladdr=<[email protected]> (497/498), delay=00:00:03, xdelay=00:00:03, mailer=esmtp, pri=120678, relay=163mx01.mxmail.netease.com. [220.181.14.136], dsn=2.0.0, stat=Sent (Mail OK queued as mx12,PsCowEBZ4UJBeX9VOdmmBw--.5481S3 1434417474)

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/6E/8C/wKiom1V_joHQIfNLAAEgNJ6pD9Y495.jpg" title="youjian.jpg" alt="wKiom1V_joHQIfNLAAEgNJ6pD9Y495.jpg" />



本文出自 “模範生的學習部落格” 部落格,請務必保留此出處http://8802265.blog.51cto.com/8792265/1662250

linux下安裝配置nagios監控

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.