准备工做
一、关闭iptablesphp
- chkconfig iptables off
二、关闭selinuxhtml
用vim打开 /etc/selinux/confignode
将 SELINUX=enforcing 修改成 SELINUX=disabled 保存重启。python
三、安装httpd、mysql、php、net-snmp、gcc、glibc、glibc-common、gd、gd-devel、openssl、libtool、libtool-ltdl、libtool-ltdl-devel【安装完成后用 rpm -qi httpd 或者 rpm -qa |grep mysql 命令查看是否安装成功及版本信息】。mysql
- yum install -y httpd-*
- yum install -y mysql-*
- yum install -y php-*
- yum install -y net-snmp*
- yum install -y gcc
- yum install -y glibc
- yum install -y glibc-common //这个可能安装glibc的时候已经装了
- yum install -y gd
- yum install -y gd-devel
- yum install -y openssl*
- yum install -y libtool
- yum install -y libtool-ltdl //这个可能安装libtool的时候已经装了
- yum install -y libtool-ltdl-devel
四、安装包下载linux
整合Nagios+Cacti+Nconf+Npc中文版安装包ios
1、nagios环境的搭建
一、安装nagiosweb
- useradd nagios
- tar zxf nagios-3.2.0.tar.gz
- cd nagios-3.2.0
- ./configure -prefix=/var/www/html/nagios
- make all
- make install && make install-init && make install-commandmode && make install-config && make install-webconf
二、安装中文的nagiossql
- tar xf nagios-cn-3.2.0.tar.bz2
- cd nagios-cn-3.2.0
- ./configure -prefix=/var/www/html/nagios
- make all
- make install && make install-init && make install-commandmode && make install-config && make install-webconf
三、增长nagios登录认证文件,必定要用默认的nagiosadmin做为用户数据库
- htpasswd -c /var/www/html/nagios/etc/htpasswd.users nagiosadmin //设置nagios用户密码
不然须要修改/var/www/html/nagios/etc/cgi.cfg这个文件
vi /etc/nagios/cgi.cfg
- authorized_for_system_information=nagiosadmin
- authorized_for_configuration_information=nagiosadmin
- authorized_for_system_commands=nagiosadmin
- authorized_for_all_services=nagiosadmin
- authorized_for_all_hosts=nagiosadmin
- authorized_for_all_service_commands=nagiosadmin
- authorized_for_all_host_commands=nagiosadmin
四、安装插件
- tar xf nagios-plugins-1.4.14.tar.gz
- cd nagios-plugins-1.4.14
- ./configure -prefix=/var/www/html/nagios/
- make
- make install
五、将运行Apache的用户添加到nagios组里,这样Apache才有权限读取文件
usermod -G nagios apache //将apache用户加到nagios组
六、阶段测试
- chown nagios.nagios /var/www/html/nagios/ -R
- service httpd restart
- chkconfig httpd on
- /etc/init.d/nagios start
- chkconfig nagios on
访问 http://IP/nagios 看看帐号密码对不对

2、cacti环境的搭建
一、rrdtool的安装
这里须要安装的是:rrdtool,rrdtool-devel.rrdtool-perl,rrdtool-php, rrdtool-python,下载文章中提供的软件包,本地rpm安装。
- rpm -ivh --nodeps rrdtool-1.3.8-7.el6.x86_64.rpm
- rpm -ivh --nodeps rrdtool-devel-1.3.8-7.el6.x86_64.rpm
- rpm -ivh --nodeps rrdtool-perl-1.3.8-7.el6.x86_64.rpm
- rpm -ivh --nodeps rrdtool-php-1.3.8-7.el6.x86_64.rpm
- rpm -ivh --nodeps rrdtool-python-1.3.8-7.el6.x86_64.rpm
- service mysqld start
二、配置snmp
vim /etc/snmp/snmpd.conf
- com2sec notConfigUser 127.0.0.1 public
- access notConfigGroup "" any noauth exact all none none
- view all included .1 80
- //前两行是修改最后一行是取消注释
- service snmpd restart
- chkconfig snmpd on
- snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
- IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
- IP-MIB::ipAdEntIfIndex.xxx.xxx.xxx.xxx = INTEGER: 2
显示以上信息,则snmp配置成功,xxx.xxx.xxx.xxx会根据你本机的IP信息配置而不一样。
三、安装cacti
- tar xf cacti-0.8.7e-cn-utf8.tar.gz
- mv cacti-0.8.7e-cn-utf8 /var/www/html/cacti
四、建立cacti数据库
- service mysqld start
- chkconfig mysqld on
- /usr/bin/mysql_secure_installation //设置数据库root密码,回车-输入y-输入两次密码-在按4个Y
- #mysql -uroot -proot
- mysql>create database cacti default character set utf8; //数据库字符集设置utf8,不然乱码
- mysql>grant all privileges on cacti.* to cacti@localhost identified by 'cacti' with grant option;
- mysql>flush privileges;
五、将cacti的表内容导入建立的数据库
- cd /var/www/html/cacti
- mysql -ucacti -pcacti cacti < cacti.sql //若是mysql版本为5.5以上须要将cacti.sql里的TYPE=MyISAM 修改成 ENGINE=MyISAM
六、编辑.php文件,以适应环境
vim /var/www/html/cacti/include/config.php
修改内容以下
- $database_type = "mysql";
- $database_default = "cacti";
- $database_hostname = "localhost";
- $database_username = "cacti";
- $database_password = "cacti";
- useradd -r -M cacti
- chown -R cacti /var/www/html/cacti/rra/
- chown -R cacti /var/www/html/cacti/log/
七、在cacti用户下建立计划任务以画图
- yum install -y vixie-cron //安装计划任务,某些系统上可能没有预装
- chkconfig crond on //设为开机启动
- service crond start //启动crond
- vim /etc/crontab
- //添加
- */5 * * * * root /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1
八、安装中文字体不然图像文字上是乱码
- mkdir /ttf
- mv ttf-arphic-ukai_0.2.20080216.1.orig.tar.gz /ttf
- cd /ttf
- tar xf ttf-arphic-ukai_0.2.20080216.1.orig.tar.gz
- mv ukai.ttc /usr/share/fonts/ukai.ttc
- cd ..
- rm -rf ttf/
九、从web页面启动cacti,安装,并查看图形化界面
浏览器访问:http://localhost/cacti/install/ 安装
默认登陆用户:admin 密码:admin

