监控系统安装配置文档(Nagios+Cacti+Nconf)
# yum install -y httpd gcc glibc glibc-common gd gd-devel php php-gd ntp
2.安裝nagios# 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
2.增加nagios登陸認證文件,一定要用默認的nagiosadmin作為用戶,否則需要修改其他文件。# htpasswd -c /var/www/html/nagios/etc/htpasswd.users nagiosadmin
3. 安裝插件:# wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz
# tar -xf nagios-plugins-1.4.15.tar # cd nagios-plugins-1.4.15 # ./configure --prefix=/var/www/html/nagios/ # make # make install 4.將運行Apache的用戶添加到nagios組里,這樣Apache才有權限讀取文件 # usermod -G nagios apache??? //將apache用戶加到nagios組。 5.階段測試 # chown nagios.nagios /var/www/html/nagios/ -R # service httpd restart # chkconfig httpd on? # /etc/init.d/nagios start 二:cacti環境的搭建 1.rrdtool的安裝,這里需要安裝的是:rrdtool,rrdtool-devel.rrdtool-perl,rrdtool-php # yum localinstall -y --nogpgcheck rrdtool-* # service mysqld start 2.配置snmp # vim /etc/snmp/snmp.conf 修改3項?127.0.0.1 、 all、啟用項 # service snmpd restart 3.安裝cacti# 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 4.創建cacti數據庫 mysql> create database cacti;mysql> grant all on cacti.* to 'cacti'@'localhost' identified by 'cacti';
mysql> flush privileges; 5.將cacti的表內容導入創建的數據庫 # cd /var/www/html/cacti # mysql -ucacti -pcacti cacti < /var/www/html/cacti/cacti.sql 6.分別編輯兩個.php文件,以適應環境,修改內容相同。 # 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/ 7.在cacti用戶下創建計劃任務以畫圖 # su cacti # crontab –e??????????????? */1 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1
# php /var/www/html/cacti/poller.php > /dev/null 2>&1
# exit 8.從web頁面啟動cacti,安裝,并查看圖形化界面 三:整合Nagios與Cacti 1.下載并安裝ndoutils# 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 2.準備配置文件# 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/* 3.修改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 4.修改ndo2db.cfg以適應當前環境 # 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 5.修改ndomod.cfg以適應當前環境 # vim /var/www/html/nagios/etc/ndomod.cfg output_type=tcpsocket output=127.0.0.1 6.為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 7.啟動守護進程# /var/www/html/nagios/bin/ndo2db-3x -c /var/www/html/nagios/etc/ndo2db.cfg
# tail -20 /var/log/messages??? //查看其中是否有錯誤出現 添加開機自動啟動# echo "/var/www/html/nagios/bin/ndo2db-3x -c /var/www/html/nagios/etc/ndo2db.cfg" >> /etc/rc.local
# service nagios restart 四:安裝ncp,以在Cacti中展現Nagios 1.先安裝cacti擴展模塊# 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/";
從web進入cacti,啟用cacti plugin擴展
2.安裝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';
3.安裝 npc支持:json# 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?查看是否有導入信息 4.打開php.ini文件添加對json的支持 # vim /etc/php.ini 添加 extension=json.so 5.為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生效?????????????????? # php -m????????????????????????????????????????????? //查看是否有json被加載 6.修改配置文件以讓npc讀取到新的數據。 # vim /var/www/html/nagios/etc/ndo2db.cfg db_prefix=npc_ 6.1 從Web進入Cacti,確保正確使用npc選項。 6.2 修改mysql中的表結構: ./mysql -ucacti -p cactialter table npc_eventhandlers add long_output TEXT NOT NULL default '' after output;
alter table npc_hostchecks add long_output TEXT NOT NULL default '' after output;
alter table npc_hoststatus add long_output TEXT NOT NULL default '' after output;
alter table npc_notifications add long_output TEXT NOT NULL default '' after output;
alter table npc_servicechecks add long_output TEXT NOT NULL default '' after output;
alter table npc_servicestatus add long_output TEXT NOT NULL default '' after output;
alter table npc_statehistory add long_output TEXT NOT NULL default '' after output;
alter table npc_systemcommands add long_output TEXT NOT NULL default '' after output;
7.重啟ndo2db進程,重新加載配置文件重啟nagios服務。 # service ndo2db restart # service nagios restart 8.在Web上配置NPC以使之正常讀取工作。在Settings->npc中 ,勾上Remote Commands
Nagios Command File Path= /var/www/html/nagios/var/rw/nagios.cmd
Nagios URL=你的地址(http://ocalhost/nagios/) 接下來刷新npc就可以看到數據 五:nconf的安裝與配置 首先對mysql數據庫進行定義 mysql> create database nconf;?mysql> grant all privileges on nconf.* to nconf@localhost identified by 'nconf';
mysql> flush privileges;?? mysql>quit 下載與安裝nconf# 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/
進入web,開始安裝 http://您nagios監控端的IP/nconf 在web頁面按照安裝提示一步步安裝 使用剛才創建的nconf數據庫和nconf數據庫用戶/密碼 輸入用于通過nconf生成nagios配置文件所需的nconf路徑和nagios命令路徑 設置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-ONE/deploy_local.sh 修改里面的nagios為我們nagios的安裝路徑/var/www/html/nagios 重新刷新頁面,輸入admin/您設置的密碼,進入nconf頁面點擊Generate Nagios config嘗試生成配置文件,以測試是否與nagios成功關聯
注意:nconf在點擊【Generate Nagios config】后將您的生成nagios配置文件是/var/www/html/nconf/output/NagiosConfig.tgz,而并非直接導入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.cf 將其中cfg_file=*******字段全部注釋 ,并加入cfg_dir=/var/www/html/nagios/etc/Default_collector
cfg_dir=/var/www/html/nagios/etc/global
# service nagios reload 重載nagios配置文件使之生效 六:問題跟蹤: 1.啟動ndo2db發現日志報錯: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轉載于:https://blog.51cto.com/yyy3y/727964
總結
以上是生活随笔為你收集整理的监控系统安装配置文档(Nagios+Cacti+Nconf)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JAVA多线程同步
- 下一篇: Jquery $ 符号讲解