cacti+nagios 整合企业级监控平台(三)

运维监控   npc集成nagios  

上一篇:cacti+nagios 整合企业级监控平台(二)

五、利用npc插件集成nagios到cacti
  • 安装 apache 服务
    yum install httpd httpd-devel php php-common php-pdo php-gd php-devel php-mysql php-mbstring php-cli libjpeg libjpeg-devel gd gd-devel zlib zlib-devel

  • nagios中文版安装(nagios-cn-3.2.3.tar.bz2)

grep -w "^nagios:" /etc/passwd &> /dev/null || useradd  nagios    #添加nagios用户  
tar zxvf  nagios-cn-3.2.3.tar.bz2  
./configure --prefix=/usr/local/nagios LDFLAGS=-L/usr/local/mysql/lib --enable-mysql --with-ndo2db-user=nagios --with-ndo2db-group=nagios --with-mysql-lib=/usr/local/mysql/lib --with-mysql-inc=/usr/local/mysql/include
make all  
make install  
make install-init  
make install-config  
make install-commandmode  
make install-webconf                    #自动生成了apache配置文件/etc/httpd/conf.d/nagios.conf  
sed -i 's/Listen 80/Listen 8080/g' /etc/httpd/conf/httpd.conf #因为nginx占用了80所以修改为8080  
service httpd restart  
  • 安装NRPE服务
tar zxvf nrpe-2.12.tar.gz  
cd nrpe-2.12  
./configure --prefix=/usr/local/nagios  
make all  
make install-plugin  
make install-daemon  
make install-daemon-config  
make install-xinetd  
> /usr/local/nagios/etc/nrpe.cfg              #生成配置文件
cat >> /usr/local/nagios/etc/nrpe.cfg << EOF  
log_facility=daemon  
pid_file=/var/run/nrpe.pid  
server_port=5666  
nrpe_user=nagios  
nrpe_group=nagios  
allowed_hosts=127.0.0.1                       #nagios_client配置允许服务端的IP  
dont_blame_nrpe=1  
debug=0  
command_timeout=60  
connection_timeout=300  
command[check_users]=/usr/local/nagios/libexec/check_users -w 10 -c 20  
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20  
command[check_data]=/usr/local/nagios/libexec/check_disk -w 10% -c 5% -p /data  
command[check_root]=/usr/local/nagios/libexec/check_disk -w 10% -c 5% -p /  
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z  
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 450 -c 500  
command[check_game]=/usr/local/nagios/libexec/check_tcp -p 8080 -w 10 -c 20  
command[check_local_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%  
command[check_ping]=/usr/local/nagios/libexec/check_ping -H localhost -w 200,20% -c 300,50% -p 3 -t 2  
command[check_http]=/usr/local/nagios/libexec/check_http localhost -p 80 -w 10 -c 20  
EOF  
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d         #后台启动
  • 测试Nrpe是否能正常工作
    /usr/local/nagios/libexec/check_nrpe -H localhost

  • 安装NDoutils
    NDoutils是把Nagios的数据写到mysql里的插件,这个是集成的关键。下载地址

tar zxf ndoutils-1.4b7.tar.gz  
cd ndoutils-1.4b7  
./configure --prefix=/usr/local/nagios LDFLAGS=-L/usr/local/mysql/lib --enable-mysql --with-ndo2db-user=nagios --with-ndo2db-group=nagios --with-mysql-lib=/usr/local/mysql/lib --with-mysql-inc=/usr/local/mysql/include 
make  
  • 然后直接把我们想要的程序及配置文件复制到nagios中就可以
cd src  
cp ndomod-3x.o ndo2db-3x log2ndo file2sock /usr/local/nagios/bin  
cd ../config  
cp ndomod.cfg ndo2db.cfg /usr/local/nagios/etc/  
  • 配置文件修改
    vi /usr/local/nagios/etc/ndo2db.cfg
lock_file=/usr/local/nagios/var/ndo2db.lock  
ndo2db_user=nagios  
ndo2db_group=nagios  
socket_type=unix  
socket_name=/usr/local/nagios/var/ndo.sock  
tcp_port=5668                            #监听端口  
use_ssl=0  
db_servertype=mysql  
db_host=127.0.0.1                        #数据库地址  
db_port=3306  
db_name=cacti                            #库名  
db_prefix=npc_  
db_user=cacti                            #数据库用户名同cacti  
db_pass=******                           #数据库密码  
max_timedevents_age=1440  
max_systemcommands_age=10080  
max_servicechecks_age=10080  
max_hostchecks_age=10080  
max_eventhandlers_age=44640  
max_externalcommands_age=44640  
max_notifications_age=44640  
max_contactnotifications=44640  
max_contactnotificationmethods=44640  
max_logentries_age=129600  
max_acknowledgements_age=44640  
debug_level=0  
debug_verbosity=1  
debug_file=/usr/local/nagios/var/ndo2db.debug  
max_debug_file_size=1000000  

vi /usr/local/nagios/etc/nagios.cfg

更改
check_external_commands = 1  
command_check_interval = -1  
event_broker_options = -1  
添加
broker_module = /usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg  
  • 重新启动NDoutils和Nagios
    /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg
    service nagios restart
    chkconfig nagios on
  • 登陆cacti 设置npc

  • 刷新npc SQL

mysql -uroot -p  
use cacti;  
ALTER TABLE `npc_hostchecks` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;  
ALTER TABLE `npc_hoststatus` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;  
ALTER TABLE `npc_servicechecks` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;  
ALTER TABLE `npc_servicestatus` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;  
ALTER TABLE `npc_statehistory` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;  
ALTER TABLE `npc_eventhandlers` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;  
ALTER TABLE `npc_systemcommands` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;  
ALTER TABLE `npc_notifications` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;  
exit;  
  • 查看npc页面,是否整合成功