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

[经验分享] 监控系统安装配置文档(Nagios+Cacti+Nconf)

[复制链接]

尚未签到

发表于 2019-1-11 12:17:22 | 显示全部楼层 |阅读模式
监控系统安装配置文档(Nagios+Cacti+Nconf)


一:Nagios环境的搭建
1.为以后的配置搭建安装环境
# yum install -y http*
# yum install -y mysql*
# yum install -y php-*
# yum install -y net-snmp*
  # yum install -y httpd gcc glibc glibc-common gd gd-devel php php-gd ntp

2.安装nagios
  # wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.3.1/nagios-3.3.1.tar.gz
# tar zxf nagios-3.3.1.tar.gz
# cd nagios
# ./configure --prefix=/var/www/html/nagios
# make all
# useradd nagios
  # make install && make install-init && make install-commandmode && make install-config && make install-webconf

2.增加nagios登陆认证文件,一定要用默认的nagiosadmin作为用户,否则需要修改其他文件。
  # htpasswd -c /var/www/html/nagios/etc/htpasswd.users nagiosadmin

3. 安装插件:
  # wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz
# tar -xf nagios-plugins-1.4.15.tar
# cd nagios-plugins-1.4.15
# ./configure --prefix=/var/www/html/nagios/
# make
# make install

4.将运行Apache的用户添加到nagios组里,这样Apache才有权限读取文件
# usermod -G nagios apache    //将apache用户加到nagios组。

5.阶段测试
# chown nagios.nagios /var/www/html/nagios/ -R
# service httpd restart
# chkconfig httpd on
# /etc/init.d/nagios start


二:cacti环境的搭建
1.rrdtool的安装,这里需要安装的是:rrdtool,rrdtool-devel.rrdtool-perl,rrdtool-php
# yum localinstall -y --nogpgcheck rrdtool-*
# service mysqld start

2.配置snmp
# vim /etc/snmp/snmp.conf
                修改3项 127.0.0.1 、 all、启用项
# service snmpd restart

3.安装cacti
  # wget http://www.cacti.net/downloads/cacti-0.8.7h.tar.gz
# tar zxvf cacti-0.8.7h.tar.gz
# mv cacti-0.8.7h /var/www/html/cacti

4.创建cacti数据库
mysql> create database cacti;
  mysql> grant all on cacti.* to 'cacti'@'localhost' identified by 'cacti';
mysql> flush privileges;

5.将cacti的表内容导入创建的数据库
# cd /var/www/html/cacti
# mysql -ucacti -pcacti cacti < /var/www/html/cacti/cacti.sql

6.分别编辑两个.php文件,以适应环境,修改内容相同。
# vim /var/www/html/cacti/include/config.php
# vim /var/www/html/cacti/include/global.php
  $database_default = &quot;cacti&quot;;       //默认数据库名
  $database_hostname = &quot;localhost&quot;;         //主机名
  $database_username = &quot;cacti&quot;;              //登陆数据库用户名
  $database_password = &quot;cacti&quot;;              //登陆数据库密码
  $database_port = &quot;3306&quot;;

# useradd –r –M cacti
# chown –R cacti /var/www/html/cacti/rra/
# chown –R cacti /var/www/html/cacti/log/

7.在cacti用户下创建计划任务以画图
# su cacti
# crontab –e
  */1 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1
  # php /var/www/html/cacti/poller.php > /dev/null 2>&1
# exit

8.从web页面启动cacti,安装,并查看图形化界面



三:整合Nagios与Cacti
1.下载并安装ndoutils
  # wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.4b9/ndoutils-1.4b9.tar.gz/download
# tar zxvf ndoutils-1.4b9.tar.gz
# cd ndoutils-1.4b9
  # ./configure --prefix=/var/www/html/nagios --enable-mysql --disable-pgsql --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql
# make

2.准备配置文件
  # cp -v src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /var/www/html/nagios/bin
# cd db
# ./installdb -ucacti -pcacti -hlocalhost -d cacti
# cd ..
  # cp -v config/{ndo2db.cfg-sample,ndomod.cfg-sample} /var/www/html/nagios/etc
  # mv /var/www/html/nagios/etc/ndo2db.cfg-sample /var/www/html/nagios/etc/ndo2db.cfg
  # mv /var/www/html/nagios/etc/ndomod.cfg-sample /var/www/html/nagios/etc/ndomod.cfg
