Nagios+PNP安装部署-创新互联
下载所需要的相关软件包,本文使用的nagios版本是3.4.3,nagios-plugins版本是2.2.1,nrpe版本是2.15。配置好yum源后即可开始下面的安装。
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:国际域名空间、网页空间、营销软件、网站建设、青田网站维护、网站推广。一、安装相关软件包
#yum -y install gd fontconfig-devel libjpeg-devel libpng-devel gd-devel perl-GD openssl-devel php mailx postfix cpp gcc* libstdc++ glib2-devel libtoul-ltdl-devel httpd php*
二、创建nagios用户和组
#groupadd -g 6000 nagios #groupadd -g 6001 nagcmd #useradd -u 6000 -g nagios -G nagcmd nagios
三、编译安装nagios
#tar zxvf nagios-3.4.3.tar.gz #cd nagios #./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-user=nagios --with-command-group=nagcmd --enable-event-broker --enable-nanosleep --enable-embedded-perl --with-perlcache #make all #make install #make install-init #make install-commandmode #make install-webconf #make install-config
四、配置apache
1.配置apache
在配置文件/etc/httpd/conf/httpd.conf中找到
DirectoryIndex index.html index.html.var
将其修改为:
DirectoryIndex index.html index.php
再在apache配置文件下增加如下内容:
AddType application/x-httpd-php .php
2.设置用户访问控制
#htpasswd -cm /usr/local/nagios/etc/htpasswd.users nagiosadmin
五、权限设定与启动服务
#chown nagios:nagcmd /usr/local/nagios/etc/htpasswd.users #usermod -a -G nagios,nagcmd apache #service httpd restart
六、Nagios插件安装
#tar zxvf nagios-plugins-2.2.1.tar.gz #cd nagios-plugins-2.2.1 #./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios #make all #make install #chmod 755 /usr/local/nagios #chkconfig httpd on;chkconfig nagios on #/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
七、禁用selinux和iptables
#setenforce 0 #service iptables status
八、安装rrdtool工具
#yum -y install cairo-devel libxml2-devel pango-devel pango libpng-devel freetype freetype-devel libart_lgpl-devel zlib* cgilib* #tar zxvf rrdtool-1.4.5.tar.gz #cd rrdtool-1.4.5 #./configure --prefix=/usr/local/rrdtool #make && make install #/usr/local/rrdtool/bin/rrdtool -v
九、安装PNP
1.安装PNP
#tar zxvf pnp4nagios-0.6.14.tar.gz #cd pnp4nagios-0.6.14 #./configure --prefix=/usr/local/pnpnagios --with-nagios-user=nagios --with-nagios-group=nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool #make all #make install #make install-webconf #make install-config #make install-init
2.配置PNP
1)修改/usr/local/pnpnagios/etc下的配置文件
#cp misccommands.cfg-sample misccommands.cfg #cp nagios.cfg-sample nagios.cfg #cp rra.cfg-sample rra.cfg
2)修改/usr/local/pnpnagios/etc/pages下的配置文件
#cd /usr/local/pnpnagios/etc/pages #cp web_traffic.cfg-sample web_traffic.cfg
3)修改/usr /local/pnpnagios/etc/check_commands下的配置文件
#cd /etc/local/pnpnagios/etc/check_commands #cp check_all_local_disks.cfg-sample check_all_local_disks.cfg #cp check_nrpe.cfg-sample check_nrpe.cfg #cp check_nwstat.cfg-sample check_nwstat.cfg
然后service npcd start如果正确启动说明安装成功
3.nagios的配置
修改/usr/local/nagios/etc/objects/commands.cfg配置文件,修改如下:
修改/usr/local/nagios/etc/objects/templates.cfg,修改如下:
若需要开启日志调试功能,则修改/usr/local/pnpnagios/etc/process_perfdata.cfg配置文件
LOG_LEVEL = 0
将数字变更为2。这就开启了日志的调试功能
增加nagios数据输出设置,修改nagios主配置文件/usr/local/nagios/etc/nagios.cfg:
.................... process_performance_data=1 host_perdata_command=process-host-perfdata service_perfdata_command=process-service-perfdata ....................
修改/usr/local/nagios/etc/objects/localhost.cfg配置文件,修改如下:
.................... define host{ ................ use linux-server,hosts-pnp ................ } .................... define service{ use local-service,services-pnp host_name localhost service_description PING check_command check_ping!100.0,20%!500.0,60% } ....................
十、验证性能分析图标功能
重启ncpd,nagios,httpd服务,在浏览器输入http://192.168.111.105/nagios/。出现登录界面,用户名:nagiosadmin;密码:nagiosadmin。出现如下界面:
点击拆线小图标,出现如下界面:
监控远程主机,需要在被监控主机(192.168.111.114)上安装nrpe,安装过程如下:
#tar zxvf nrpe-2.15.tar.gz #cd nrpe-2.15 #./configure --prefix=/usr/local/nagios --enable-command-args #make all #make install-plugin #make install-daemon #make install-daemon-config #make install-xinetd
修改/etc/hosts配置文件,在文件内容最后加入以下两行:
nrpe 5666/tcp nrpe 5666/udp
修改/etc/xinetd.d/nrpe配置文件,原内容如下:
修改only_from后面的IP,改为监控主机的地址:
only_from = 192.168.111.105
启动xinetd服务,查看5666端口是否处于监听状态:
#netstat -anp|grep 5666
将被监控主机上的check_nrpe脚本传到监控主机上:
#scp /usr/local/nagios/libexec/check_nrpe root@192.168.111.105:/usr/local/nagios/libexec
监控主机操作如下:
#/usr/local/nagios/libexec/check_nrpe -H 192.168.111.114(测试被监控主机nrpe是否正常工作)
修改commands.cfg文件,增加如下内容:
定义新的被监控主机,修改localhost.cfg文件,增加如下内容:
检查nagios主配置文件是否配置正确,无问题后重启nagios服务:
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #service nagios restart
十一、扩展(自定义插件,如mysql)
1.在被监控主机安装mysql-server
#yum -y install mysql-server #service mysqld restart
2.在被监控主机建立一个可远程连接的用户
mysql>create user 'nagios'@192.168.111.114 identified by '123'; mysql>flush privileges;
3.监控主机安装mysql客户端程序
#yum -y install mysql
4.编写插件check_mysql
#!/bin/bash mysql_user=nagios mysql_password=123 mysql_host=192.168.111.114 if mysql -h $mysql_host -u $mysql_user -p$mysql_password -e "show databases" &>/dev/null then echo "mysql:OK" exit 0 else echo "mysql:DOWN" exit 2 fi
5.修改脚本权限
chmod 755 check_mysql
6.修改/usr/local/nagios/etc/objects/command.cfg
define command{ command_name check_mysql command_line $USER1$/check_mysql }
7.修改/usr/local/nagios/etc/objects/localhost.cfg
define service{ .......... service_description mysql .......... check_command check_mysql .......... }
插件自定义结束
文章名称:Nagios+PNP安装部署-创新互联
文章分享:http://cdiso.cn/article/ddicco.html