控制面板 > 设备 > 本机 > SNMP选项 > SNMP 版本 选择 版本1 > 保存

控制面板 > 设置 > 路径 > RRDTool默认字体路径 /usr/share/fonts/ukai.ttc > 保存

若是配置正确,隔几分钟,咱们的cacti就会有数据了,如图,你也能够手动执行如下命令手动生成rrd图像
/usr/bin/php /var/www/html/cacti/poller.php --force

3、安装cacti-spine
一、cacti-spine的安装
因为默认cmd.php来轮询数据,速度会很慢,特别是在监控节点比较多的状况下,cmd.php就更显不足了,所以咱们采用Spine来轮询数据。cacti-spine是一个由C语言开发的,用于替代cmd.php的快速获取速度的引擎。
- tar xf cacti-spine-0.8.7e.tar.gz
- cd cacti-spine-0.8.7e
- ./configure
//这里若是出现报错
configure: error: cannot run /bin/sh config/config.sub
解决步骤
- cd config
- ll -h
- rm -rf config.guess config.sub ltmain.sh
- ln -s -f /usr/share/libtool/config/config.sub config.sub
- ln -s -f /usr/share/libtool/config/config.guess config.guess
- ln -s -f /usr/share/libtool/config/ltmain.sh ltmain.sh
- cd ..
在从新运行 ./configure
make
//这里若是出现错误,可能由于你没有装 libtool 或者libtool的版本不匹配