# chmod 644 /var/www/html/nagios/etc/ndo*
# chown nagios:nagios /var/www/html/nagios/etc/*
# chown nagios:nagios /var/www/html/nagios/bin/*

3.修改nagios.cfg配置文件以适应当前环境
# vim /var/www/html/nagios/etc/nagios.cfg
                在文件中添加:
  broker_module=/var/www/html/nagios/bin/ndomod-3x.o config_file=/var/www/html/nagios/etc/ndomod.cfg
检查
                event_broker_options=-1     //为Nagios开启event broker

4.修改ndo2db.cfg以适应当前环境
# vim /var/www/html/nagios/etc/ndo2db.cfg
                socket_type=tcp
                db_servertype=mysql
                db_host=localhost
                db_port=3306
               
                db_name=cacti

                db_prefix=nagios_
                db_user=cacti
                db_pass=cacti

5.修改ndomod.cfg以适应当前环境
# vim /var/www/html/nagios/etc/ndomod.cfg
                output_type=tcpsocket
                output=127.0.0.1

6.为ndo2db添加启动进程
# cp ./daemon-init /etc/init.d/ndo2db
# vim /etc/init.d/ndo2db
                检查里面的路径确保不会出现“//&quot;,并将Ndo2dbBin修改成下面的值:
                Ndo2dbBin=/var/www/html/nagios/bin/ndo2db-3x
# chmod +x /etc/init.d/ndo2db

7.启动守护进程
  # /var/www/html/nagios/bin/ndo2db-3x -c /var/www/html/nagios/etc/ndo2db.cfg
# tail -20 /var/log/messages    //查看其中是否有错误出现

添加开机自动启动
  # echo &quot;/var/www/html/nagios/bin/ndo2db-3x -c /var/www/html/nagios/etc/ndo2db.cfg&quot; >> /etc/rc.local
# service nagios restart


四:安装ncp,以在Cacti中展现Nagios
1.先安装cacti扩展模块
  # wget http://www.cacti.net/downloads/pia/cacti-plugin-0.8.7h-PA-v3.0.tar.gz
# tar xvf cacti-plugin-0.8.7h-PA-v3.0.tar.gz
# cp -R cacti-plugin-arch/* /var/www/html/cacti/
# cd /var/www/html/cacti/
# mysql -ucacti -pcacti cacti < pa.sql
# patch -p1 -N < cacti-plugin-0.8.7h-PA-v3.0.diff //为cacti配置文件打补丁的时候注意在为include/config.php打补丁的时候有可能它将 include/config.php.dist给打补丁了,我们只需要手动加入下面的内容即可。

# vim include/config.php
                修改(或新加入)为
  $url_path = &quot;/cacti/&quot;;

  从web进入cacti,启用cacti plugin扩展

2.安装npc
# tar zxvf npc-2.0.4.tar.gz
# mv npc /var/www/html/cacti/plugins/
# vim /var/www/html/cacti/include/config.php
                加入:
  $plugins[] = 'npc';

3.安装 npc支持:json
  # wget http://pkgs.fedoraproject.org/repo/pkgs/php-pecl-json/json-1.2.1.tgz/d8904d2f004ceec85eeacf524cd25539/json-1.2.1.tgz
# tar zxvf json-1.2.1.tgz
# cd json-1.2.1
# phpize               //如果发现没有Phpize文件,则是因为php-devel包没有安装导致的
# ./configure
# make && make install

# php -i | grep php.ini 查看是否有导入信息

4.打开php.ini文件添加对json的支持
# vim /etc/php.ini
                添加
                extension=json.so

5.为apache添加php支持。
# vim /etc/httpd/conf/httpd.conf
                添加一行:
  AddType application/x-httpd-php .php .phtml
修改原DirectoryIndex内容为:
  DirectoryIndex index.html index.html.var index.php
# usermod -G cacti apache
# service httpd restart                   //重启apache以让php生效                  
# php -m                                              //查看是否有json被加载

