開源監控系統整合Nagios+Cacti+Nconf+Npc中文版

準備工做

一、關閉iptablesphp

  1. 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

  1. yum install -y httpd-*
  2. yum install -y mysql-*
  3. yum install -y php-*
  4. yum install -y net-snmp*
  5. yum install -y gcc
  6. yum install -y glibc
  7. yum install -y glibc-common       //這個可能安裝glibc的時候已經裝了
  8. yum install -y gd
  9. yum install -y gd-devel
  10. yum install -y openssl*
  11. yum install -y libtool
  12. yum install -y libtool-ltdl              //這個可能安裝libtool的時候已經裝了
  13. yum install -y libtool-ltdl-devel

四、安裝包下載linux

整合Nagios+Cacti+Nconf+Npc中文版安裝包ios

1、nagios環境的搭建

一、安裝nagiosweb

  1. useradd nagios
  2. tar zxf nagios-3.2.0.tar.gz
  3. cd nagios-3.2.0
  4. ./configure -prefix=/var/www/html/nagios
  5. make all
  6. make install && make install-init && make install-commandmode && make install-config && make install-webconf

二、安裝中文的nagiossql

  1. tar xf nagios-cn-3.2.0.tar.bz2
  2. cd nagios-cn-3.2.0
  3. ./configure -prefix=/var/www/html/nagios
  4. make all
  5. make install && make install-init && make install-commandmode && make install-config && make install-webconf

三、增長nagios登錄認證文件,必定要用默認的nagiosadmin做爲用戶數據庫

  1. htpasswd -c /var/www/html/nagios/etc/htpasswd.users nagiosadmin             //設置nagios用戶密碼

不然須要修改/var/www/html/nagios/etc/cgi.cfg這個文件

vi  /etc/nagios/cgi.cfg

  1. authorized_for_system_information=nagiosadmin
  2. authorized_for_configuration_information=nagiosadmin
  3. authorized_for_system_commands=nagiosadmin
  4. authorized_for_all_services=nagiosadmin
  5. authorized_for_all_hosts=nagiosadmin
  6. authorized_for_all_service_commands=nagiosadmin
  7. authorized_for_all_host_commands=nagiosadmin

四、安裝插件

  1. tar xf nagios-plugins-1.4.14.tar.gz
  2. cd nagios-plugins-1.4.14
  3. ./configure -prefix=/var/www/html/nagios/
  4. make
  5. make install

五、將運行Apache的用戶添加到nagios組裏,這樣Apache纔有權限讀取文件

usermod -G nagios apache                         //將apache用戶加到nagios組

六、階段測試

  1. chown nagios.nagios /var/www/html/nagios/ -R
  2. service httpd restart
  3. chkconfig httpd on
  4. /etc/init.d/nagios start
  5. chkconfig nagios on

訪問 http://IP/nagios 看看帳號密碼對不對

20160705091629

2、cacti環境的搭建

一、rrdtool的安裝

這裏須要安裝的是:rrdtool,rrdtool-devel.rrdtool-perl,rrdtool-php, rrdtool-python,下載文章中提供的軟件包,本地rpm安裝。

  1. rpm -ivh --nodeps rrdtool-1.3.8-7.el6.x86_64.rpm
  2. rpm -ivh --nodeps rrdtool-devel-1.3.8-7.el6.x86_64.rpm
  3. rpm -ivh --nodeps rrdtool-perl-1.3.8-7.el6.x86_64.rpm
  4. rpm -ivh --nodeps rrdtool-php-1.3.8-7.el6.x86_64.rpm
  5. rpm -ivh --nodeps rrdtool-python-1.3.8-7.el6.x86_64.rpm
  6. service mysqld start

二、配置snmp

vim /etc/snmp/snmpd.conf

  1. com2sec notConfigUser  127.0.0.1       public
  2. access  notConfigGroup ""      any       noauth    exact  all none none
  3. view all    included  .1                               80
  4. //前兩行是修改最後一行是取消註釋
  1. service snmpd restart
  2. chkconfig snmpd on
  3. snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
  4. IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
  5. IP-MIB::ipAdEntIfIndex.xxx.xxx.xxx.xxx = INTEGER: 2

