欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Nagios遠(yuǎn)程監(jiān)控安裝與配置詳解圖文第3/3頁

 更新時間:2008年07月01日 22:36:21   作者:  
作為系統(tǒng)管理員,我最擔(dān)心那些重要的在線系統(tǒng)在我不知情的情況下停機(jī)或者停止網(wǎng)絡(luò)服務(wù),要改變這種被動局面,這里作者推薦一款網(wǎng)絡(luò)監(jiān)控軟件Nagios,文中講述作者使用Nagios的過程以及心得,希望對初學(xué)者有所幫助。

2、增加新的配置文件
先創(chuàng)建簡單的配置文件timeperiods.cfg,其內(nèi)容如下:
define timeperiod{
    timeperiod_name 24x7
    alias      24 Hours A Day, 7 Days A Week
    sunday     00:00-24:00
    monday     00:00-24:00
    tuesday     00:00-24:00
    wednesday    00:00-24:00
    thursday    00:00-24:00
    friday     00:00-24:00
    saturday    00:00-24:00
    }
這個文件的定義明晰易懂,不多做說明。另建議7X24小時監(jiān)控。
第二個手動創(chuàng)建的配置文件是 contacts.cfg,其格式如下:
define contact {
    contact_name     sa  //不要有空格
    alias        system administrator
    service_notification_period  24x7
    host_notification_period    24x7
    service_notification_options  w,u,c,r
    host_notification_options    d,u,r
    service_notification_commands service-notify-by-sms,service-
notify-by-email //這個命令讀配置文件miscommands.cfg
    host_notification_commands   host-notify-by-email,host-noti
fy-by-sms   //這個命令讀配置文件miscommands.cfg
    email             sery@163.com
    pager             13333333333 //手機(jī)號,收報警短信
    }   //不要把這個符號寫掉了

define contact {
    contact_name     sery
    alias        system administrator
    service_notification_period  24x7
    host_notification_period    24x7
    service_notification_options  w,u,c,r
    host_notification_options    d,u,r
    service_notification_commands service-notify-by-sms,service-
notify-by-email
    host_notification_commands   host-notify-by-email,host-noti
fy-by-sms
    email             sery@sohu.com
    pager             13312345678
    }
上面的文件定義了2個聯(lián)系人,如果有更多聯(lián)系人的話,照這個格式在后面追加即可。服務(wù)通知選項(xiàng)(service_notification_options)與主機(jī)通知選項(xiàng)(host_notification_options)的幾個選項(xiàng)在這里說明一下:w-warning , u-unknown,c-critical,r-recovery;d-down,u-unreachable,注意一下,主機(jī)報警和服務(wù)報警有些差異。
緊接著的第三個手動創(chuàng)建的配置文件是contactgroups.cfg文件,這個文件是依照上一個文件contacts.cfg來的,contactgroups文件相對簡單一些,其格式如下:
define contactgroup {
    contactgroup_name  sagroup //不要用空格
    alias        system administrator group
    members       sa,sery //本例有2個成員
}
多個成員之間用逗號做分界符,如果有更多的聯(lián)系組,就依相同的格式在文件中追加余下的組。
關(guān)鍵的角色終于登場,這就是配置文件hosts.cfg。下面是我定義的兩個主機(jī)的基本樣式:
#define monitor host

