生产环境监控系统Nginx+Nagios+Cacti+Nconf大整合(最新源码安装)

Linux评论9阅读模式

此文是成功在《Nginx下搭建Nagios监控平台》基础上继续,安装整合Cacti、Nconf。其中花了很多时间来排错。
1、下载所需要最新稳定源码包

cd nagios-cacti
wget http://www.cacti.net/downloads/cacti-0.8.8a.tar.gz
wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8a.tar.gz
wget http://nchc.dl.sourceforge.net/project/nagios/ndoutils-1.x/ndoutils-1.5.2/ndoutils-1.5.2.tar.gz
wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.7.tar.gz
wget http://iweb.dl.sourceforge.net/project/gibtmirdas/npc-2.0.4.tar.gz
wget http://nchc.dl.sourceforge.net/project/nconf/nconf/1.3.0-0/nconf-1.3.0-0.tgz

2、snmp

yum -y install net-snmp-*
vi /etc/snmp/snmpd.conf #确保下面3个地方如下
com2sec notConfigUser  127.0.0.1 public
access  notConfigGroup ""      any       noauth    exact  all none none
view all    included  .1                               80
 
chkconfig snmpd on
service snmpd start

3、spine
spine是一个基于C语言的,非常快速的轮询引擎。它是默认的cmd.php的可选替代,主要是为了加快SNMP轮训。如果你发现你的cmd.php 运行超过300 秒的话,推荐使用Spine。

tar xzf cacti-spine-0.8.8a.tar.gz
cd cacti-spine-0.8.8a
./configure --prefix=/usr/local/spine
make && make install
cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
sed -i 's@DB_Pass.*$@DB_Pass         cactiuser123@' /usr/local/spine/etc/spine.conf
cd ../

4、Cacti

tar xzf cacti-0.8.8a.tar.gz
mv cacti-0.8.8a /data/admin/cacti/
chown -R www.www /data/admin/cacti/
mysqlrootpwd=admin
/usr/local/mysql/bin/mysql -uroot -p$mysqlrootpwd -e "grant all on cacti.* to cactiuser@localhost identified by 'cactiuser123'"
/usr/local/mysql/bin/mysql -uroot -p$mysqlrootpwd -e "flush privileges"
sed -i 's@ENGINE=MyISAM@@g' /data/admin/cacti/cacti.sql
sed -i '1 i\create database cacti;' /data/admin/cacti/cacti.sql
/usr/local/mysql/bin/mysql -uroot -p$mysqlrootpwd cacti < /data/admin/cacti/cacti.sql sed -i 's@$database_password.*@$database_password = "cactiuser123";@g' /data/admin/cacti/include/config.php sed -i 's@//$url_path@$url_path@g' /data/admin/cacti/include/config.php echo '*/5 * * * * /usr/local/php/bin/php /data/admin/cacti/poller.php > /dev/null 2>/data/admin/cacti/log/pooler-error.log' >> /var/spool/cron/www
service crond restart
yum install rrdtool
tar xzf rrdtool-1.4.7.tar.gz
cd rrdtool-1.4.7
yum -y install libart_lgpl libart_lgpl-deve pango-devel cairo-devel
./configure --prefix=/usr/local/rrtool --disable-python --disable-tcl
make && make install
cd ../

登录web页面地址(具体地址看nginx.conf配置文件):http://www.linuxeye.com/cacti
Cacti默认的用户名与密码是admin,输入用户名与密码,点击login。为了安全的原因,第一次登录成功后,cacti会强制要求你更改一个新的密码 ,输入新密码并确认密码,点击save,进入cacti控制台界面,如下图解:
生产环境监控系统Nginx+Nagios+Cacti+Nconf大整合(最新源码安装)-图片1

生产环境监控系统Nginx+Nagios+Cacti+Nconf大整合(最新源码安装)-图片2

生产环境监控系统Nginx+Nagios+Cacti+Nconf大整合(最新源码安装)-图片3

5、安装配置Ndoutils
Ndoutils是整合cacti和nagios是利用了cacti的一个插件nagios for cacti,它的原理是将nagios的数据通过ndo2db导入到mysql数据库(cacti的库中),然后cacti读取数据库信息将nagios的结果展示出来。

tar xzf ndoutils-1.5.2.tar.gz
cd ndoutils-1.5.2
./configure --prefix=/usr/local/nagios --enable-mysql --with-mysql=/usr/local/mysql

make报错以下错误:

cd ./src && make
make[1]: Entering directory `/root/nagios-cacti/ndoutils-1.5.2/src'
gcc -fPIC -g -O2 -I/usr/local/mysql/include -DHAVE_CONFIG_H  -c -o io.o io.c
In file included from io.c:11:
../include/config.h:261:25: error: mysql/mysql.h: No such file or directory
../include/config.h:262:26: error: mysql/errmsg.h: No such file or directory
make[1]: *** [io.o] Error 1
make[1]: Leaving directory `/root/nagios-cacti/ndoutils-1.5.2/src'
make: *** [all] Error 2

