您好,登錄后才能下訂單哦!
系統(tǒng):CentOS6.5 內(nèi)核版本系統(tǒng):2.6.32-431.23.3.el6.x86_64
關(guān)閉iptables 、selinux
chkconfig iptables off
安裝前的準(zhǔn)備工作
yum install -y httpd-* mysql-* php-* net-snmp* gcc glibc glibc-common gd gd-devel openssl*
一、nagios 環(huán)境的搭建
1.安裝nagios
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
2.安裝中文的nagios
這個(gè)比較簡(jiǎn)單就跟打補(bǔ)丁一樣
tar zxf 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
3.增加nagios登陸認(rèn)證文件,一定要用默認(rèn)的nagiosadmin作為用戶
htpasswd -c /var/www/html/nagios/etc/htpasswd.users nagiosadmin
*否則需要修改/var/www/html/nagios/etc/cgi.cfg這個(gè)文件
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
4.安裝插件:
tar xf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
./configure -prefix=/var/www/html/nagios/
make
make install
5.將運(yùn)行Apache的用戶添加到nagios組里,這樣Apache才有權(quán)限讀取文件
usermod -G nagios apache ##將apache用戶加到nagios組。
6.階段測(cè)試
chown nagios.nagios /var/www/html/nagios/ -R
service httpd restart
chkconfig httpd on
/etc/init.d/nagios start
*問http://IP/nagios 看看賬號(hào)密碼對(duì)不對(duì)
二:cacti環(huán)境的搭建
1.rrdtool的安裝
這里需要安裝的是:rrdtool,rrdtool-devel.rrdtool-perl,rrdtool-php, rrdtool-python我用的rrdtools的版本是 1.3.8-7.el6.x86_64,由于我用的是阿里云yum里有rrdtool 所以我就直接yum install rrdtool* 來(lái)進(jìn)行安裝
rrdtool-devel-1.3.8-7.el6.x86_64
rrdtool-perl-1.3.8-7.el6.x86_64
rrdtool-1.3.8-7.el6.x86_64
rrdtool-php-1.3.8-7.el6.x86_64
rrdtool-python-1.3.8-7.el6.x86_64
如果沒有自行下載。下載完成后,本地yum安裝。(百度云里面有1.4的)
yum localinstall -y --nogpgcheck rrdtool-*
service mysqld start
2.配置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
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
IP-MIB::ipAdEntIfIndex.xxx.xxx.xxx.xxx = INTEGER: 3
顯示以上信息,則snmp配置成功,xxx.xxx.xxx.xxx會(huì)根據(jù)你本機(jī)的IP信息配置而不同。
3.安裝cacti
cacti-0.8.7e-cn-utf8.tar.gz
mv cacti-0.8.7e-cn-utf8 /var/www/html/cacti
4.創(chuàng)建cacti數(shù)據(jù)庫(kù)
#mysql
mysql>create database cacti default character set utf8; //數(shù)據(jù)庫(kù)字符集設(shè)置utf8,否則亂碼
mysql>grant all privileges on cacti.* to cacti@localhost identified by ‘cacti’ with grant option;
mysql>flush privileges;
5.將cacti的表內(nèi)容導(dǎo)入創(chuàng)建的數(shù)據(jù)庫(kù)
cd /var/www/html/cacti
mysql -ucacti -pcacti cacti < cacti.sql
6.編輯.php文件,以適應(yīng)環(huán)境。
vim /var/www/html/cacti/include/config.php
修改內(nèi)容如下
$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/
7.在cacti用戶下創(chuàng)建計(jì)劃任務(wù)以畫圖
vim /etc/crontab
*/5 * * * * root php /var/www/html/cacti/poller.php &>/dev/null
php /var/www/html/cacti/poller.php > /dev/null 2>&1
8.安裝中文字體否則圖像文字上是亂碼
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
rm –rf /ttf
9.從web頁(yè)面啟動(dòng)cacti,安裝,并查看圖形化界面
控制面板 > 設(shè)備 > 本機(jī) > SNMP選項(xiàng) > SNMP 版本 選擇 版本1 > 保存
控制面板 > 設(shè)置 > 路徑 > RRDTool默認(rèn)字體路徑 /usr/share/fonts/ukai.ttc > 保存
如果配置正確,隔幾分鐘,我們的cacti就會(huì)有數(shù)據(jù)了,如圖,你也可以手動(dòng)執(zhí)行以下命令手動(dòng)生成rrd圖像
php /var/www/html/cacti/poller.php
SNMP 版本號(hào)
字體路徑
中文的圖表
三:安裝cacti-spine
1. cacti-spine的安裝
由于默認(rèn)cmd.php來(lái)輪詢數(shù)據(jù),速度會(huì)很慢,特別是在監(jiān)控節(jié)點(diǎn)比較多的情況下,cmd.php就更顯不足了,因此我們采用Spine來(lái)輪詢數(shù)據(jù)。cacti-spine是一個(gè)由C語(yǔ)言開發(fā)的,用于替代cmd.php的快速獲取速度的引擎。
tar xf cacti-spine-0.8.7e.tar.gz
cd cacti-spine-0.8.7e
./configure
#make && make install
vi /usr/local/spine/etc/spine.conf
修改內(nèi)容如下:
DB_Host localhost
DB_Database cacti
DB_User cacti
DB_Pass cacti
DB_Port 3306
/usr/local/spine/bin/spine
echo /usr/local/spine/bin/spine >>/etc/rc.d/rc.local
*如果你直接成功了那么恭喜你請(qǐng)直接看2.cacti-spine的應(yīng)用,如果出現(xiàn)報(bào)錯(cuò)*
[root@iZ2314cchhjZ cacti-spine-0.8.7e]# ./configure
configure: error: cannot run /bin/sh config/config.sub
[root@iZ2314cchhjZ cacti-spine-0.8.7e]#
解決步驟
cd cacti-spine-0.8.7e/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
make install
vi /usr/local/spine/etc/spine.conf
修改內(nèi)容如下:
DB_Host localhost
DB_Database cacti
DB_User cacti
DB_Pass cacti
DB_Port 3306
/usr/local/spine/bin/spine
echo /usr/local/spine/bin/spine >>/etc/rc.d/rc.local
*如果你make 成功了請(qǐng)忽略這里*
這時(shí)候你make 報(bào)錯(cuò),這是因?yàn)槟憧赡軟]有裝 libtool 或者libtool的版本不匹配
./libtool: line 467: CDPATH: command not found
./libtool: line 1145: func_opt_split: command not found
libtool: Version mismatch error. This is libtool 2.2.6b, but the
libtool: definition of this LT_INIT comes from an older release.
libtool: You should recreate aclocal.m4 with macros from libtool 2.2.6b
libtool: and run autoconf again.
make: *** [spine] 錯(cuò)誤 63
先檢查你有沒有安裝libtool 如果沒有就yum install libtool* 然后在進(jìn)行嘗試
如果還不行的
[root@iZ2314cchhjZ cacti-spine-0.8.7e]# autoreconf --force --install
[root@iZ2314cchhjZ cacti-spine-0.8.7e]# make
make install
vi /usr/local/spine/etc/spine.conf
修改內(nèi)容如下:
DB_Host localhost
DB_Database cacti
DB_User cacti
DB_Pass cacti
DB_Port 3306
/usr/local/spine/bin/spine
echo /usr/local/spine/bin/spine >>/etc/rc.d/rc.local
2.cacti-spine的應(yīng)用
控制面板 > 設(shè)置 > 路徑 > Spine輪詢器路徑 /usr/local/spine/bin/spine
控制面板 > 設(shè)置 > 輪詢器 > 輪詢器類型 spine
四:整合Nagios與Cacti
1.下載并安裝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
2.準(zhǔn)備配置文件
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配置文件以適應(yīng)當(dāng)前環(huán)境
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以適應(yīng)當(dāng)前環(huán)境
vim /var/www/html/nagios/etc/ndo2db.cfg
# 確保下列內(nèi)容為唯一項(xiàng)
socket_type=unix
db_servertype=mysql
db_host=localhost
db_port=3306
db_name=cacti
db_prefix=nagios_
db_user=cacti
db_pass=cacti
5.修改ndomod.cfg以適應(yīng)當(dāng)前環(huán)境
vim /var/www/html/nagios/etc/ndomod.cfg
# 確保下列項(xiàng)的唯一內(nèi)容為
output_type=unixsocket
output=127.0.0.1
6.為ndo2db添加啟動(dòng)進(jìn)程
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.啟動(dòng)守護(hù)進(jìn)程與nagios
service ndo2db start
tail -20 /var/log/messages ## 查看其中是否有錯(cuò)誤出現(xiàn)。如無(wú)報(bào)錯(cuò)請(qǐng)繼續(xù)
service nagios restart
五:安裝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/cacti/
cd /var/www/html/cacti
mysql -ucacti -pcacti cacti < pa.sql
patch -p1 -N < cacti-plugin-0.8.7e-PA-v2.5-cn-utf8.diff
如果你的cacti訪問時(shí)候是使用http://ip/cacti,你需要修改/var/www/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 > 區(qū)域權(quán)限,選擇”插件管理” > 保存
然后我們就能夠在控制面板的”配置”下面看到多出一個(gè)”插件管理”的選項(xiàng)
六:安裝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';
1.安裝 npc支持:json (看情況進(jìn)行安裝)
先使用這條命令看看PHP里有沒有JSON的模塊php -m | grep json如果有了就略過。
tar zxvf json-1.2.1.tgz
cd json-1.2.1
phpize ## 如果發(fā)現(xiàn)沒有Phpize文件,則是因?yàn)閜hp-devel包沒有安裝導(dǎo)致的
./configure
make && make install
php -i | grep php.ini ## 查看是否有導(dǎo)入信息
打開php.ini文件添加對(duì)json的支持
vim /etc/php.ini
# 添加
extension=json.so
php -m ## 查看是否有json被加載
2.配置npc基本環(huán)境
一.為apache添加php支持。
vim /etc/httpd/conf/httpd.conf
# 添加一行:
AddType application/x-httpd-php .php .phtml
# 修改原DirectoryIndex內(nèi)容為:
DirectoryIndex index.html index.html.var index.php
usermod -G cacti apache
service httpd restart ## 重啟apache以讓php生效
學(xué)神科技有限公司Linux講師:top 聯(lián)系QQ 3059942361 想要深入學(xué)習(xí)Linux系統(tǒng)架構(gòu)師,可以隨時(shí)與我聯(lián)系
二.修改配置文件以讓npc讀取到新的數(shù)據(jù)。
vim /var/www/html/nagios/etc/ndo2db.cfg
db_prefix=npc_
三. 修改mysql中的表結(jié)構(gòu):
#mysql -ucacti -pcacti
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;
四.重啟ndo2db進(jìn)程,重新加載配置文件重啟nagios服務(wù)。
service ndo2db restart
service nagios restart
五.在Web上配置NPC以使之正常讀取工作。
控制面板 > 插件管理 > 安裝 > 啟用
控制面板 > 設(shè)置 > NPC
Nagios Command File Path= /var/www/html/nagios/var/rw/nagios.cmd
Nagios URL=你的地址(http://101.200.175.24/nagios)
接下來(lái)刷新npc就可以看到數(shù)據(jù)啦
如果你點(diǎn)開NPC的時(shí)候狀態(tài)是OFF的話。進(jìn)行操作如下:
vim /var/www/html/nagios/etc/ndomod.cfg
# 修改
output_type=tcpsocket
vim /var/www/html/nagios/etc/ndo2db.cfg
# 修改
socket_type=tcp
*一定要保證是唯一項(xiàng)*
七:Nconf的安裝與配置
1.nconf的準(zhǔn)備工作
#mysql
mysql> create database nconf;
mysql> grant all privileges on nconf.* to nconf@localhost identified by ‘nconf’;
mysql> flush privileges;
mysql> quit
2.安裝nconf
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/
3.進(jìn)入Web頁(yè)面在web頁(yè)面按照安裝提示一步步安裝
*使用剛才創(chuàng)建的nconf數(shù)據(jù)庫(kù)和nconf數(shù)據(jù)庫(kù)用戶/密碼
4.成功連接mysql數(shù)據(jù)庫(kù)之后一切保持默認(rèn),直到下面的,設(shè)置nconf管理員密碼,此時(shí)默認(rèn)登錄用戶為admin
5.之后,網(wǎng)頁(yè)安裝完成。
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/
6.重新刷新網(wǎng)頁(yè)
7.點(diǎn)擊Generate Nagios config嘗試生成配置文件,以測(cè)試是否與nagios成功關(guān)聯(lián)
8.最后的設(shè)置
一.在web頁(yè)面對(duì)監(jiān)控服務(wù)和主機(jī)配置完畢,點(diǎn)擊Generate Nagios config
二.deploy_local.sh是nconf自帶配置文件導(dǎo)入腳本
/var/www/html/nconf/ADD-ONS/deploy_local.sh
手動(dòng)執(zhí)行此腳本,將在/var/www/html/nagios/etc下生成兩目錄Default_collector與global
三.修改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配置文件使之生效
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。