此平台是基于apache2.2.1+php5.3.0+nagios3.1.2+fetion2009等软件的组合搭建而出,这些软件的版本是现阶段 最新的。本人经过一段时间的搭建与测试,各个功能都能够成功实现,现源于开源软件,本人却不敢独享,现把搭建与配置过程介绍如下:
一、服务器端的设置
1、下载需求软件:
nagios主程序:
nagios插件程序:
apache程序:
php程序:
libACE程序:
fetion机器人程序:
2、软件的安装
(1) apache的安装
[root@localhost httpd-2.2.11]# ./configure –prefix=/usr/local/apache –enable-so
[root@localhost httpd-2.2.11]# make && make install容
[root@localhost httpd-2.2.11]# make && make install容
(2) php的安装
[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请
> –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> 请输入内容
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> 请输入内容
(3) nagios的安装
为了支持Nagios安装完后status map,trend等完全显示,需要gd库的支持,首先看一下gd与gd-devel有没有安装








如果没有,请拿出光盘安装上,或者用yum -y install gd*安装也可









(4) nagios-plugin的安装


(5) 飞信机器人的安装
在安装飞信之前需要在/usr/lib目录下加上libACE库文件,以便使飞信能够正常使用


好了,现在来正式安装飞信




测试飞信能否成功发送短信(发送对象需是自己飞信好友):


如果136***能成功收到137***的短信就是正常的哟,如果不能成功看日志。
3、nagios的配置
首先讲一下,我建有host(主机),hostgroup(主机组),contact(联系人),contactgroup(联系人组),分别讲一下它们的相关情况:
host包含:TH-02,VH-178,VH-132,MH-110,MH-13
hostgroup包含:TG(别名:testgroup) , VG(别名:virtualgroup),MG(别名:maintaingroup);TG包括主机:TH-02,VG包括主机:VH-132,VH-178,MG包括主机:MH-110,MH-13
contact包含:WSP,HW,ZY
contactgroup包含:testers,virtualers,maintainers;testers包含用户:WSP,virtualers包含用户:WSP和HW,maintainers包含用户:ZY
为了直观起见,请看下图,

好了,有了大致模块以后,现在我们正式开始配置nagios吧
(1) host的编辑与添加
为了灵活使用,我们直接进入/usr/local/nagios/etc/objects目录下面,


##########################################################################
### Define whole host for all the machines


# Define testgroup host for the testers machine

define host{
host_name TH-02
alias testhost02
max_check_attempts 5
contact_groups testers
address 60.191.*.*
}


# Define virtualgroup host for the virtualers machine

define host{
host_name VH-178
alias Virutalhost178
max_check_attempts 5
contact_groups virtualers
address *.*.*.178
}

define host{
host_name VH-132
alias Virtualhost132
max_check_attempts 5
contact_groups virtualers
address *.*.*.132
}

# Define maintaingroup host for the maintainers machine

define host{
host_name MH-110
alias maintainhost110
max_check_attempts 5
contact_groups maintainers
address *.*.*.110
}

define host{
host_name MH-13
alias maintainhost13
max_check_attempts 5
contact_groups maintainers
address *.*.*.13
}

##############################################################################
### Define all hostgroup for the whole machine


# Define testgroup

define hostgroup{
hostgroup_name TG
alias testgroup
members TH-02
}

# Define virtualgroup

define hostgroup{
hostgroup_name VG
alias virtualgroup
members VH-178,VH-132
}

# Define maintaingroup

define hostgroup{
hostgroup_name MG
alias maintaingroup
members MH-110,MH-13
}

#############################################################################
### SERVICE DEFINITIONS


# Define a service to “ping” the whole machine

define service{
host_name TH-02,VH-178,VH-132,MH-110
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%

































































































}




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
}











service 可以根据自己的需要加的,我这里只对HTTP与PING来作阐述的。
(2) contacts.cfg的编辑
































































































(3) commands.cfg的编辑
为了支持飞信发短信的功能需要在此文件中添加飞信命令,以促使信息的发送,代码如下:











(4) 编辑nagios.cfg




(5) 编辑cgi.cfg
为了保证权限能正常访问nagios的web页面,需把这些行的值改掉:








服务器端的配置基本上大致如此了。
4、启动nagios与apache服务
(1) nagios自启动







(2) apache的启动



注:为了让apache可以自启动,可以加入到/etc/rc.local之中。
5、测试与浏览
在启动nagios服务之前,我们可以先测试一下是否配置有没有错误,或者你启动的时候出现错误也可以用下述命令进行测试















































呵呵,没有错误,可能您在配置之前或多或少会出现问题的,根据相关错误提示,逐一排查,相信您定会成功的。
现在我们打开nagios的web页面,输入:http://***.com/nagios样例
先看map页面,大致页面如下

再看hosts相关链接页面:

最后,我们再看一下hostgroups页面:

二、客户端的配置:
1、需求软件的下载:
nagios插件程序:
nrpe软件:
2、软件的安装
(1) nagios插件的安装:
首先在安装前建立nagios用户,命令如下:






(2) nrpe的程序的安装:







(3) 修改nrpe.cfg配置文件:





(4) 运行nrpe服务:

(5) 查看nrpe运行情况:

tcp 0 0 *.*.*.110:5666 0.0.0.0:* LISTEN 3538/nrpe

(6) 设置nrpe自启动:



(7) 在监控服务器端测试被监控服务器是否正常运行

测试如果一切正常,整个配置过程全部告一段落,只需到监控服务器中设置对被监控服务器的所需服务的监控即可。
这样一来,整个nagios的配置全部告一段落了,把被监控服务器的某个服务暂时停用一下,马上就会收到飞信的短消息了,一切表明,配置成功了。
本文出自 “↑山高海深↓——踏梦狼” 博客,请务必保留此出处http://tamenglang.blog.51cto.com/431396/183917
发表回复
要发表评论,您必须先登录。