解决方法如下:

sed -i 's@#include <mysql/mysql.h>@#include @' include/config.h
sed -i 's@#include <mysql/errmsg.h>@#include @' include/config.h

重新编译安装

make && make install
cp daemon-init /etc/init.d/ndo2db
chmod +x /etc/init.d/ndo2db
chkconfig --add ndo2db
cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
chown nagios.nagios /usr/local/nagios/etc/{ndo2db.cfg,ndomod.cfg}
 
sed -i 's@ENGINE=MyISAM@@g' db/mysql.sql
sed -i '1 i\use cacti;' db/mysql.sql
/usr/local/mysql/bin/mysql -ucactiuser -pcactiuser123 cacti < db/mysql.sql
sed -i 's@\(.*broker_module=/somewhere/module2.o.*$\)@\1\nbroker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg@' /usr/local/nagios/etc/nagios.cfg

修改ndo2db.cfg、ndomod.cfg适应当前环境

sed -i 's@socket_type=unix@#socket_type=unix@' /usr/local/nagios/etc/ndo2db.cfg
sed -i 's@#socket_type=tcp@socket_type=tcp@' /usr/local/nagios/etc/ndo2db.cfg
 
sed -i 's@^db_name.*$@db_name=cacti@' /usr/local/nagios/etc/ndo2db.cfg
sed -i 's@^db_user.*$@db_user=cactiuser@' /usr/local/nagios/etc/ndo2db.cfg
sed -i 's@^db_pass.*$@db_pass=cactiuser123@' /usr/local/nagios/etc/ndo2db.cfg
 
sed -i 's@^output_type=unixsocket@#output_type=unixsocket@' /usr/local/nagios/etc/ndomod.cfg
sed -i 's@^output=/usr/local/nagios/var/ndo.sock@#output=/usr/local/nagios/var/ndo.sock@' /usr/local/nagios/etc/ndomod.cfg
sed -i 's@^#output_type=tcpsocket@output_type=tcpsocket@' /usr/local/nagios/etc/ndomod.cfg
sed -i 's@^#output=127.0.0.1@output=127.0.0.1@' /usr/local/nagios/etc/ndomod.cfg
 
cd ../
service ndo2db start

6、安装NPC,在Cacti中展现Nagios

tar xzf npc-2.0.4.tar.gz -C /data/admin/cacti/plugins
chown -R www.www /data/admin/cacti/plugins
cd ../

登陆Cacti,在Console -> Plugin Management 安装NPC生产环境监控系统Nginx+Nagios+Cacti+Nconf大整合(最新源码安装)-图片4
再点击绿色按钮启用
生产环境监控系统Nginx+Nagios+Cacti+Nconf大整合(最新源码安装)-图片4
在Settings->npc中 ,勾上Remote Commands
生产环境监控系统Nginx+Nagios+Cacti+Nconf大整合(最新源码安装)-图片4

sed -i 's@^db_prefix=nagios_@db_prefix=npc_@' /usr/local/nagios/etc/ndo2db.cfg

修改mysql中的表结构:

/usr/local/mysql/bin/mysql -ucactiuser -pcactiuser123
alter table cacti.npc_eventhandlers add long_output TEXT NOT NULL default '' after output;
alter table cacti.npc_hostchecks add long_output TEXT NOT NULL default '' after output;
alter table cacti.npc_hoststatus add long_output TEXT NOT NULL default '' after output;
alter table cacti.npc_notifications add long_output TEXT NOT NULL default '' after output;
alter table cacti.npc_servicechecks add long_output TEXT NOT NULL default '' after output;
alter table cacti.npc_servicestatus add long_output TEXT NOT NULL default '' after output;
alter table cacti.npc_statehistory add long_output TEXT NOT NULL default '' after output;
alter table cacti.npc_systemcommands add long_output TEXT NOT NULL default '' after output;
service ndo2db restart
service nagios restart

测试:
生产环境监控系统Nginx+Nagios+Cacti+Nconf大整合(最新源码安装)-图片5

7、Nconf的安装与配置
准备工作

/usr/local/mysql/bin/mysql -uroot -p$mysqlrootpwd -e "create database nconf;"
/usr/local/mysql/bin/mysql -uroot -p$mysqlrootpwd -e "grant all privileges on nconf.* to nconf@localhost identified by 'nconf';"
/usr/local/mysql/bin/mysql -uroot -p$mysqlrootpwd -e "flush privileges;"

安装nconf

tar xzf nconf-1.3.0-0.tgz -C /data/admin/
chown -R www.www /data/admin/nconf

进入Web页面在web页面按照安装提示一步步安装

生产环境监控系统Nginx+Nagios+Cacti+Nconf大整合(最新源码安装)-图片6

ln -s /usr/local/nagios/bin/nagios /data/admin/nconf/bin

登录web Nconf管理地址:http://www.linuxeye.com/nconf/