6.修改配置文件以让npc读取到新的数据。
# vim /var/www/html/nagios/etc/ndo2db.cfg
                db_prefix=npc_

6.1
从Web进入Cacti,确保正确使用npc选项。

6.2 修改mysql中的表结构:
./mysql -ucacti -p 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;


7.重启ndo2db进程,重新加载配置文件重启nagios服务。
# service ndo2db restart
# service nagios restart

8.在Web上配置NPC以使之正常读取工作。

  在Settings->npc中 ,勾上Remote Commands
  Nagios Command File Path= /var/www/html/nagios/var/rw/nagios.cmd
Nagios URL=你的地址(http://ocalhost/nagios/)
接下来刷新npc就可以看到数据


五:nconf的安装与配置
首先对mysql数据库进行定义
mysql> create database nconf;
  mysql> grant all privileges on nconf.* to nconf@localhost identified by 'nconf';
mysql> flush privileges;  
mysql>quit

下载与安装nconf
  # wget http://sourceforge.net/projects/nconf/files/nconf/1.2.6-0/nconf-1.2.6-0.tgz/download
# tar -zxf nconf-1.2.6-0.tgz -C /var/www/html/
# cd /var/www/html/nconf
  # chown -R apache.apache config/ temp/ static_cfg/ output/

进入web,开始安装
http://您nagios监控端的IP/nconf
在web页面按照安装提示一步步安装
使用刚才创建的nconf数据库和nconf数据库用户/密码
http://file:///C:/Users/yan.wei/AppData/Local/Temp/msohtmlclip1/01/clip_image001.jpg

输入用于通过nconf生成nagios配置文件所需的nconf路径和nagios命令路径
http://file:///C:/Users/yan.wei/AppData/Local/Temp/msohtmlclip1/01/clip_image003.jpg
设置nconf管理员密码,此时默认登录用户为admin

网页安装完成
# rm -rf INSTALL INSTALL.php UPDATE UPDATE.php
  # ln -s /var/www/html/nagios/bin/nagios bin/nagios
  # chmod +x /var/www/html/nconf/bin/generate_config.pl
# chown -R apache.apache bin
# chmod +x /var/www/html/nagios/bin/nagios
  # chmod +x /var/www/html/nconf/ADD-ONS/deploy_local.sh   
# vim /var/www/html/nconf/ADD-ONE/deploy_local.sh      
                修改里面的nagios为我们nagios的安装路径/var/www/html/nagios
重新刷新页面,输入admin/您设置的密码,进入nconf页面
  点击Generate Nagios config尝试生成配置文件,以测试是否与nagios成功关联

  注意:nconf在点击【Generate Nagios config】后将您的生成nagios配置文件是/var/www/html/nconf/output/NagiosConfig.tgz,而并非直接导入nagios中。
  1.在web页面对监控服务和主机配置完毕,点击【Generate Nagios config】
2.deploy_local.sh是nconf自带配置文件导入脚本
# /var/www/html/nconf/ADD-ONS/deploy_local.sh
手动执行此脚本,将在/var/www/html/nagios/etc下生成两目录Default_collector与global
3.修改nagios主配置文件
# vim /var/www/html/nagios/etc/nagios.cf
将其中cfg_file=*******字段全部注释 ,并加入
  cfg_dir=/var/www/html/nagios/etc/Default_collector
  cfg_dir=/var/www/html/nagios/etc/global
# service nagios reload
重载nagios配置文件使之生效


六:问题跟踪:
1.启动ndo2db发现日志报错:
  ndomod: Could not open data sink! I'll keep trying, but some output may get lost...
解决办法:
  检查 /nagios/etc目录的权限是否足够的大
确保/var/www/html/nagios/etc/nagios.cfg中有如下行出现,否则,请自行添加:
  event_broker_options=-1
检查ndo2db.cfg中的配置,确保使用tcp连接
                socket_type=tcp
检查ndomod.cfg中的配置,确保使用tcp套接字
                output_type=tcpsocket






运维网声明 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-662041-1-1.html 上篇帖子: cacti监控遇见的问题 下篇帖子: cacti大赢家网站运维监控配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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