cacti + nagios + npc 整合布置51CTO博客 - 牛牛娱乐

cacti + nagios + npc 整合布置51CTO博客

2019年03月10日09时10分36秒 | 作者: 晨涛 | 标签: 装置,文件,修正 | 浏览: 306


centos5.5 + cacti + nagios +  npc

都是用的yum做的,软件版别如下:
cacti-0.8.7e.tar.gz
cacti-plugin-0.8.7e-PA-v2.6.zip
nagios-3.4.1.tar.gz
nagios-plugins-1.4.16.tar.gz
ndoutils-1.4b9.tar.gz
npc-2.0.4.tar.gz
PDO_MYSQL-1.0.2.tgz
php-json-ext-1.2.1.tar.gz
rrdtool-1.4.4.tar.gz


一、装置环境LAMP

  1. #yum -y install *gcc*

  2. #yum -y install httpd httpd-manual mysql mysql-devel mysql-server php php-devel php-mysql php-common php-pdo php-gd lm_sensors net-snmp php-snmp net-snmp-utils


  3. # chkconfig mysqld on

  4. # chkconfig httpd on

  5. # chkconfig snmpd on

  6. # service mysqld start

  7. # service httpd start

  8. # service snmpd start


  9. # mysqladmin -u root password 'redhat321'


  10. # mysql -u root -p

  11. :输入暗码

  12. mysql>create database cacti;

  13. Query OK, 1 row affected (0.00 sec)


  14. mysql>grant all on cacti.* to cactiadmin@localhost identified by 'cacti321';

  15. Query OK, 0 rows affected (0.01 sec)


  16. mysql>flush privileges;

  17. Query OK, 0 rows affected (0.00 sec)


  18. mysql> \q

二、装置cacti
1、装置rrdtool需求的软件包
# yum -y install  cairo-devel libxml2-devel pango pango-devel

2、装置rrdtool

  1. # tar xf rrdtool-1.4.4.tar.gz

  2. # cd rrdtool-1.4.4

  3. # ./configure prefix=/usr/local/rrdtool && make && make install

  4. # ln -s /usr/local/rrdtool/bin/* /usr/local/bin/

3、装置cacti-0.8.7.e

  1. # tar xf cacti-0.8.7e.tar.gz -C /var/www/html/

  2. # cd /var/www/html/

  3. # mv cacti-0.8.7e/ cacti

  4. # chown -R root.root /var/www/html/cacti/

4、导入数据库

  1. # mysql -u root -p cacti <cacti/cacti.sql

  2. Enter password:

5、修正cacti装备文件,衔接数据库

  1. # vim /var/www/html/cacti/include/config.php

  2. $database_username = "cactiadmin";

  3. $database_password = "cacti321";


  4. # vim /var/www/html/cacti/include/global.php

  5. $database_username = "cactiadmin";

  6. $database_password = "cacti321";

6、装置插件cacti-plugin

  1. # wget http://mirror.cactiusers.org/downloads/plugins/cacti-plugin-0.8.7e-PA-v2.6.zip

  2. # unzip cacti-plugin-0.8.7e-PA-v2.6.zip

  3. # cd cacti-plugin-arch/

  4. # cp cacti-plugin-arch/{cacti-plugin-0.8.7e-PA-v2.6.diff,pa.sql} /var/www/html/cacti/

  5. # cd /var/www/html/cacti/

7、打补丁导入数据库

  1. # patch -p1 -N <cacti-plugin-0.8.7e-PA-v2.6.diff

  2. # mysql -uroot -p cacti<pa.sql

8、修正装备文件,如下:

  1. # vim include/global.php

  2. $config['url_path'] = '/cacti/';

9、增加计划任务

  1. # crontab -e

  2. */5 * * * * /usr/bin/php /var/www/html/cacti/poller.php

  3. # service crond restart

10、浏览器输入http://192.168.163.143/cacti/install初始化cacti,最终如下:

别的cacti无法显现图片,图片显红叉,可是点进去有图:
处理方法:
settings里边的RRDTOOLS版别设置不对,默以为1.0.x,改为1.2.x就行了。

三、被监控端装备

1、装置snmp效劳
# rpm -ivh  lm_sensors-2.10.7-4.el5.i386.rpm  net-snmp-5.3.2.2-7.el5.i386.rpm