成功连接mysql数据库,之后一切保持默认,直到下面的,设置nconf管理员密码,此时默认登录用户为admin。

出现报错(如下图),删除相应文件

rm -rf /data/admin/nconf/{INSTALL,INSTALL.php,UPDATE,UPDATE.php}

生产环境监控系统Nginx+Nagios+Cacti+Nconf大整合(最新源码安装)-图片7

重新刷新页面,输入admin/您设置的密码,进入nconf页面

点击Generate Nagios config尝试生成配置文件,以测试是否与nagios成功关联
nconf –> Generate Nagios config –> 报错了。
Error accessing or executing Nagios / Icinga binary ‘/data/admin/nconf/bin/nagios’.
Cannot run the mandatory syntax check.

解决办法:
检查你的/data/admin/nconf/bin/nagios这个文件所链接的那个原始文件的权限,确保是777或者775

chmod +x /usr/local/nagios/bin/nagios

点击Generate Nagios config尝试生成配置文件,还是报如下错误:
Error Deployment not possible due to errors in configuration.
Error: Cannot open main configuration file ‘/data/admin/nconf/temp/test/Default_collector.cfg’ for reading!
因此Nconf的脚本使用的perl无法和MySQL交互导致,因此安装perl-DBD-MySQL,方法如下:

wget http://www.cpan.org/modules/by-module/DBD/DBD-mysql-4.023.tar.gz
tar xzf DBD-mysql-4.023.tar.gz
cd DBD-mysql-4.023
yum -y install perl-DBI  #解决报错Can't locate DBI/DBD.pm in @INC
perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config
make && make install
cd ../
cd /usr/local/nagios
sed -i 's@^OUTPUT_DIR.*@OUTPUT_DIR="/data/admin/nconf/output/"@' /data/admin/nconf/ADD-ONS/deploy_local.sh
sed -i 's@^tar -xf@tar -xzf@' /data/admin/nconf/ADD-ONS/deploy_local.sh #源码包中少了个z参数,不能正常解压,折腾死我了
/data/admin/nconf/ADD-ONS/deploy_local.sh #手动执行此脚本,将在/usr/local/nagios/etc/下生成目录Default_collector与global

修改nagios主配置文件,注销以前配置,交给nconf管理

sed -i 's@\(^cfg_file=.*\)@#\1@g' /usr/local/nagios/etc/nagios.cfg
echo 'cfg_dir=/usr/local/nagios/etc/Default_collector
cfg_dir=/usr/local/nagios/etc/global' >> /usr/local/nagios/etc/nagios.cfg
 
service nagios restart

用Nconf Web修改后希望以www能重启nagios

sed -i 's@^Defaults.*requiretty@#Defaults    requiretty@' /etc/sudoers
sed -i 's@\(^root.*\)@\1\nwww ALL=NOPASSWD: /etc/rc.d/init.d/nagios reload@' /etc/sudoers
cat /data/admin/nconf/config/deployment.ini
[extract config]
type        = local
source_file = "/data/admin/nconf/output/NagiosConfig.tgz"
target_file = "/tmp/"
action      = extract
 
点击复制
type        = local
source_file = "/tmp/Default_collector/"
target_file = "/usr/local/nagios/etc/Default_collector/"
action      = copy
 
点击复制
type        = local
source_file = "/tmp/global/"
target_file = "/usr/local/nagios/etc/global/"
action      = copy
reload_command = "sudo /etc/rc.d/init.d/nagios reload"

Fri Apr 19 11:55:15 CST 2013

 
  • 本文由 yeho 发表于 2013-04-19
  • 转载请务必保留本文链接:https://linuxeye.com/314.html
  • Cacti
  • Nagios
  • Nconf
  • ndoutils
  • Nginx
  • rrdtool
  • SNMP
  • spine
  • 流量监控
  • 监控
Linux

Nginx反向代理永久性缓存

Nginx缓存简介 Nginx缓存方式有两种: 永久性的缓存:这种缓存若不手动删除,该缓存文件会一直生效,因此,永久缓存只是用于缓存网站中几乎不会更改的内容; 临时缓存:这种缓存是根据请求连接进行哈希...
Linux

Nginx Lua Redis防止CC攻击

Nginx Lua Redis防止CC攻击实现原理:同一个外网IP、同一个网址(ngx.var.request_uri)、同一个客户端(http_user_agent)在某一段时间(CCseconds...
Linux

Keepalived+Nginx架构整理版

Keepalived介绍 keepalived是一个类似于layer3, 4, 5 交换机制的软件,也就是我们平时说的第3层、第4层和第5层交换。Keepalived的作用是检测web服务器的状态,如...
Nginx中文域名配置 Linux

Nginx中文域名配置

Nginx虚拟主机上绑定一个带中文域名,比如linuxeye.中国,浏览器不能跳转。 why? 因为操作系统的核心都是英文组成,DNS服务器的解析也是由英文代码交换,所以DNS服务器上并不支持直接的中...
匿名

发表评论

匿名网友
确定

拖动滑块以完成验证