nagios+cacti+npc(pass)
Nagios+cacti+npc2012.07.05
系统环境:Centos5.5(64位)+开发工具安装
所需软件:
cacti-0.8.7e.tar.gz
cacti-plugin-0.8.7e-PA-v2.6.zip
rrdtool-1.4.5.tar.gz
nagios-3.2.0.tar.gz
nagios-plugins-1.4.14.tar.gz
nagios-cn-3.2.0.tar.bz2
php-json-ext-1.2.1.tar.bz2
ndoutils-1.4b9.tar.gz
npc-2.0.4.tar.gz
下载地址:http://download.csdn.net/detail/w361031315/4412965
参考:下载后压缩包中的文档(Nagios+cacti+npc经典配置详解)
提示:此版本软件兼容性通过,其他版可能有问题。
安装所需环境:
# yum -y install php* mysql* httpd net-snmp-utils
# chkconfig mysqld on
# chkconfig httpd on
# service httpd start
# service mysqld start
更改mysql密码
# mysqladmin -uroot password "123456"
安装rrdtool
# ls
cacti-0.8.7e.tar.gz nagios-cn-3.2.0.tar.bz2 npc-2.0.4.tar.gz
cacti-plugin-0.8.7e-PA-v2.6.zipnagios-plugins-1.4.14.tar.gzphp-json-ext-1.2.1.tar.bz2
nagios-3.2.0.tar.gz ndoutils-1.4b9.tar.gz rrdtool-1.4.5.tar.gz
# ./configure --prefix=/usr/local ; make ; make install
(如果报错:configure: error: Please fix the library issues listed above and try again.
# yum -y install pango*后在安装)
Cacti安装
# tar zxvf cacti-0.8.7e.tar.gz
# mv cacti-0.8.7e /var/www/html/cacti
# chown -R root.root /var/www/html/cacti/
添加个用来读写监测数据的用户账号:runct,调整子目录rra/,log/的属主权限
# chown -R runct.runct /var/www/html/cacti/rra /var/www/html/cacti/log
导入cacti.sql,建立数据库、表结构
# mysql -uroot -p123456
mysql> create database cacti default character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on cacti.*tocactiuser@localhost identified by 'pwd123';
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
# mysql -ucactiuser -ppwd123 cacti < /var/www/html/cacti/cacti.sql
调整配置文件
# vi /var/www/html/cacti/include/config.php
30 $database_password = "pwd123";
cacti-plugins 插件安装
# unzip cacti-plugin-0.8.7e-PA-v2.6.zip
# cd /var/www/html/cacti/
# patch -p1 -N < /soft/cacti-plugin-arch/cacti-plugin-0.8.7e-PA-v2.6.diff
# mysql -ucactiuser -ppwd123 cacti < /soft/cacti-plugin-arch/pa.sql
# vi include/global.php
56 $config['url_path'] = '/cacti/';
建立任务调度
# su runct
$ crontab -e
$ crontab -l
*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php &> /dev/null
$ exit
Cacti 的 web 初始化
在浏览器输入 http://your ip address/cacti/ 登陆 cacti
http://blog.运维网.com/attachment/201207/205858398.png
Next
http://blog.运维网.com/attachment/201207/205959542.png
Next
http://blog.运维网.com/attachment/201207/210013927.png
Finish
帐号密码:admin,admin
第一次要改密码这里改为pwd123
http://blog.运维网.com/attachment/201207/210028663.png
如果不出图
http://blog.运维网.com/attachment/201207/210040806.png
修改settings-general rrdtool1.2.X 保存
http://blog.运维网.com/attachment/201207/210145967.png
好了,有图了
http://blog.运维网.com/attachment/201207/210159350.png
Nagios安装
准备帐号,目录
# cd /soft/
# useradd nagios
# mkdir /usr/local/nagios
# chown -R nagios.nagios /usr/local/nagios/
开始安装
# tar zxvf nagios-3.2.0.tar.gz
# cd nagios-3.2.0
# ./configure --prefix=/usr/local/nagios ;make all;make install;make install-init;make install-commandmode;make install-config;make install-webconf
修改nagios页面
# cp /etc/httpd/conf.d/nagios.conf /var/www/html/
生成 nagios 页面访问账号
# touch /usr/local/nagios/etc/htpasswd.users
# htpasswd -c /usr/local/nagios/etc/htpasswd.users admin
New password:
Re-type new password:
htpasswd: password verification error(2次输的不一样,在执行一次命令)
帐号:admin 密码:123
Nagios 的 CGI 配置文件
# vi /usr/local/nagios/etc/cgi.cfg(如下图)
# grep -v ^# /usr/local/nagios/etc/cgi.cfg |grep -v ^$
main_config_file=/usr/local/nagios/etc/nagios.cfg
physical_html_path=/usr/local/nagios/share
url_html_path=/nagios
show_context_help=0
use_pending_states=1
use_authentication=1
use_ssl_authentication=0
authorized_for_system_information=admin
authorized_for_configuration_information=admin
authorized_for_system_commands=admin
authorized_for_all_services=admin
authorized_for_all_hosts=admin
authorized_for_all_service_commands=admin
authorized_for_all_host_commands=admin
default_statusmap_layout=5
default_statuswrl_layout=4
ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$
refresh_rate=90
escape_html_tags=1
action_url_target=_blank
notes_url_target=_blank
lock_author_names=1
测试 nagios 是否成功
# service nagios start
Starting nagios: done.
# chkconfig nagios on
# service httpd restart
http://blog.运维网.com/attachment/201207/210221414.png
http://blog.运维网.com/attachment/201207/210236543.png
汉化(选做)
# cd /soft/
# tar jxvf nagios-cn-3.2.0.tar.bz2
# cd nagios-cn-3.2.0
# ./configure;make all;make install
# service httpd restart
http://blog.运维网.com/attachment/201207/210247865.png
nagios-plugins 插件安装
# cd /soft/
# tar zxvf nagios-plugins-1.4.14.tar.gz
# cd nagios-plugins-1.4.14
# ./configure --prefix=/usr/local/nagios ;make ;make install
插件装好,监控的localhost正常了
http://blog.运维网.com/attachment/201207/210259822.png
PHP 支持 JSON 扩展
# cd /soft/
# tar jxvf php-json-ext-1.2.1.tar.bz2
# cd php-json-ext-1.2.1
# phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20050922
Zend Extension Api No: 220051025
# ./configure ;make ;make install
# vi /etc/php.d/json.ini(新建)
extension=json.so
# vi /var/www/html/test.php
# service httpd restart
# service httpd restart
查看网页,出来json成功
http://blog.运维网.com/attachment/201207/205448110.png
ndoutils 安装
# cd /soft/
# tar zxvf ndoutils-1.4b9.tar.gz
#./configure --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql --enable-mysql --with-ndo2db-user=nagios --with-ndo2db-group=nagios
# make (不make install)
# cd src/
# cp ndomod-3x.o ndo2db-3x log2ndo file2sock /usr/bin
# cd ../config
# cp ndo2db.cfg-sample ndo2db.cfg
# cp ndomod.cfg-sample ndomod.cfg
# cp ndo2db.cfg ndomod.cfg /usr/local/nagios/etc/
# cd /usr/local/nagios/etc/
# vi ndo2db.cfg
102 db_name=cacti
111 db_prefix=npc_
120 db_user=cactiuser
121 db_pass=pwd123
163 debug_level=1
# vi /usr/local/nagios/etc/nagios.cfg
247 # Uncomment the line belowyou're running Nagios 3.x
248 broker_module=/usr/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg
NPC安装
# cd /soft/
# tar zxvf npc-2.0.4.tar.gz
# mv npc/ /var/www/html/cacti/plugins/
# vi /var/www/html/cacti/include/global.php
46 $plugins[] = 'npc';
NPC 界面设置
登陆cacti
http://blog.运维网.com/attachment/201207/205505194.png
找到UserManagement
http://blog.运维网.com/attachment/201207/205518844.png
进去把勾plugin Management勾上,保存
http://blog.运维网.com/attachment/201207/205531270.png
点 settings下面的plugin management ,在点INSTALL,然后enable
http://blog.运维网.com/attachment/201207/205547981.png
装好了
http://blog.运维网.com/attachment/201207/205601475.png
返回(console)菜单栏,点击 configuration-------settings----NPC,修改一下三个参数(如下图,cmd填写上就行,命令会自动生成)
http://blog.运维网.com/attachment/201207/205616743.png
点击NPC为OFF
http://blog.运维网.com/attachment/201207/205627160.png
启动ndo2db
# ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
# service nagios restart
# cat /var/log/messages
Jul5 17:30:27 localhost nagios: ndomod: Could not open data sink!I'll keep trying, but some output may get lost...
Jul5 17:30:27 localhost nagios: Event broker module '/usr/bin/ndomod-3x.o' initialized successfully.
Jul5 17:30:27 localhost nagios: Finished daemonizing... (New PID=12009)
第一行报错:是因为没给ndo2db文件权限
#chown nagios.nagios /usr/local/nagios/etc/ndo*
# service nagios restart
# cat /var/log/messages
Jul5 17:37:46 localhost ndo2db-3x: mysql_error: 'Unknown column 'long_output' in 'field list''
这次是,数据库有问题
# mysql -ucactiuser -ppwd123
mysql> use cacti;
alter table npc_eventhandlers add long_output TEXT NOT NULL default '' after output;
alter table npc_hostchecks add long_output TEXT NOT NULL default '' after output;
alter table npc_hoststatus add long_output TEXT NOT NULL default '' after output;
alter table npc_notifications add long_output TEXT NOT NULL default '' after output;
alter table npc_servicechecks add long_output TEXT NOT NULL default '' after output;
alter table npc_servicestatus add long_output TEXT NOT NULL default '' after output;
alter table npc_statehistory add long_output TEXT NOT NULL default '' after output;
alter table npc_systemcommands add long_output TEXT NOT NULL default '' after output;
执行这些语句,在重启nagios
# service nagios restart
# cat /var/log/messages
Jul5 17:40:52 localhost nagios: ndomod: Successfully connected to data sink.0 queued items to flush.
Jul5 17:40:52 localhost nagios: Event broker module '/usr/bin/ndomod-3x.o' initialized successfully.
Jul5 17:40:52 localhost nagios: Finished daemonizing... (New PID=12381)
Ndo2db启动成功,现在就可以看到NPC的数据了。
http://blog.运维网.com/attachment/201207/205651265.png
页:
[1]