当前位置: > Linux服务器 > 监控工具 >

CentOS 5.7 64位系统中安装nagios监控服务

时间:2014-10-26 01:39来源:linux.it.net.cn 作者:it

系统版本:
CentOS release 5.7 x86_64

软件版本:
nagios-3.3.1.tar.gz,nagios-plugins-1.4.15.tar.gz,pnp4nagios-0.6.6.tar.gz,nrpe-2.13.tar.gz,check_openmanage-3.7.3.tar.gz,OM_6.2.0_ManNode_A00.tar.gz

软件说明:
pnp4nagios-0.6.6.tar.gz:基于rrdtool为nagios数据呈现连续的图表信息。
OM_6.2.0_ManNode_A00.tar.gz :检测dell服务器硬件状态,包括风扇转速,温度,电源电压等等所有硬件状态信息。可通过web方式查看。
check_openmanage-3.7.3.tar.gz:探测OMSA硬件状态信息,返回给nagios,在nagios上成像。

步骤1,安装nagios前的准备

下载nagios机器插件
 

wget http://cdnetworks-kr-2.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.3.1/nagios-3.3.1.tar.gz 
wget http://cdnetworks-kr-2.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz

配置sohu的yum安装源:
 

cd /etc/yum.repos.d/  
mv CentOS-Base.repo CentOS-Base.repo.bak  
wget http://mirrors.sohu.com/help/CentOS-Base-sohu.repo  
mv CentOS-Base-sohu.repo CentOS-Base.repo  
vim /etc/yum/pluginconf.d/fastestmirror.conf 

关闭fastestmirror,enable选项设置为0 
 

yum clean 
yum makecache 
yum update

yum安装LAMP环境:
 

yum -y install httpd php php-mysql mysql mysql-server php-snmp php-pdo perl-DBDMySQL

启动httpd
 

/etc/init.d/httpd start

设置开机启动apache
 

chkconfig --level 2345 httpd on 
chkconfig --list httpd

步骤2,安装nagios及其插件
添加nagios用户和用户组:
 

useradd nagios && passwd nagios 
groupadd nagcmd 
usermod -G nagcmd nagios

安装nagios及其插件:
 

tar xzvf nagios-3.3.1.tar.gz 
cd nagios 
./configure --with-nagios-user=nagios --with-nagiosgroup=nagcmd && make all && make install && make install-init && make install-config && make install-commandmode && make install-webconf 
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin//创建web界面管理员账户,需要创建密码。

vim /etc/init.d/nagios  //修改启动文件中的commandfile,启动时给full权限 
 

if [ -d $NagiosLockDir ]; then touch $NagiosLockDir/$NagiosLockFile; fi 
   echo " done." 
chmod 777 $NagiosCommandFile//添加此行代码 
exit 0 
/etc/init.d/nagios start 
/etc/init.d/httpd restart

安装nagios插件
 

tar -xzvf nagios-plugins-1.4.15.tar.gz 
cd nagios-plugins-1.4.15 
./configure --prefix=/usr/local/nagios/ && make && make install 
grep ^User /etc/httpd/conf/httpd.conf//查看apache用户 
User apache 
usermod -G nagcmd apache//将apache用户添加到nagcmd用户组中 
chown -R nagios:nagios /usr/local/nagios/ 
chmod 755 -R /usr/local/nagios/

步骤3,pnp4nagios 安装

下载pnp4nagios
 

wget http://cdnetworks-kr-1.dl.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.6.tar.gz

安装pnp4nagios
 

tar xzvf pnp4nagios-0.6.6.tar.gz 
yum -y install apr-devel apr-util check-devel cairo-devel pango-devel libxml2-devel rpmbuild glib2-devel dbus-devel freetype-devel fontconfig-devel gcc-c++ expat-devel python-devel libXrender-devel zlib libpng freetype libjpeg fontconfig gd libxml2 pcre pcre-devel libpcre libconfuse libart_lgpl-devel 
yum -y install ruby 
yum -y install libdbi