顯示以上信息,則snmp配置成功,xxx.xxx.xxx.xxx會根據你本機的IP信息配置而不一樣。

三、安裝cacti

  1. tar xf cacti-0.8.7e-cn-utf8.tar.gz
  2. mv cacti-0.8.7e-cn-utf8 /var/www/html/cacti

四、建立cacti數據庫

  1. service mysqld start
  2. chkconfig mysqld on
  3. /usr/bin/mysql_secure_installation       //設置數據庫root密碼,回車-輸入y-輸入兩次密碼-在按4個Y
  4. #mysql -uroot -proot
  5. mysql>create database cacti default character set utf8;       //數據庫字符集設置utf8,不然亂碼
  6. mysql>grant all privileges on cacti.* to cacti@localhost identified by 'cacti' with grant option;
  7. mysql>flush privileges;

五、將cacti的表內容導入建立的數據庫

  1. cd /var/www/html/cacti
  2. mysql -ucacti -pcacti cacti < cacti.sql       //若是mysql版本爲5.5以上須要將cacti.sql裏的TYPE=MyISAM 修改成 ENGINE=MyISAM

六、編輯.php文件,以適應環境

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

修改內容以下

  1. $database_type = "mysql";
  2. $database_default = "cacti";
  3. $database_hostname = "localhost";
  4. $database_username = "cacti";
  5. $database_password = "cacti";
  1. useradd -r -M cacti
  2. chown -R cacti /var/www/html/cacti/rra/
  3. chown -R cacti /var/www/html/cacti/log/

七、在cacti用戶下建立計劃任務以畫圖

  1. yum install -y vixie-cron      //安裝計劃任務,某些系統上可能沒有預裝
  2. chkconfig crond on             //設爲開機啓動
  3. service crond start            //啓動crond
  4. vim /etc/crontab
  5.        //添加
  6.        */5 * * * * root /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1

八、安裝中文字體不然圖像文字上是亂碼

  1. mkdir /ttf
  2. mv ttf-arphic-ukai_0.2.20080216.1.orig.tar.gz /ttf
  3. cd /ttf
  4. tar xf ttf-arphic-ukai_0.2.20080216.1.orig.tar.gz
  5. mv ukai.ttc /usr/share/fonts/ukai.ttc
  6. cd ..
  7. rm -rf ttf/

九、從web頁面啓動cacti,安裝,並查看圖形化界面

瀏覽器訪問:http://localhost/cacti/install/ 安裝

默認登陸用戶:admin   密碼:admin

20160705095444

控制面板 > 設備 > 本機 > SNMP選項 > SNMP 版本 選擇 版本1  > 保存

20160705095615

控制面板 > 設置 > 路徑 > RRDTool默認字體路徑  /usr/share/fonts/ukai.ttc > 保存

20160705095714

若是配置正確,隔幾分鐘,咱們的cacti就會有數據了,如圖,你也能夠手動執行如下命令手動生成rrd圖像

/usr/bin/php /var/www/html/cacti/poller.php --force

20160705110530

3、安裝cacti-spine

一、cacti-spine的安裝

因爲默認cmd.php來輪詢數據,速度會很慢,特別是在監控節點比較多的狀況下,cmd.php就更顯不足了,所以咱們採用Spine來輪詢數據。cacti-spine是一個由C語言開發的,用於替代cmd.php的快速獲取速度的引擎。

  1. tar xf cacti-spine-0.8.7e.tar.gz
  2. cd cacti-spine-0.8.7e
  3. ./configure

//這裏若是出現報錯

configure: error: cannot run /bin/sh config/config.sub

解決步驟

  1. cd config
  2. ll -h
  3. rm -rf config.guess config.sub ltmain.sh
  4. ln -s -f /usr/share/libtool/config/config.sub config.sub
  5. ln -s -f /usr/share/libtool/config/config.guess config.guess
  6. ln -s -f /usr/share/libtool/config/ltmain.sh ltmain.sh
  7. cd ..

在從新運行 ./configure

make

//這裏若是出現錯誤,可能由於你沒有裝 libtool 或者libtool的版本不匹配

20160704164551

先檢查你有沒有安裝libtool 

rpm -qi libtool若是沒有就yum install -y libtool*而後在進行嘗試