先检查你有没有安装libtool
rpm -qi libtool若是没有就yum install -y libtool*而后在进行尝试
若是还不行的
- #autoreconf --force --install
- #make
- #make install
vi /usr/local/spine/etc/spine.conf //修改访问数据库用户密码
修改内容以下:
- DB_Host localhost
- DB_Database cacti
- DB_User cacti
- DB_Pass cacti
- DB_Port 3306
测试是否正常
#/usr/local/spine/bin/spine //此命令须要在/usr/local/spine/etc/目录下运行,不然会报错PM - SPINE: Poller[0] FATAL: Unable to read configuration file! (Spine init)
#echo /usr/local/spine/bin/spine >>/etc/rc.d/rc.local
二、cacti-spine的应用
控制面板 > 设置 > 路径 > Spine轮询器路径 /usr/local/spine/bin/spine
控制面板 > 设置 > 轮询器 > 轮询器类型 spine
4、整合Nagios与Cacti
一、下载并安装ndoutils
- 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
二、准备配置文件
- 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/*
三、修改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
四、修改ndo2db.cfg以适应当前环境
- vim /var/www/html/nagios/etc/ndo2db.cfg
- //确保下列内容为惟一项
- socket_type=unix
- db_servertype=mysql
- db_host=localhost
- db_port=3306
- db_name=cacti
- db_prefix=nagios_
- db_user=cacti
- db_pass=cacti
五、修改ndomod.cfg以适应当前环境
- vim /var/www/html/nagios/etc/ndomod.cfg
- //确保下列项为惟一内容
- output_type=unixsocket
- output=127.0.0.1 //去掉注释
六、为ndo2db添加启动进程
- cp ./daemon-init /etc/init.d/ndo2db
- vim /etc/init.d/ndo2db
- // 并将Ndo2dbBin修改为下面的值
- Ndo2dbBin=/var/www/html/nagios/bin/ndo2db-3x
- chmod +x /etc/init.d/ndo2db
七、启动守护进程与nagios
service ndo2db start
chkconfig ndo2db on
tail -20 /var/log/messages // 查看其中是否有错误出现。如无报错请继续
service nagios restart
5、安装cacti-plugin 插件管理
Cacti-Plugin安装过程以下:
- gunzip cacti-plugin-0.8.7e-PA-v2.5-cn-utf8.diff.gz
- mv cacti-plugin-0.8.7e-PA-v2.5-cn-utf8.diff /var/www/html/cacti/
- cd /var/www/html/cacti
- patch -p1 -N < cacti-plugin-0.8.7e-PA-v2.5-cn-utf8.diff
- mysql -ucacti -pcacti cacti < pa.sql
若是你的cacti访问时候是使用 http://ip/cacti,你须要修改/var/www/html/cacti/include/global.php
修改以下:
- $database_type = "mysql";
- $database_default = "cacti";
- $database_hostname = "localhost";
- $database_username = "cacti";
- $database_password = "cacti";
- $database_port = "3306";
-
- $config['url_path'] = '/cacti/'; //记住是修改不是添加
配置Cacti
控制面板 > 用户管理 > admin > 区域权限,选择”插件管理” > 保存
而后咱们就可以在控制面板的”配置”下面看到多出一个”插件管理”的选项
6、安装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';

一、安装 npc支持:json (看状况进行安装,个人已经装了)
先使用这条命令看看PHP里有没有JSON的模块 php -m | grep json 若是有了就略过。
tar zxvf json-1.2.1.tgz
cd json-1.2.1
phpize //若是发现没有Phpize文件,则是由于php-devel包没有安装致使的
yum install -y php-devel //安装php-devel
./configure
make && make install
php -i | grep php.ini // 查看是否有导入信息
打开php.ini文件添加对json的支持
vim /etc/php.ini
// 添加
extension=json.so
php -m // 查看是否有json被加载
二、配置npc基本环境
1)为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生效
2)修改配置文件以让npc读取到新的数据
- vim /var/www/html/nagios/etc/ndo2db.cfg
- //修改
- db_prefix=npc_
3)启用NPC插件,修改mysql中的表结构
控制面板 > 插件管理 > 安装 > 启用
- #mysql -ucacti -pcacti -A
- mysql> use cacti;
- mysql> alter table npc_eventhandlers add long_output TEXT NOT NULL default '' after output;
- mysql> alter table npc_hostchecks add long_output TEXT NOT NULL default '' after output;
- mysql> alter table npc_hoststatus add long_output TEXT NOT NULL default '' after output;
- mysql> alter table npc_notifications add long_output TEXT NOT NULL default '' after output;
- mysql> alter table npc_servicechecks add long_output TEXT NOT NULL default '' after output;
- mysql> alter table npc_servicestatus add long_output TEXT NOT NULL default '' after output;
- mysql> alter table npc_statehistory add long_output TEXT NOT NULL default '' after output;
- mysql> alter table npc_systemcommands add long_output TEXT NOT NULL default '' after output;
4)重启ndo2db进程,从新加载配置文件重启nagios服务
service ndo2db start
service nagios restart
5)在Web上配置NPC以使之正常读取工做
控制面板 > 设置 > NPC
Nagios Command File Path= /var/www/html/nagios/var/rw/nagios.cmd
Nagios URL=你的地址(http://101.200.175.24/nagios)
接下来刷新npc就能够看到数据啦
若是你点开NPC的时候状态是OFF的话。进行操做以下:
- vim /var/www/html/nagios/etc/ndomod.cfg
- // 修改
- output_type=tcpsocket
- vim /var/www/html/nagios/etc/ndo2db.cfg
- // 修改
- socket_type=tcp
*必定要保证是惟一项,有重复的注释掉*
7、Nconf的安装与配置
一、nconf的准备工做
- #mysql -uroot -proot
- mysql> create database nconf;
- mysql> grant all privileges on nconf.* to nconf@localhost identified by 'nconf';
- mysql> flush privileges;
- mysql> quit
二、安装nconf
- tar -zxf nconf-1.3.0-0.tgz -C /var/www/html/
- cd /var/www/html/nconf
- chown -R apache.apache config/ temp/ static_cfg/ output/
三、进入Web页面在web页面按照安装提示一步步安装
http://localhost/nconf/
//使用刚才建立的nconf数据库和nconf数据库用户/密码
到下图中这个页面设置登陆用户密码

四、成功链接mysql数据库以后一切保持默认,直到下面的,设置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-ONS/deploy_local.sh
- //修改NAGIOS_DIR路径
- NAGIOS_DIR="/var/www/html/nagios/etc/"
六、从新刷新网页
七、点击Generate Nagios config尝试生成配置文件,以测试是否与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.cfg
- //将其中cfg_file=*******字段所有注释 ,并加入
- cfg_dir=/var/www/html/nagios/etc/Default_collector
- cfg_dir=/var/www/html/nagios/etc/global
- service nagios reload //重载nagios配置文件使之生效
若是生成Nagios配置文件没问题的话,就能够执行如下脚本使Nagios配置生效:
#/var/www/html/nconf/ADD-ONS/deploy_local.sh
想实现Nconf点生成使Nagios配置文件当即生效的,请查看下面这篇文章!
Nconf点生成使Nagios配置文件当即生效