準備工做
一、關閉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配置文件當即生效