若是還不行的

  1. #autoreconf --force --install
  2. #make
  3. #make install

vi /usr/local/spine/etc/spine.conf        //修改訪問數據庫用戶密碼

修改內容以下:

  1. DB_Host         localhost
  2. DB_Database     cacti
  3. DB_User         cacti
  4. DB_Pass         cacti  
  5. 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

  1. tar zxvf ndoutils-1.4b9.tar.gz
  2. cd ndoutils-1.4b9
  3. ./configure -prefix=/var/www/html/nagios -enable-mysql -disable-pgsql -with-mysql-inc=/usr/include/mysql -with-mysql-lib=/usr/lib/mysql
  4. make

二、準備配置文件

  1. cp -v src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /var/www/html/nagios/bin
  2. cd db
  3. ./installdb -ucacti -pcacti -hlocalhost -d cacti
  4. cd ..
  5. cp -v config/{ndo2db.cfg-sample,ndomod.cfg-sample} /var/www/html/nagios/etc
  6. mv /var/www/html/nagios/etc/ndo2db.cfg-sample /var/www/html/nagios/etc/ndo2db.cfg
  7. mv /var/www/html/nagios/etc/ndomod.cfg-sample /var/www/html/nagios/etc/ndomod.cfg
  8. chmod 644 /var/www/html/nagios/etc/ndo*
  9. chown nagios.nagios /var/www/html/nagios/etc/*
  10. chown nagios.nagios /var/www/html/nagios/bin/*

三、修改nagios.cfg配置文件以適應當前環境

  1. vim /var/www/html/nagios/etc/nagios.cfg
  2.      //在文件中添加
  3.      broker_module=/var/www/html/nagios/bin/ndomod-3x.o config_file=/var/www/html/nagios/etc/ndomod.cfg
  4.      //檢查  
  5.      event_broker_options=-1             //爲Nagios開啓event broker 

四、修改ndo2db.cfg以適應當前環境

  1. vim /var/www/html/nagios/etc/ndo2db.cfg
  2.      //確保下列內容爲惟一項
  3.      socket_type=unix
  4.      db_servertype=mysql
  5.      db_host=localhost
  6.      db_port=3306
  7.      db_name=cacti
  8.      db_prefix=nagios_
  9.      db_user=cacti  
  10.      db_pass=cacti

五、修改ndomod.cfg以適應當前環境

  1. vim /var/www/html/nagios/etc/ndomod.cfg
  2.        //確保下列項爲惟一內容
  3.       output_type=unixsocket
  4.       output=127.0.0.1            //去掉註釋

六、爲ndo2db添加啓動進程

  1. cp ./daemon-init /etc/init.d/ndo2db
  2. vim /etc/init.d/ndo2db
  3.        // 並將Ndo2dbBin修改爲下面的值
  4.        Ndo2dbBin=/var/www/html/nagios/bin/ndo2db-3x
  5. 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安裝過程以下:

  1. gunzip cacti-plugin-0.8.7e-PA-v2.5-cn-utf8.diff.gz
  2. mv cacti-plugin-0.8.7e-PA-v2.5-cn-utf8.diff /var/www/html/cacti/
  3. cd /var/www/html/cacti
  4. patch -p1 -N < cacti-plugin-0.8.7e-PA-v2.5-cn-utf8.diff
  5. mysql -ucacti -pcacti cacti < pa.sql

若是你的cacti訪問時候是使用 http://ip/cacti,你須要修改/var/www/html/cacti/include/global.php

修改以下:

  1. $database_type = "mysql";
  2. $database_default = "cacti";
  3. $database_hostname = "localhost";
  4. $database_username = "cacti";
  5. $database_password = "cacti";
  6. $database_port = "3306";
  7.  
  8. $config['url_path'] = '/cacti/';          //記住是修改不是添加

配置Cacti

控制面板 > 用戶管理 > admin > 區域權限,選擇」插件管理」 > 保存

而後咱們就可以在控制面板的」配置」下面看到多出一個」插件管理」的選項

6、安裝NPC 插件

  1. tar zxvf npc-2.0.4.tar.gz
  2. mv npc /var/www/html/cacti/plugins/
  3. vim /var/www/html/cacti/include/config.php
  4.        // 加入
  5.        $plugins[] = 'npc';

20160705153935

一、安裝 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支持

  1. vim /etc/httpd/conf/httpd.conf
  2.        // 添加一行
  3.        AddType application/x-httpd-php .php .phtml
  4.        // 修改原DirectoryIndex內容爲
  5.        DirectoryIndex index.html index.html.var index.php
  6. usermod -G cacti apache
  7. service httpd restart            // 重啓apache以讓php生效 

2)修改配置文件以讓npc讀取到新的數據

  1. vim /var/www/html/nagios/etc/ndo2db.cfg
  2.        //修改
  3.        db_prefix=npc_

3)啓用NPC插件,修改mysql中的表結構

控制面板 > 插件管理 > 安裝 > 啓用

  1. #mysql -ucacti -pcacti -A
  2. mysql> use cacti;
  3. mysql> alter table npc_eventhandlers add long_output TEXT NOT NULL default '' after output;
  4. mysql> alter table npc_hostchecks add long_output TEXT NOT NULL default '' after output;
  5. mysql> alter table npc_hoststatus add long_output TEXT NOT NULL default '' after output;
  6. mysql> alter table npc_notifications add long_output TEXT NOT NULL default '' after output;
  7. mysql> alter table npc_servicechecks add long_output TEXT NOT NULL default '' after output;
  8. mysql> alter table npc_servicestatus add long_output TEXT NOT NULL default '' after output;
  9. mysql> alter table npc_statehistory add long_output TEXT NOT NULL default '' after output;
  10. 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的話。進行操做以下:

  1. vim /var/www/html/nagios/etc/ndomod.cfg
  2.        // 修改
  3.        output_type=tcpsocket
  4. vim /var/www/html/nagios/etc/ndo2db.cfg
  5.        // 修改
  6.        socket_type=tcp

*必定要保證是惟一項,有重複的註釋掉*

7、Nconf的安裝與配置

一、nconf的準備工做

  1. #mysql -uroot -proot
  2. mysql> create database nconf;
  3. mysql> grant all privileges on nconf.* to nconf@localhost identified by 'nconf';
  4. mysql> flush privileges;
  5. mysql> quit

二、安裝nconf

  1. tar -zxf nconf-1.3.0-0.tgz -C /var/www/html/
  2. cd /var/www/html/nconf
  3. chown -R apache.apache config/ temp/ static_cfg/ output/

三、進入Web頁面在web頁面按照安裝提示一步步安裝

http://localhost/nconf/

//使用剛纔建立的nconf數據庫和nconf數據庫用戶/密碼

到下圖中這個頁面設置登陸用戶密碼

20160706111013

四、成功鏈接mysql數據庫以後一切保持默認,直到下面的,設置nconf管理員密碼,此時默認登陸用戶爲admin

五、網頁安裝完成後

  1. rm -rf INSTALL INSTALL.php  UPDATE UPDATE.php      //刪除安裝所需的初始化文件
  2. ln -s /var/www/html/nagios/bin/nagios bin/nagios
  3. chmod +x /var/www/html/nconf/bin/generate_config.pl
  4. chown -R apache.apache  bin
  5. chmod +x /var/www/html/nagios/bin/nagios
  6. chmod +x /var/www/html/nconf/ADD-ONS/deploy_local.sh
  7. vim /var/www/html/nconf/ADD-ONS/deploy_local.sh
  8.        //修改NAGIOS_DIR路徑
  9.        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主配置文件

  1. vim /var/www/html/nagios/etc/nagios.cfg
  2.        //將其中cfg_file=*******字段所有註釋 ,並加入 
  3.        cfg_dir=/var/www/html/nagios/etc/Default_collector
  4.        cfg_dir=/var/www/html/nagios/etc/global
  5. service nagios reload               //重載nagios配置文件使之生效

若是生成Nagios配置文件沒問題的話,就能夠執行如下腳本使Nagios配置生效:

#/var/www/html/nconf/ADD-ONS/deploy_local.sh

想實現Nconf點生成使Nagios配置文件當即生效的,請查看下面這篇文章!

Nconf點生成使Nagios配置文件當即生效

相關文章
相關標籤/搜索