yum安装rrdtool,可能之前的yum源没有此文件包,所以需要配置一个新的yum源。
 

cd /etc/yum.repos.d/

vim dag.repo 
添加内容: 
 

  [dag] 
   name=Dag RPM Repository for Red Hat Enterprise Linux 
   baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag 
   gpgcheck=1 
   gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt 
   enabled=1 
 

保存退出 
 

mv CentOS-Base.repo CentOS-Base.repo.old 
yum install -y rrdtool perl-rrdtool rrdtool-devel 
cd /root/softwares/pnp4nagios-0.6.6 
./configure --with-nagios-user=nagios --with-nagios-group=nagcmd 
make all 
make install && make install-webconf && make install-config && make install-init

添加pnp4nagios的配置文件
 

cd /usr/local/pnp4nagios/etc/ 
mv misccommands.cfg-sample misccommands.cfg 
mv nagios.cfg-sample nagios.cfg 
mv npcd.cfg-sample npcd.cfg 
mv process_perfdata.cfg-sample process_perfdata.cfg 
mv rra.cfg-sample rra.cfg 
cd pages/ 
mv web_traffic.cfg-sample web_traffic.cfg 
cd ../check_commands 
mv check_all_local_disks.cfg-sample check_all_local_disks.cfg 
mv check_nrpe.cfg-sample check_nrpe.cfg 
mv check_nwstat.cfg-sample check_nwstat.cfg 
/etc/init.d/npcd restart //启动pnp4nagios

修改nagios配置文件
 

cd /usr/local/nagios/etc 
vim nagios.cfg 
#打开注释项: 
process_performance_data=1 
host_perfdata_command=process-host-perfdata 
service_perfdata_command=process-service-perfdata 
cd objects/

vim commands.cfg 
修改perfdata 标红的command_line 
 

# 'process-host-perfdata' command definition definecommand{ 
 command_nameprocess-host-perfdata 
 command_line/usr/local/pnp4nagios/libexec/process_perfdata.pl 
 } 
 # 'process-service-perfdata' command definition define command{ 
 command_nameprocess-service-perfdata 
 command_line/usr/local/pnp4nagios/libexec/process_perfdata.pl 
 }

修改templates.cfg文件。


vim templates.cfg //添加小太阳模版,镶嵌在nagios页面上 
 

 

##### 添加pnp4nagios的模板 ####### 
define host { 
   name host-pnp 
   action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_ 
   register 0 
   } 
 define service { 
 name srv-pnp 
 action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$ 
 register 0 
 }

遇到的问题:
一、访问nagios页面,点击图表显示图标,报错如下:
Kohana requires PHP 5.2 or newer.
说明我们安装的php版本过低,需要升级php
 
二、访问nagios页面,点击图表显示图标,报错如下:
解决办法:(与yum升级php相似)
找到php比较新的yum源,创建新的源,将原有的yum源先屏蔽掉,使用新源。

mv CentOS-Base.repo CentOS-Base.repo.old 
vim updatephp.repo 
添加如下内容 
 

[abrmblings] 
name=Jason's Utter Ramblings Repo 
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/ 
enabled=1 
gpgcheck=1 
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka 
yum update php -y 
yum install php*-gd

步骤4,安装nrpe和 OMSA,以及用nrpe检测OMSA

下载安装nrpe:
 

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz 
tar xzvf nrpe-2.13.tar.gz 
cd nrpe-2.13 
/configure && make all && make install-plugin && make install-daemon && make install-daemon-config 
ll /usr/local/nagios/ 
chown -R nagios:nagios /usr/local/nagios

添加nrpe检测OMSA配置文件:
 

mkdir -p /usr/local/nagios/etc/objects/Dell_OMSA 
cd /usr/local/nagios/etc/objects/Dell_OMSA/

vim dell_service_linux.cfg 
其中添加内容:
 

