原文链接:http://foreveryan.blog.51cto.com/3508502/727866
- 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
- 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
- htpasswd -c /var/www/html/nagios/etc/htpasswd.users nagiosadmin
- wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz
- tar -zvxf nagios-plugins-1.4.15.tar.gz
- cd nagios-plugins-1.4.15
- ./configure --prefix=/var/www/html/nagios/
- make
- make install
- 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
在这里没有提供rrdtool的工具,需要下载可以去这里下载上述的3个软件包
rrdtool、rrdtool-devel的地址:
http://packages.express.org/rrdtool/
rrdtool-php的地址:
http://pkgs.org/download/rrdtool-php
注意,rrdtool的组件和附加组件版本尽量一致,而由于rrdtool-php这个包非常稀有,所以,尽量请以rrdtool-php的版本来决定rrdtool以及rrdtool-devel的版本。
还有一定要对应环境,别安装成了fedora的版本了=。=
|
- yum localinstall -y --nogpgcheck rrdtool-*
- service mysqld start
- vim /etc/snmp/snmpd.conf
- # 修改3项 127.0.0.1 、 all、启用项(修改的内容详见我Cacti的安装文档,上面有非常详细的内容介绍)
- service snmpd restart
- 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
- mysql> create database cacti;
- mysql> grant all on cacti.* to 'cacti'@'localhost' identified by 'cacti';
- mysql> flush privileges;
- cd /var/www/html/cacti
- mysql -ucacti -pcacti cacti < /var/www/html/cacti/cacti.sql
- vim /var/www/html/cacti/include/config.php
- vim /var/www/html/cacti/include/global.php
$database_default = "cacti"; //默认数据库名
$database_hostname = "localhost"; //主机名
$database_username = "cacti"; //登陆数据库用户名
$database_password = "cacti"; //登陆数据库密码
$database_port = "3306";
|
- useradd –r –M cacti
- chown –R cacti /var/www/html/cacti/rra/
- chown –R cacti /var/www/html/cacti/log/
- su cacti
- crontab –e
- */5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1
- php /var/www/html/cacti/poller.php > /dev/null 2>&1
- exit
- 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
- 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/*
- 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
- 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
- vim /var/www/html/nagios/etc/ndomod.cfg
- # 确保下列项的唯一内容为
- output_type=tcpsocket
- output=127.0.0.1
- 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
- service ndo2db start
- tail -20 /var/log/messages ## 查看其中是否有错误出现。如无报错请继续
- service nagios start
- 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 = "/cacti/";
- 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';
- 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 ## 查看是否有导入信息
- vim /etc/php.ini
- # 添加
- extension=json.so
- 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被加载
- vim /var/www/html/nagios/etc/ndo2db.cfg
- db_prefix=npc_
- ./mysql -ucacti -p cacti
- 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;
- service ndo2db restart
- service nagios restart
- # 进入mysql数据库
- mysql> create database nconf;
- # 创建nconf数据库
- mysql> grant all privileges on nconf.* to nconf@localhost identified by 'nconf';
- # 创建nconf用户并赋权
- mysql> flush privileges;
- # 刷新特权表
- mysql> quit
- 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/
- 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路径为 /var/www/html/nagios/etc/
- /var/www/html/nconf/ADD-ONS/deploy_local.sh
- 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配置文件使之生效
六:错误总结:
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
|
2.在npc安装过程中进行表操作时报错
mysql> alter table npc_eventhandlers add long_output TEXT NOT NULL default '' after output; 解决办法:要先在cacti页面下正确的启用npc插件,正确的启用~一个向上的箭头和一个向右的箭头都要开启才行~ |
3.在应用nconf的时候报错
点 nconf --> Generate Nagios config --> 报错了。 Error accessing or executing Nagios / Icinga binary '/var/www/html/nconf/bin/nagios'. 解决办法: 检查你的/var/www/html/nconf/bin/nagios这个文件所链接的那个原始文件的权限,确保是777或者775 |
4....当然还没有发现错误,如果有,将会继续补充,欢迎网友在安装部署的过程中发现错误将错误积极交流,我将一一添加……
七:最后的样式