下载所需要的相关软件包,本文使用的nagiOS版本是3.4.3,nagios-plugins版本是2.2.1,nrpe版本是2.15。配置好yum源后即可开始下面的安装。一、安装相关软件包#y
下载所需要的相关软件包,本文使用的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
配置apache
在配置文件/etc/httpd/conf/httpd.conf中找到
DirectoryIndex index.html index.html.var
将其修改为:
DirectoryIndex index.html index.php
再在apache配置文件下增加如下内容:
AddType application/x-httpd-php .php
设置用户访问控制
#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
安装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
配置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如果正确启动说明安装成功
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=1host_perdata_command=process-host-perfdataservice_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/tcpnrpe 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)
在被监控主机安装Mysql-server
#yum -y install mysql-server#service mysqld restart
在被监控主机建立一个可远程连接的用户
mysql>create user 'nagios'@192.168.111.114 identified by '123';mysql>flush privileges;
监控主机安装mysql客户端程序
#yum -y install mysql
编写插件check_mysql
#!/bin/bashmysql_user=nagiosmysql_passWord=123mysql_host=192.168.111.114if mysql -h $mysql_host -u $mysql_user -p$mysql_password -e "show databases" &>/dev/null then echo "mysql:OK" exit 0else echo "mysql:DOWN" exit 2fi
修改脚本权限
chmod 755 check_mysql
修改/usr/local/nagios/etc/objects/command.cfg
define command{ command_name check_mysql command_line $USER1$/check_mysql}
修改/usr/local/nagios/etc/objects/localhost.cfg
define service{ .......... service_description mysql .......... check_command check_mysql ..........}
插件自定义结束
--结束END--
本文标题: Nagios+PNP安装部署
本文链接: https://lsjlt.com/news/245646.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0