570
中電雲集
nagios整合飛信機器人實現短信報警監控服務器
1.下載安裝包
apache2.2安裝包
https://www.xuningbo.com/wp-content/uploads/2011/12/httpd-2.2.21.tar.gz
fetion機器人程序:(這個是我整理過的,包含libACE程序在內,2011-12-9測試可用)
https://www.xuningbo.com/wp-content/uploads/2011/12/fx.zip
nagios主程序:(用的3.23中文版的,有技術水平的可以到官網下3.3英文版的)
https://www.xuningbo.com/wp-content/uploads/2011/12/nagios-cn-3.2.3.tar.bz2
nagios插件程序:
https://www.xuningbo.com/wp-content/uploads/2011/12/nagios-plugins-1.4.15.tar.gz
php程序:
https://www.xuningbo.com/wp-content/uploads/2011/12/php-5.3.8.tar.gz
2、軟件的安裝
首先安裝支持:
[root@localhost httpd-2.2.21]# yum -yinstall gcc gd*
(1) apache的安裝 [root@localhost httpd-2.2.21]# ./configure –prefix=/usr/local/apache –enable-so
[root@localhost httpd-2.2.21]# make && make install
grep -v “#” /usr/local/apache-2.2.15/bin/apachectl > /etc/init.d/apache
用vi編輯Apache服務控製腳本/etc/init.d/apache:
vi /etc/init.d/apache
在文件最前麵插入下麵的行,使其支持chkconfig命令:
#!/bin/sh
# chkconfig: 2345 85 15
# description: Apache is a World Wide Web server.
保存後退出vi編輯器,執行下麵的命令增加Apache服務控製腳本執行權限:
chmod +x /etc/init.d/apache
執行下麵的命令將Apache服務加入到係統服務:
chkconfig –add apache
執行下麵的命令檢查Apache服務是否已經生效:
chkconfig –list apache
命令輸出類似下麵的結果:
apache 0:off 1:off 2:on 3:on 4:on 5:on 6:off
表明apache服務已經生效,在2、3、4、5運行級別隨係統啟動而自動啟動,以後可以使用service命令控製Apache的啟動和停止。
(2) php的安裝
支持:yum -y install libxml*
[root@localhost php-5.2.10]# ./configure –prefix=/usr/local/php \
> –with-apxs2=/usr/local/apache/bin/apxs
[root@localhost php-5.2.10]# make && make install
[root@localhost php-5.2.10]# cp php.ini-dist /usr/local/lib/php.ini
[root@localhost php-5.2.10]# vi /usr/local/apache/conf/httpd.conf
為了配置文件的工整,在配置文件的相關地方加入如下配置:
LoadModule php5_module modules/libphp5.so(如果有,不用加)
AddType application/x-httpd-php .php .html
找到DirectoryIndex index.html
改為:DirectoryIndex index.php index.html
在最後加入nagios的訪問目錄:
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
<Directory “/usr/local/nagios/sbin”>
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Alias /nagios /usr/local/nagios/share
<Directory “/usr/local/nagios/share”>
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
如果重新啟動apache報如下錯誤:
httpd: Syntax error on line 53 of /usr/local/apache/conf/httpd.conf: Cannot load /usr/local/apache/modules/libphp5.so into server: /usr/local/apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied
原因:是Linux有一個SELinux保護模式引起的。
解決辦法:
關閉SELINUX的方法:
vi /etc/selinux/config 將SELINUX=enforcing 改成SELINUX=disabled 需要重啟
(3) nagios的安裝 為了支持Nagios安裝完後status map,trend等完全顯示,需要gd庫的支持,之前我已經提了,沒裝的裝下 [root@localhost nagios-cn-3.2.3]#useradd nagios[root@localhost nagios-cn-3.2.3]# ./configure –prefix=/usr/local/nagios \
> –with-gd-lib=/usr/lib –with-gd-inc=/usr/include –with-nagios-user=nagios \
> –with-nagios-group=nagios
[root@localhost nagios-cn-3.2.3]# make all
[root@localhost nagios-cn-3.2.3]# make install
[root@localhost nagios-cn-3.2.3]# make install-init
[root@localhost nagios-cn-3.2.3]# make install-commandmode
[root@localhost nagios-cn-3.2.3]#make install-config (4) nagios-plugin的安裝 [root@localhost nagios-plugins-1.4.15]# ./configure –prefix=/usr/local/nagios
[root@localhost nagios-plugins-1.4.15]# make && make install (5) 飛信機器人的安裝 [root@localhost fx]# cd fx [root@localhost fx]# mv libACE* libcrypto.so.* libssl.so.* /usr/lib [root@localhost fx]# cd .. [root@localhost xuningbo]# mv fx /usr/local/fetion [root@localhost xuningbo]# chmod -R 755 /usr/local/fetion [root@localhost xuningbo]# chown -R nagios:nagios /usr/local/fetion 測試飛信能否成功發送短信(發送對象需自己或者飛信好友): [root@localhost xuningbo]# /usr/local/fetion/fetion –mobile=159****** –pwd=***** –to=159**** –msg-utf8=”test” 注意:第一次使用提示: 鍥懼艦楠岃瘉鐮佸凡緇忕敓鎴愶紝鏂囦歡鍚嶄負:159****.jpg璿瘋瘑鍒悗杈撳靉鍥懼艦楠岃瘉鐮? 解決方式:將圖片下載到本地,打開 輸入圖中驗證碼即可,以後就不需要了 鎮ㄨ緭鍏ョ殑璿嗗埆鐮佹槸:hyxh
SIP-C/4.0 280 Send SMS OK
T: sip:338172353@fetion.com.cn;p=6142
I: 2
Q: 1 M
L: 115
D: Fri, 09 Dec 2011 07:05:13 GMT
XI: 2D50732F57C792E4616756574DD0F131 即發送成功。 3、nagios的配置 我隻用了一台監控與一台被監控,所以設置非常簡單 [root@localhost xuningbo]# cd /usr/local/nagios/etc/objects/ [root@localhost objects]# vi hosts.cfg define host{
host_name test
alias testhost02
max_check_attempts 5
contact_groups admins
address 61.164.*.*
}
define hostgroup{
hostgroup_name group
alias testgroup
members test
}define service{
host_name test
service_description PING
is_volatile 0
check_period 24×7
max_check_attempts 1
normal_check_interval 1
retry_check_interval 1
notification_options w,u,c,r
notification_interval 1
notification_period 24×7
check_command check_ping!100.0,20%!500.0,60%
}define service{
host_name test
service_description HTTP
is_volatile 0
check_period 24×7
max_check_attempts 1
normal_check_interval 1
retry_check_interval 1
notification_options w,u,c,r
notification_interval 1
notification_period 24×7
check_command check_http
notifications_enabled 0
}
[root@localhost objects]# vi contacts.cfg
define contact{
contact_name xuningbo ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
service_notification_commands notify-service-by-email,service-notify-by-fei
host_notification_commands notify-host-by-email,host-notify-by-fei
pager 159****
email xuningbo_0@126.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members xuningbo
}
(3) commands.cfg的編輯
為了支持飛信發短信的功能需要在此文件中添加飛信命令,以促使信息的發送,代碼如下:
# ‘notify-host-by-fei’ command definition
define command {
command_name host-notify-by-fei ;
command_line /usr/local/fetion/fetion –mobile=137*** –pwd=*** –to=$CONTACTPAGER$ –msg-utf8=”Host $HOSTSTATE$ alert for $HOSTNAME$! on ‘$LONGDATETIME$’” $CONTACTPAGER$
}
# ‘notify-service-by-fei’ command definition
define command {
command_name service-notify-by-fei
command_line /usr/local/fetion/fetion –mobile=137*** –pwd=*** –to=$CONTACTPAGER$ –msg-utf8=”$HOSTADDRESS$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ on $LONGDATETIME$” $CONTACTPAGER$
}
(4) 編輯nagios.cfg
為了使剛才編輯的文件生效,需加入一行:
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
[root@localhost etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 3.2.3
Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 10-03-2010
License: GPL
Website: https://www.nagios.org
Reading configuration data…
Read main config file okay…
Processing object config file ‘/usr/local/nagios/etc/objects/commands.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/contacts.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/timeperiods.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/templates.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/hosts.cfg’…
Read object config files okay…
Running pre-flight check on configuration data…
Checking services…
Checked 2 services.
Checking hosts…
Checked 1 hosts.
Checking host groups…
Checked 1 host groups.
Checking service groups…
Checked 0 service groups.
Checking contacts…
Checked 1 contacts.
Checking contact groups…
Checked 1 contact groups.
Checking service escalations…
Checked 0 service escalations.
Checking service dependencies…
Checked 0 service dependencies.
Checking host escalations…
Checked 0 host escalations.
Checking host dependencies…
Checked 0 host dependencies.
Checking commands…
Checked 26 commands.
Checking time periods…
Checked 5 time periods.
Checking for circular paths between hosts…
Checking for circular host and service dependencies…
Checking global event handlers…
Checking obsessive compulsive processor commands…
Checking misc settings…
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
檢查沒問題就可以測試了!
設置權限:
apache配置文件中改為
ScriptAlias /nagios/cgi-bin “/usr/local/nagios/sbin”
<Directory “/usr/local/nagios/sbin”>
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName “Nagios Access”
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Alias /nagios “/usr/local/nagios/share”
<Directory “/usr/local/nagios/share”>
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName “Nagios Access”
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
添加賬戶:
/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users admin
vi /usr/local/nagios/etc/cgi.cfg
authorized_for_system_information=test(你遠程登錄的賬號)
authorized_for_configuration_information=test(你遠程登錄的賬號)
authorized_for_system_commands=test(你遠程登錄的賬號)
authorized_for_all_services=test(你遠程登錄的賬號)
authorized_for_all_hosts=nagiosadmin,test(你遠程登錄的賬號)
authorized_for_all_service_commands=test(你遠程登錄的賬號)
authorized_for_all_host_commands=test(你遠程登錄的賬號)
最後更新:2017-01-04 22:34:35