http://carywu.blog.51cto.com/13185/152040
同志們啊,真是久違了啊,老久沒來更新俺的部落格了,實在是這段時間老忙了,不忙的時候又老沒興趣寫這玩意。
這段時間抽空整理了下公司所有的伺服器,安裝了個nagios監控伺服器,把公司的幾十台linux伺服器和幾台郵件伺服器,檔案伺服器,路由器,交換機,vpn都監控了下來,再設定了下報警短信,讓手機24小時都能收到出問題的報警資訊。哎呀......突然發覺我沒事情做了!!
nagios伺服器的安裝俺就不羅嗦了,網上很多非常詳細的教程,真的幸苦這些大俠們,讓我節省了賊多的研究時間,直接把精力放在後期的優化配置上了。在此,偶也不敢獨享,供出來讓大家參考,哥們先抛個磚頭,有玉的都抛回來。
先說報警短信吧。俺為了省錢,用的是移動的139郵箱,這郵箱有自動短信轉發功能,會把郵件轉到你的手機上。本來我想用個包月付費形式的,可惜手機太爛(西門子6688),不支援這個功能。就用了個免費的限制70個字的功能。勉強度過了。
因為字數的限制,我就修改了下nagios配置檔案,新添加了個notify-host-by-phone 和 notify-service-by-phone的指令:
define command{
command_name notify-host-by-phone
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "$NOTIFICATIONTYPE$:$HOSTNAME$:$HOSTSTATE$" $CONTACTEMAIL$
}
command_name notify-service-by-phone
command_line /usr/bin/printf "%b" "$NOTIFICATIONTYPE$:Service: $SERVICEDESC$\nHost: $HOSTALIAS$:State: $SERVICESTATE$:$SERVICEOUTPUT$" | /bin/mail -s "H:$HOSTALIAS$:$SERVICESTATE$:$SERVICEOUTPUT$" $CONTACTEMAIL$
然後再在contacts.cfg中新添加了個手機的聯系人,将此聯系人添加到相應的聯系人組内。如此這般,系統就會發送報警到這個郵箱,然後這個郵箱再轉發到手機。
define contact{
contact_name carywu
alias sys admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-phone
host_notification_commands notify-host-by-phone
email [email protected]
}
###OK,以上是報警短信設定,非常簡單####
###下面再來介紹下監控DELL Openmanage服務的安裝過程#####
由于很多公司的伺服器都是DELL的伺服器,DELL的openmanage軟體确實不錯,可以監控伺服器的硬碟,記憶體,電源等運作狀态。通過網頁就能一覽無遺,而且還支援SNMP協定。是以,我們可以通過nagios插件來監控這個服務。
首先要做的是将DELL Openmanage軟體包安裝到伺服器上,這個我就不說了。有一個需要說明的就是還得把SNMP軟體包安裝上。
#打開添加與删除程式,添加元件:選擇simple Network Management Protocol服務。

##安裝好後,再在運作裡輸入services.msc,打開服務清單,選擇SNMP services,修改安全設定:
####OK,DELL伺服器端設定完畢######
####以下開始nagios伺服器的配置了#####
1:從nagiosexchange網站下載下傳高手寫好的插件程式,我貼出URL:
[url]http://www.nagiosexchange.org/cgi-bin/jump.cgi?ID=1437&view=File1;d=1[/url]
2:将這個檔案copy到/usr/local/nagios/libexec目錄下(我安裝的nagios在此目錄),改名為: check_dell_openmanage.pl
我們來看下它的用法:
Usage: ./check_dell_openmanage.pl [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd) [-P <port>] -T test|dellom|dellom_storage|blade|global|chassis|custom [-f] [-t <timeout>] [-V] [-u <unknown_default>]
-v, --verbose #顯示是否NET:SNMP正常
print extra debugging information
-h, --help
print this help message
-H, --hostname=HOST #DELL伺服器IP/hostname
name or IP address of host to check
-C, --community=COMMUNITY NAME #就是前面設定的community
community name for the host's SNMP agent (implies v 1 protocol)
-2, --v2c
use SNMP v2 (instead of SNMP v1)
-P, --port=PORT
SNMPd port (Default 161)
-t, --timeout=INTEGER
timeout for SNMP in seconds (Default: 5)
-V, --version
prints version number
-u, --unknown_default=INT
If attribute is not found then report the output as this number (i.e. -u 0)
-T, --type=test|dellom|dellom_storage|blade|global|chassis|custom
This allows to use pre-defined system type
Currently support systems types are:
test (tries all OID's in verbose mode can be used to generate new system type)
dellom (Dell OpenManage general detailed)
dellom_storage (Dell OpenManage plus Storage Management detailed)
blade (some features are on the chassis not the blade)
global (only check the global health status)
chassis (only check the system chassis health status)
custom (intended for customization)
3: 首先确認下你的nagios伺服器上是否安裝好perl NET:SNMP軟體包,如果你沒安裝,沒關系,我已經幫你搞到這些軟體了,我的伺服器系統是RHEL 4,如果你的和我不同,那請自己去網上搜去吧。
相關軟體:(由于安裝NET-SNMP會牽出一系列依賴包,俺一并列出來算了。有遺漏的請自己去搜吧)
#####相關軟體下載下傳URL#######
NET:SNMP
[url]http://rpmforge.sw.be/redhat/el4/en/i386/rpmforge/RPMS/perl-Net-SNMP-5.2.0-1.2.el4.rf.noarch.rpm[/url]
CRYPT:DES (依賴包)
[url]http://rpmforge.sw.be/redhat/el4/en/i386/rpmforge/RPMS/perl-Crypt-DES-2.05-3.2.el4.rf.i386.rpm[/url]
PERL(socket6)
[url]http://rpmforge.sw.be/redhat/el4/en/i386/rpmforge/RPMS/perl-Socket6-0.20-1.el4.rf.i386.rpm[/url]
PERL(Digest:HMAC)
[url]ftp://ftp.muug.mb.ca/mirror/fedoralegacy/fedora/3/os/i386/perl-Digest-HMAC-1.01-13.noarch.rpm[/url]
PERL(Digest:SHA1)
[url]http://whiteboxlinux.osmirror.nl/4/en/os/i386/WhiteBox/RPMS/perl-Digest-SHA1-2.07-5.i386.rpm[/url]
#####結束軟體下載下傳######
4:編輯/usr/local/nagios/etc/object/commands.cfg檔案,添加以下新的指令:
command_name check_dell_open_manage
command_line $USER1$/check_dell_openmanage.pl -H $HOSTADDRESS$ -C $ARG1$ -T $ARG2$
}
5:建立立個cfg檔案,添加你需要監控的主機及相關的服務。注意,這個新添加的.cfg檔案需要在nagios.cfg檔案中注冊。比如我添加的名字為checkopenmanage.cfg檔案,存在objects目錄中,需要在nagios.cfg中添加一條:cfg_file=/usr/local/nagios/etc/objects/checkopenmanage.cfg
define service{
use generic-service
host_name XXXXXXXX #DELL伺服器定義名
service_description Dell OpenManage Status
check_command check_dell_open_manage!mailsrv!dellom
normal_check_interval 3
retry_check_interval 1
use generic-service
host_name XXXXXXXX #DELL伺服器定義名
service_description Dell OpenManage Status plus Storage
check_command check_dell_open_manage!mailsrv!dellom_storage
6:看看結果吧!!!
#####以上就是偶舉的兩個例子了,一個是報警短信,一個是安裝監控插件。