#################################################################
# Wangjing IDC servers                     #
#################################################################
define host {
    host_name         nagios-server
    alias           nagios server
    address          61.x..x.49
    contact_groups       sagroup //多個聯(lián)系組用逗號分隔,
數(shù)據(jù)來源于contactgroups.cfg check_command check-host-alive max_check_attempts 5 notification_interval 10 //值可調(diào),大小什么值合適需自己測定 notification_period 24x7 notification_options d,u,r } define host { host_name 24-25 alias server 24-25 address 202.X.24.25 contact_groups sagroup check_command check-host-alive //down機(jī)就發(fā)報警通知 max_check_attempts 5 notification_interval 10 notification_period 24x7 notification_options d,u,r }
更多的主機(jī)依此格式逐個追加進(jìn)來。小技巧,如果是連續(xù)的ip段,最好自己寫個腳本生成hosts.cfg文件,為了以后維護(hù)方便,盡可能在文件中使用易讀的注釋(如本例# Wangjing IDC servers #)。
再一個重量級的配置文件是services.cfg,沒有這個文件,什么監(jiān)控也沒用。下面給出一個樣式文件:
#service definition

##############################################################
# Wangjing IDC servers service for host-live        #
##############################################################
define service {
    host_name    nagios-server //來源:hosts.cfg
    service_description  check-host-alive
    check_period     24x7
    max_check_attempts  4
    normal_check_interval 3
    retry_check_interval 2
    contact_groups    sagroup //來源:contactgroups.cfg
    notification_interval  10
    notification_period   24x7
    notification_options  w,u,c,r
    check_command      check-host-alive //檢查主機(jī)是否存活
    }
define service {
    host_name    74-210
    service_description  check_tcp 80
    check_period     24x7
    max_check_attempts  4
    normal_check_interval 3
    retry_check_interval 2
    contact_groups    sagroup
    notification_interval  10
    notification_period   24x7
    notification_options  w,u,c,r
    check_command   check_tcp!80 //檢查tcp 80端口服務(wù)是否正常
    }
書寫時要注意的是,check_tcp與要監(jiān)控的服務(wù)端口之間要用”!”做分隔符。如果服務(wù)太多,以應(yīng)該考慮用腳本來生成。
主機(jī)組配置文件hostgroups.cfg,這是一個可選的項(xiàng)目,它建立在文件hosts之上,其格式如下:
define hostgroup {
     hostgroup_name sa-servers
     alias      sa servers
     members     nagios-server,24-25,24-26 //用逗號間隔多個主機(jī)
     }
多個主機(jī)組依上面的格式逐個追加上去。后面給一個主機(jī)組的截圖。

 千辛萬苦,終于把這些配置給做好保存,現(xiàn)在幾乎有點(diǎn)迫不及待了,運(yùn)行程序/usr/local/nagios –v /usr/local/nagios/etc/nagios.cfg來檢查所有配置文件的正確性。如果十分幸運(yùn)的話,運(yùn)行完畢將在輸出尾部出現(xiàn):

Total Warnings: 0
Total Errors:  0

Things look okay - No serious problems were detected during the pre-flight check
這樣的情況,大功告成;但我卻沒有這么幸運(yùn),修改了好多個地方才成功。不過值得慶幸的是,這個校驗(yàn)的錯誤報告時非常有用的(不象有的系統(tǒng)的幫助文檔中看不中用)??次夜室庠O(shè)置的一個錯誤產(chǎn)生的輸出:
[root@netmonitor nagios]# bin/nagios -v etc/nagios.cfg

Nagios 2.5
Copyright (c) 1999-2006 Ethan Galstad (http://www.nagios.org)
Last Modified: 07-13-2006
License: GPL

Reading configuration data...

Error: Could not find any host matching 'nagios-server'
Error: Could not expand member hosts specified in hostgroup 
(config file '/usr/local/nagios/etc/hostgroups.cfg', starting on line 2) ………………………
它告訴我配置文件在什么位置產(chǎn)生錯誤(實(shí)際上我故意在配置文件里加了一個注釋符號來測試)。驗(yàn)證通過以后,就可以執(zhí)行命令/usr/local/nagios –d  /usr/local/nagios/etc/nagios.cfg 把nagios作為守護(hù)進(jìn)程。然后用ps –aux | grep nagios 看進(jìn)程是否處于運(yùn)行狀態(tài)。到這一步,nagios服務(wù)基本上算是配置完畢。做hosts.cfg、services.cfg等配置時,可以運(yùn)用一些小技巧來減少出錯的概率:如先定義少許的主機(jī)、服務(wù),待校驗(yàn)無誤后再追加。
驗(yàn)收
用瀏覽器輸入nagios所在服務(wù)器的ip及目錄,如http://61.135.X..X/nagios,再輸驗(yàn)證所需的用戶名和密碼,就可點(diǎn)擊頁面右邊的相關(guān)連接來查看各種狀態(tài)。關(guān)掉某個被nagios監(jiān)控主機(jī)的服務(wù)或者拔掉某個服務(wù)器的網(wǎng)線,等幾分鐘,點(diǎn)擊超連接“Service Detail”觀察頁面狀態(tài)看是否有紅色的醒目的報警出現(xiàn)。

 一會兒,就會收到報警短信和報警郵件,然后在把測試所有的服務(wù)開啟或把拔下來的網(wǎng)線查上去,片刻后,網(wǎng)頁里的紅色報警表格消失,手機(jī)短信或郵件通知故障恢復(fù)。如果你的情況也這樣,那么真正大功告成。
Nagios的功能十分強(qiáng)大,在我的項(xiàng)目里,因?yàn)槲业男枨蟛煌M可能的簡化了nagios而沒有使用代理、多更多插件等功能,在一個不超過1000個服務(wù)器的網(wǎng)絡(luò)規(guī)模里,它工作得很好。如果有更多的服務(wù)器,建議使用mysql數(shù)據(jù)來管理監(jiān)控對象。在部署nagios的過程中,我多很多選項(xiàng)作了取舍,更詳細(xì)的情況請參照官方的文檔。

相關(guān)文章

最新評論