搭建nagios+centreon分布式
1 测试
server端保持不变,增加了一台代理服务器及客户端节点。
server:172.25.128.35
proxy:172.25.128.40 (节点)
client:test
#拷贝前面实验的nagios客户端程序,修改allowed_hosts为192.168.128.39
2 proxy端 (直接从server拷贝)
2.1 修改
安装服务,需要安装nagios、nagios-plugins、nrpe、ndoutils,安装过程与server端完全一样。
安装完后后从server端拷贝一个脚本文件到proxy:
[root@centreon libexec]#scp
process-service-perfdata 192.168.128.39:/usr/local/nagios/libexec/
启动服务:
[root@localhost ~]#/etc/init.d/nagios start
[root@localhost ~]#/etc/init.d/ndo2db start
[root@localhost
~]#/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
3 server端与proxy的nagios用户间建立ssh互信,因为server端通过web添加完配置之后,需要通过ssh将配置发送到proxy端。
[root@centreon ~]# su nagios
[nagios@centreon root]$cd
[nagios@centreon ~]$ ssh-keygen
[nagios@centreon ~]$ ssh-copy-id -i
~/.ssh/id_rsa.pub 192.168.128.39
[nagios@centreon ~]$ ssh
192.168.128.39 #测试无密码登陆
4 web页面配置
1) 添加poller,配置-》Centreon -》增加(可以复制Central再修改)
Poller Name:idc_bj
输出填写proxy端IP

2) 添加poller的ndomod.cfg文件,配置-》Centreon-》ndomod.cfg -》增加
实例名称:idc_bj
输出填写server端IP:192.168.128.21

3) 添加poller的ndomod.cfg文件,配置-》Centreon-》ndo2db.cfg -》增加
修改数据库选项:用户名和密码是给proxy开通的用户,需在mysql中授权
4)添加poller的nagios.cfg文件
4、 添加proxy到server端数据库访问权限
mysql> grant all privileges ON centstatus.* to
centreon@'129.168.128.39' identified by 'centreon';
mysql> flush privileges;
5、 proxy服务器添加nagios用户相关命令的sudo权限
[root@localhost ~]# vi /etc/sudoers
nagios ALL=NOPASSWD:
/etc/init.d/nagios restart
nagios ALL=NOPASSWD:
/etc/init.d/nagios stop
nagios ALL=NOPASSWD:
/etc/init.d/nagios start
nagios ALL=NOPASSWD:
/etc/init.d/nagios reload
nagios ALL=NOPASSWD:
/usr/sbin/nagiostats
nagios
ALL=NOPASSWD: /usr/sbin/nagios *
修改完成后可以在server的nagios用户下执行ssh sudo 命令:
[nagios@centreon ~]$ ssh 192.168.128.39
sudo /etc/init.d/nagios restart
如果报以下错:
sudo: sorry, you must have a tty to run
sudo
解决方法:注释/etc/sudoers中 ‘Defaults requiretty’
6、 添加proxy后端主机:配置-》主机-》添加
与以前的添加主机过程一样,“监控自”选择idc_bj:
保存后自动生成服务
导出nagios配置后查看监控页面
如果app节点为非运行状态,可以尝试如下方法:
/usr/local/nagios/etc 下的配置文件web端重启后无法更新。
因为是原来的配置文件,所以把原来的配置文件删除一次既可。
[root@nagios_app1]# cd /usr/loca/nagios/etc
[root@nagios_app1 etc]# ll
total 168
-rw-r--r-- 1 centreon centreon 1806 Jun 4 14:42 centreon.conf
-rw-rw-r-- 1 nagios nagios 1827 Jun 4 14:42 cgi.cfg
-rwxrwxr-x 1 nagios nagios 1825 Jun 2 19:05 cgi.cfg~
-rw-rw-r-- 1 apache apache 11357 Jun 4 09:49 checkcommands.cfg
-rw-rw-r-- 1 apache apache 1089 Jun 4 09:49 connectors.cfg
-rw-rw-r-- 1 apache apache 1383 Jun 4 09:49 contactgroups.cfg
-rw-rw-r-- 1 apache apache 2744 Jun 4 09:49 contacts.cfg
-rw-rw-r-- 1 apache apache 1509 Jun 4 09:49 contactTemplates.cfg
-rw-rw-r-- 1 apache apache 1089 Jun 4 09:49 dependencies.cfg
-rw-rw-r-- 1 apache apache 1089 Jun 4 09:49 escalations.cfg
-rw-rw-r-- 1 apache apache 1211 Jun 4 09:49 hostgroups.cfg
-rw-rw-r-- 1 apache apache 1575 Jun 4 09:49 hosts.cfg
-rw-rw-r-- 1 apache apache 2949 Jun 4 09:49 hostTemplates.cfg
-rw-r--r-- 1 root root 26 Jun 3 14:32 htpasswd.users
-rw-rw-r-- 1 apache apache 1573 Jun 4 09:49 meta_commands.cfg
-rw-rw-r-- 1 apache apache 1089 Jun 4 09:49 meta_contact.cfg
-rw-rw-r-- 1 apache apache 1089 Jun 4 09:49 meta_contactgroup.cfg
-rw-rw-r-- 1 apache apache 1089 Jun 4 09:49 meta_dependencies.cfg
-rw-rw-r-- 1 apache apache 1089 Jun 4 09:49 meta_escalations.cfg
-rw-rw-r-- 1 apache apache 1089 Jun 4 09:49 meta_host.cfg
-rw-rw-r-- 1 apache apache 1089 Jun 4 09:49 meta_hostgroup.cfg
-rw-rw-r-- 1 apache apache 1089 Jun 4 09:49 meta_services.cfg
-rw-rw-r-- 1 apache apache 1341 Jun 4 09:49 meta_timeperiod.cfg
-rw-rw-r-- 1 apache apache 3779 Jun 4 09:49 misccommands.cfg
-rw-rw-r-- 1 nagios nagios 3718 Jun 4 14:42 nagios.cfg
-rwxrwxr-x 1 nagios nagios 4146 Jun 2 19:05 nagios.cfg~
-rw-rw-r-- 1 centreon centreon 3019 Jun 4 14:42 nagiosCFG.DEBUG
-rw-rw-r-- 1 apache apache 1448 Jun 4 09:49 ndo2db.cfg
-rw-rw-r-- 1 apache apache 1351 Jun 4 09:49 ndomod.cfg
-rw-r--r-- 1 nagios nagios 8002 Jun 3 23:04 nrpe.cfg
drwxrwxr-x 2 nagios nagios 4096 Jun 2 19:07 objects
-rw-rw---- 1 nagios nagios 1158 Jun 4 14:42 resource.cfg
-rwxrwxr-x 1 nagios nagios 1158 Jun 2 19:05 resource.cfg~
-rw-rw-r-- 1 apache apache 1089 Jun 4 09:49 servicegroups.cfg
-rw-rw-r-- 1 apache apache 2271 Jun 4 09:49 services.cfg
-rw-rw-r-- 1 apache apache 5799 Jun 4 09:49 serviceTemplates.cfg
-rw-rw-r-- 1 apache apache 2138 Jun 4 09:49 timeperiods.cfg
[root@nagios_app1 etc]# rm -rf *.cfg
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29500582/viewspace-1249197/
,如需转载,请注明出处,否则将追究法律责任。