2、修正装备文件如下:(这儿我省掉掉了#行和空行)

  1. # vim /etc/snmp/snmpd.conf

  2. com2sec notConfigUser default public

  3. group notConfigGroup v1 notConfigUser

  4. group notConfigGroup v2c notConfigUser

  5. view systemview included .1.3.6.1.2.1.1

  6. view systemview included .1.3.6.1.2.1.25.1.1

  7. access notConfigGroup "" any noauth exact mib2 none none

  8. view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc

  9. syslocation Unknown (edit /etc/snmp/snmpd.conf)

  10. syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)

  11. pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat


3、重启效劳
# service snmpd  restart

到此就差不多了,咱们能够做些检测在效劳器上,有信息回来说名正常:
# snmpwalk -v 2c -c public ServerIP if

四、装置nagios

1、树立用户

  1. # useradd -s /sbin/nologins nagios

  2. # mkdir -p /usr/local/nagios

  3. # chown -R  nagios.nagios /usr/local/nagios/

2、编译装置nagios

  1. # tar xf nagios-3.4.1.tar.gz

  2. # cd nagios

  3. # ./configure prefix=/usr/local/nagios/

  4. # make all

  5. # make install

  6. # make install-init

  7. # make install-commandmode

  8. # make install-config

  9. # make install-webconf


  10. # chkconfig add nagios

  11. # chkconfig nagios on

  12. # service nagios start

3、装置插件

  1. # tar xf nagios-plugins-1.4.16.tar.gz

  2. # cd nagios-plugins-1.4.16

  3. # ./configure prefix=/usr/local/nagios/ && make && make install


4、修正apache的装备文件

  1. # vim /etc/httpd/conf/httpd.conf


  2. 最终增加如下内容,设置成需求输入暗码才干登陆

  3. ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

  4. <Directory "/usr/local/nagios/sbin">

  5. AuthType Basic

  6. Options ExecCGI

  7. AllowOverride   None

  8. Order allow,deny

  9. Allow from all

  10. AuthName "Nagions Access"

  11. AuthUserFile /usr/local/nagios/etc/htpasswd

  12. Require valid-user

  13. </Directory>


  14. Alias /nagios   "/usr/local/nagios/share"

  15. <Directory "/usr/local/nagios/share">

  16. AuthType Basic

  17. Options None

  18. AllowOverride None

  19. Order allow,deny

  20. Allow from all

  21. AuthName "Nagios Access"

  22. AuthUserFile /usr/local/nagios/etc/htpasswd

  23. Require valid-user

  24. </Directory>

5、装备nagios增加主机,效劳信息
在/usr/local/nagios/etc/objects/下树立2个文件:

  1. (1)hosts.cfg界说主机的文件

  2. define host{

  3. use linux-server

  4. host_name 192.168.163.143

  5. alias 192.168.163.143

  6. address 192.168.163.143

  7. }


  8. (2)services.cfg 界说主机效劳的文件

  9. define service{

  10. use local-service  //引证local-service的特点信息,在template.cfg中界说

  11. host_name 192.168.163.143 //监控那个主机,host-142在hosts.cfg中界说

  12. service_description ssh //对监控内容的描绘

  13. check_command check_ssh //指定监控的指令,check_ping在commands.cfg中界说

  14. }

  15. define service{

  16. use local-service

  17. host_name 192.168.163.143

  18. service_description Ping

  19. check_command check_ping

  20. }


  21. # chown nagios.nagios /usr/local/nagios/etc/objects/{hosts.cfg,services.cfg}

6、树立登陆的用户名暗码
# htpasswd -c  /usr/local/nagios/etc/htpasswd nagiosadmin

7、修正nagios.cfg文件,增加文件途径信息:

  1. cfg_file=/usr/local/nagios/etc/objects/hosts.cfg

  2. cfg_file=/usr/local/nagios/etc/objects/services.cfg

  3. cfg_file=/usr/local/nagios/etc/objects/commands.cfg

  4. cfg_file=/usr/local/nagios/etc/objects/contacts.cfg

  5. cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg

  6. cfg_file=/usr/local/nagios/etc/objects/templates.cfg

8、发动nagios今后拜访输入用户名暗码就能够看到Nagios了

假如发动有问题,能够运用下面的指令查看:
#  /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

四、整合cacti+nagios
整合cacti和nagios是利用了cacti的一个插件nagios for  cacti,它的原理是将nagios的数据经过ndo2db导入到mysql数据库(cacti的库中),然后cacti读取数据库信息将nagios

的成果展现出来。

