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

发布时间:2020-06-09编辑:脚本学堂
本文介绍下,在centos 5.7 64位系统中,安装nagios监控服务的方法,并就一些问题给出了解决办法。有需要的朋友,参考下吧。

系统版本:
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文件。