define service { 
 host_name web112 
 service_description check_omsa 
 use generic-service 
 check_command check_nrpe!check_omsa 
 _ser_info dell omsa 
 check_interval 10 
 notification_options c,r 
 }

vim /usr/local/nagios/etc/objects/localhost.cfg 
添加如下内容:
 

################ 自定义主机 ################## 
define host{ 
use linux-server,host-pnp 
host_name web112 
alias pnp4nagios 
address 192.168.144.112 
}

vi /usr/local/nagios/etc/nagios.cfg 
添加如下语句:
 

cfg_file=/usr/local/nagios/etc/objects/Dell_OMSA/dell_service_linux.cfg

vi /usr/local/nagios/etc/nrpe.cfg 
添加如下语句:
 

command[check_omsa]=/usr/local/nagios/libexec/check_openmanage -b ctrl_fw=ALL\/ctrl_driver=ALL -p

下载安装OMSA检测插件:
 

cd /root/softwares/ 
wget http://folk.uio.no/trondham/software/files/check_openmanage-3.7.3.tar.gz 
tar xzvf check_openmanage-3.7.3.tar.gz 
cp check_openmanage /usr/local/nagios/libexec/ 
ll /usr/local/nagios/libexec/check_openmanage 
chown -R nagios:nagios /usr/local/nagios/ 
ll /usr/local/nagios/libexec/check_openmanage 
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d 
/usr/local/nagios/libexec/check_nrpe -H localhost 
/etc/init.d/nagios restart 
/etc/init.d/npcd restart

被监控机器安装OMSA:
 

mkdir -p /usr/local/omsa 
cd /usr/local/omsa 
wget http://ftp.us.dell.com/sysman/OM_5.5.0_ManNode_A00.tar.gz 
 

vim  /etc/redhat-release   //在行末添加Tikanga 
 

CentOS release 5.6 (Final)Tikanga 
sh linux/supportscripts/srvadmin-install.sh -x  
linux/supportscripts/srvadmin-services.sh start

By default, OMSA web application runs on Port 1311 . Login to OMSA from web using the URL: https://{omsa-server-ip-address}:1311 using root as shown below. Please note that you can login only using HTTPS.

步骤5,邮件报警功能设置
vim /usr/local/nagios/etc/objects/contacts.cfg

在最后添加如下内容:
 

复制代码代码示例:
############# system administrators ############# 
define contact{ 
contact_name **** 
use generic-contact 
alias administrator01 
email 接受报警的邮箱01,例如:123456789@qq.com 

 
define contact{ 
contact_name **** 
use generic-contact 
alias administrator02 
email 接受报警的邮箱02 

  
define contact{ 
contact_name **** 
use generic-contact 
alias administrator03 
email 接受报警的邮箱03 

 
 define contact{ 
 contact_name **** 
 use generic-contact 
 alias administrator04 
 email 接受报警的邮箱04 

############# group of system administrators ########### 
define contactgroup{ 
contactgroup_name system-admins 
alias Nagios Administrators 
members 刚才定义的contact_name,成员与成员之间用逗号分割 
}

vim /usr/local/nagios/etc/objects/templates.cfg 
将contact_groups 选项的admins修改为system-admins
或通过sed命令直接替换:
 

sed 's/admins/system\-admins/g' /usr/local/nagios/etc/objects/templates.cfg 
 

要成功发送邮件,还要开启smtp服务,需要启用sendmail或者相似应用。
本文使用系统的sendmail。
 

/etc/init.d/sendmail start

发送测试邮件:
 

echo 'Hello,nagios.I'm your administrator!!!' | mail -s 'mail test' *******@qq.com 
 

如果邮件发送不成功,请检查tcp25端口是否在监听,并且查看防火墙设置是否放行25端口。

至此,nagios的监控功能初步完成。之后需要做的就是把被监控节点一个一个的加进来了。
也可以写个shell或perl脚本,批量添加主机进来。

(责任编辑:IT)
------分隔线----------------------------