1、装置php-json扩展,由于NPC运用了ExtJS,如过没有json的扩展NPC界面无法出来。

  1. # tar xf php-json-ext-1.2.1.tar.gz

  2. # cd php-json-ext-1.2.1

  3. # phpize

  4. 假如没有指令的话装置下面的软件包

  5. # rpm -ihv /media/CentOS/php-devel-5.1.6-27.el5.i386.rpm


  6. # sh configure && make && make install

2、新建文件,增加信息如下:

  1. # vim /etc/php.d/json.ini

  2. extension=json.so

装置完成后假如先验证的话,能够写个index.php的页面看下,有json信息即可,如下:

3、装置ndoutils,需求装置mysql-devel前面现已装过这儿就不必再装了

  1. # tar xf ndoutils-1.4b9.tar.gz

  2. # cd ndoutils-1.4b9

  3. # ./configure with-mysql-inc=/usr/include/mysql with-mysql-lib=/usr/lib/mysql enable-mysql with-ndo2db-user=nagioswith-ndo2db-group=nagios

  4. # make(不必make install)

4、仿制文件

  1. # cp src/{ndomod-3x.o,ndo2db-3x,log2ndo,file2sock} /usr/bin/

  2. # cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg

  3. # cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg

  4. # chmod 644 /var/www/html/nagios/etc/ndo*

5、修正装备文件信息,衔接数据库

  1. # vim /usr/local/nagios/etc/ndo2db.cfg

  2. socket_type=tcp

  3. db_host=127.0.0.1

  4. db_port=3306

  5. db_name=cacti

  6. db_prefix=npc_

  7. db_user=cactiadmin

  8. db_pass=cacti321

  9. debug_level=1


  10. # vim /usr/local/nagios/etc/ndomod.cfg

  11. output_type=tcpsocket

  12. output=127.0.0.1

6、增加发动脚本,并修正Ndo2dbBin

  1. # cp /download/ndoutils-1.4b9/daemon-init /etc/init.d/ndo2db

  2. # vim /etc/init.d/ndo2db

  3. Ndo2dbBin=/usr/bin/ndo2db-3x


  4. # chmod +x /etc/init.d/ndo2db

  5. # service ndo2db start

7、装置npc

  1. # tar xf npc-2.0.4.tar.gz

  2. # mv npc /var/www/html/cacti/plugins/


  3. 修正装备文件,增加如下信息

  4. # vim /var/www/html/cacti/include/global.php

  5. $plugins = array();

  6. $plugins[]='npc';

8、修正nagios增加信息:

  1. # vim /usr/local/nagios/etc/nagios.cfg

  2. broker_module=/usr/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg

  3. event_broker_options=-1

# service nagios restar

发动之后在cacti中增加npc,如下:


当拜访到npc这个页面的时分现已擦不多了

9、可是看npc里发现空白的,没有数据,是由于php没有PDO_MYSQL支撑,所以装置PDO_MYSQL

  1. # wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz

  2. # tar zxvf PDO_MYSQL-1.0.2.tgz

  3. # cd PDO_MYSQL-1.0.2

  4. # /usr/local/php/bin/phpize

  5. #./configure with-php-config=/usr/bin/php-config

  6. #make

  7. #make install


  8. 修正php.ini,增加如下信息,之后重启httpd即可

  9. extension = "pdo_mysql.so"

10、之后再拜访还不可,还要修正数据库结构:

  1. # mysql -u root -p

  2. mysql> alter table npc_eventhandlers add long_output TEXT NOT NULL default '' after output;

  3. mysql> alter table npc_hostchecks add long_output TEXT NOT NULL default '' after output;

  4. mysql> alter table npc_hoststatus add long_output TEXT NOT NULL default '' after output;

  5. mysql> alter table npc_notifications add long_output TEXT NOT NULL default '' after output;

  6. mysql> alter table npc_servicechecks add long_output TEXT NOT NULL default '' after output;

  7. mysql> alter table npc_servicestatus add long_output TEXT NOT NULL default '' after output;

  8. mysql> alter table npc_statehistory add long_output TEXT NOT NULL default '' after output;

  9. mysql> alter table npc_systemcommands add long_output TEXT NOT NULL default '' after output;

之后再拜访就可看到有数据了:

到此,cacti+nagios的整合就完事,建立这个的确有很多问题,百度、谷歌才处理,期望能对有的人有协助,假如有问题请及时指出,谢谢~

版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表牛牛娱乐立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章