设为首页 收藏本站
查看: 1287|回复: 0

[经验分享] nagios+cacti+npc(pass)

[复制链接]

尚未签到

发表于 2019-1-11 09:46:40 | 显示全部楼层 |阅读模式
Nagios+cacti+npc
                                                                                                                           2012.07.05
系统环境:Centos5.564位)+开发工具安装
所需软件:
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经典配置详解)
提示:此版本软件兼容性通过,其他版可能有问题。
安装所需环境:
[root@localhost ~]# yum -y install php* mysql* httpd net-snmp-utils
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# chkconfig httpd on
[root@localhost ~]# service httpd start
[root@localhost ~]# service mysqld start
更改mysql密码
[root@localhost ~]# mysqladmin -uroot password "123456"
安装rrdtool
[root@localhost soft]# 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.zip  nagios-plugins-1.4.14.tar.gz  php-json-ext-1.2.1.tar.bz2
nagios-3.2.0.tar.gz              ndoutils-1.4b9.tar.gz         rrdtool-1.4.5.tar.gz
[root@localhost rrdtool-1.4.5]# ./configure --prefix=/usr/local ; make ; make install
(如果报错:configure: error: Please fix the library issues listed above and try again.
[root@localhost rrdtool-1.4.5]# yum -y install pango*后在安装)
Cacti安装
[root@localhost soft]# tar zxvf cacti-0.8.7e.tar.gz
[root@localhost soft]# mv cacti-0.8.7e /var/www/html/cacti
[root@localhost soft]# chown -R root.root /var/www/html/cacti/
添加个用来读写监测数据的用户账号:runct,调整子目录rra/,log/的属主权限
[root@localhost soft]# chown -R runct.runct /var/www/html/cacti/rra /var/www/html/cacti/log
导入cacti.sql,建立数据库、表结构
[root@localhost soft]# mysql -uroot -p123456
mysql> create database cacti default character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on cacti.*  to  cactiuser@localhost identified by 'pwd123';
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye

[root@localhost soft]# mysql -ucactiuser -ppwd123 cacti < /var/www/html/cacti/cacti.sql
调整配置文件
[root@localhost soft]# vi /var/www/html/cacti/include/config.php
30 $database_password = &quot;pwd123&quot;;

cacti-plugins 插件安装  
[root@localhost soft]# unzip cacti-plugin-0.8.7e-PA-v2.6.zip
[root@localhost soft]# cd /var/www/html/cacti/
[root@localhost cacti]# patch -p1 -N < /soft/cacti-plugin-arch/cacti-plugin-0.8.7e-PA-v2.6.diff
[root@localhost cacti]# mysql -ucactiuser -ppwd123 cacti < /soft/cacti-plugin-arch/pa.sql
[root@localhost cacti]# vi include/global.php
     56 $config['url_path'] = '/cacti/';                                                

建立任务调度
[root@localhost cacti]# su runct
[runct@localhost cacti]$ crontab -e
[runct@localhost cacti]$ crontab -l
*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php &> /dev/null

[runct@localhost cacti]$ exit
Cacti web 初始化
在浏览器输入 http://your ip address/cacti/    登陆 cacti


Next


Next


Finish
帐号密码:adminadmin
第一次要改密码  这里改为pwd123


如果不出图


修改settings-general rrdtool1.2.X 保存


好了,有图了


Nagios安装
准备帐号,目录
[root@localhost cacti]# cd /soft/
[root@localhost soft]# useradd nagios
[root@localhost soft]# mkdir /usr/local/nagios
[root@localhost soft]# chown -R nagios.nagios /usr/local/nagios/
开始安装
[root@localhost soft]# tar zxvf nagios-3.2.0.tar.gz
[root@localhost soft]# cd nagios-3.2.0
[root@localhost 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页面
[root@localhost nagios-3.2.0]# cp /etc/httpd/conf.d/nagios.conf /var/www/html/
生成 nagios 页面访问账号
[root@localhost nagios-3.2.0]# touch /usr/local/nagios/etc/htpasswd.users
[root@localhost nagios-3.2.0]# htpasswd -c /usr/local/nagios/etc/htpasswd.users admin
New password:
Re-type new password:
htpasswd: password verification error2次输的不一样,在执行一次命令)

帐号:admin                   密码:123
Nagios CGI 配置文件
[root@localhost nagios-3.2.0]# vi /usr/local/nagios/etc/cgi.cfg(如下图)
[root@localhost nagios-3.2.0]# 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 是否成功
[root@localhost nagios-3.2.0]# service nagios start
Starting nagios: done.
[root@localhost nagios-3.2.0]# chkconfig nagios on
[root@localhost nagios-3.2.0]# service httpd restart




汉化(选做)
[root@localhost nagios-3.2.0]# cd /soft/
[root@localhost soft]# tar jxvf nagios-cn-3.2.0.tar.bz2
[root@localhost soft]# cd nagios-cn-3.2.0
[root@localhost nagios-cn-3.2.0]# ./configure;make all;make install
[root@localhost nagios-cn-3.2.0]# service httpd restart


nagios-plugins 插件安装
[root@localhost nagios-cn-3.2.0]# cd /soft/
[root@localhost soft]# tar zxvf nagios-plugins-1.4.14.tar.gz
[root@localhost soft]# cd nagios-plugins-1.4.14
[root@localhost nagios-plugins-1.4.14]# ./configure --prefix=/usr/local/nagios ;make ;make install
插件装好,监控的localhost正常了


PHP 支持 JSON 扩展
[root@localhost nagios-plugins-1.4.14]# cd /soft/
[root@localhost soft]# tar jxvf php-json-ext-1.2.1.tar.bz2
[root@localhost soft]# cd php-json-ext-1.2.1
[root@localhost php-json-ext-1.2.1]# phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20050922
Zend Extension Api No:   220051025
[root@localhost php-json-ext-1.2.1]# ./configure ;make ;make install
[root@localhost php-json-ext-1.2.1]# vi /etc/php.d/json.ini(新建)
extension=json.so                                                               

[root@localhost php-json-ext-1.2.1]# vi /var/www/html/test.php



[root@localhost php-json-ext-1.2.1]# service httpd restart

[root@localhost php-json-ext-1.2.1]# service httpd restart
查看网页,出来json成功


ndoutils 安装
[root@localhost php-json-ext-1.2.1]# cd /soft/
[root@localhost soft]# tar zxvf ndoutils-1.4b9.tar.gz
[root@localhost ndoutils-1.4b9]#./configure --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql --enable-mysql --with-ndo2db-user=nagios --with-ndo2db-group=nagios
[root@localhost ndoutils-1.4b9]# make (make install)
[root@localhost ndoutils-1.4b9]# cd src/
[root@localhost src]# cp ndomod-3x.o ndo2db-3x log2ndo file2sock /usr/bin
[root@localhost src]# cd ../config
[root@localhost config]# cp ndo2db.cfg-sample ndo2db.cfg
[root@localhost config]# cp ndomod.cfg-sample ndomod.cfg
[root@localhost config]# cp ndo2db.cfg ndomod.cfg /usr/local/nagios/etc/
[root@localhost config]# cd /usr/local/nagios/etc/
[root@localhost etc]# vi ndo2db.cfg
102 db_name=cacti
111 db_prefix=npc_
120 db_user=cactiuser
121 db_pass=pwd123
163 debug_level=1

[root@localhost etc]# vi /usr/local/nagios/etc/nagios.cfg
247 # Uncomment the line below  you're running Nagios 3.x
248 broker_module=/usr/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg

NPC安装
[root@localhost etc]# cd /soft/
[root@localhost soft]# tar zxvf npc-2.0.4.tar.gz
[root@localhost soft]# mv npc/ /var/www/html/cacti/plugins/
[root@localhost soft]# vi /var/www/html/cacti/include/global.php
  46 $plugins[] = 'npc';

NPC 界面设置
登陆cacti


找到UserManagement


进去把勾plugin Management勾上,保存


settings下面的plugin management ,在点INSTALL,然后enable


装好了


返回(console)菜单栏,点击 configuration-------settings----NPC,修改一下三个参数(如下图,cmd填写上就行,命令会自动生成)


点击NPCOFF


启动ndo2db
[root@localhost soft]# ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
[root@localhost soft]# service nagios restart
[root@localhost soft]# cat /var/log/messages
Jul  5 17:30:27 localhost nagios: ndomod: Could not open data sink!  I'll keep trying, but some output may get lost...
Jul  5 17:30:27 localhost nagios: Event broker module '/usr/bin/ndomod-3x.o' initialized successfully.
Jul  5 17:30:27 localhost nagios: Finished daemonizing... (New PID=12009)

第一行报错:是因为没给ndo2db文件权限
[root@localhost soft]#chown nagios.nagios /usr/local/nagios/etc/ndo*
[root@localhost soft]# service nagios restart
[root@localhost soft]# cat /var/log/messages
Jul  5 17:37:46 localhost ndo2db-3x: mysql_error: 'Unknown column 'long_output' in 'field list''
这次是,数据库有问题
[root@localhost soft]# 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
[root@localhost soft]# service nagios restart
[root@localhost soft]# cat /var/log/messages
Jul  5 17:40:52 localhost nagios: ndomod: Successfully connected to data sink.  0 queued items to flush.
Jul  5 17:40:52 localhost nagios: Event broker module '/usr/bin/ndomod-3x.o' initialized successfully.
Jul  5 17:40:52 localhost nagios: Finished daemonizing... (New PID=12381)

Ndo2db启动成功,现在就可以看到NPC的数据了。







运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-661904-1-1.html 上篇帖子: cacti 监控 mysql 的几种方法 _ 参考用 下篇帖子: cacti有图无数据故障检查
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表