CentOS 6.0+Nagios中文版+PNP+Nagios Web管理工具nagiosQL中文版
按照網(wǎng)上一篇文檔實(shí)踐搭建了nagios監(jiān)控系統(tǒng), 學(xué)習(xí)交流,原文地址:http://zhumeng8337797.blog.163.com/blog/static/1007689142011101551756386/
一、安裝CentOS6.0 64位系統(tǒng)
二、執(zhí)行
1.yum -y install httpd gettext mysql mysql-server mysql-devel php php-mysql php-pear
2.yum install php-mysql mysql perl mysql-server perl-DBI perl-DBD-MySQL httpd gcc glibc glibc-common gd gd-devel php
三、下載安裝包
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz (現(xiàn)在最新版本的插件)
wget http://sourceforge.net/projects/nagios-cn/files/sourcecode/zh_CN%203.2.3/nagios-cn-3.2.3.tar.bz2/download
四、用戶和組的準(zhǔn)備
useradd nagios
passwd nagios
usermod -s /sbin/nologin nagios
uroupadd nagcmd
usermod -G nagcmd nagios
usermod -G nagcmd apache
五、開始安裝程序
解壓:tar -jxvf nagios-cn-3.2.3.tar.bz2
編譯安裝:cd nagios-cn-3.2.3
yum -y install gcc automake autoconf libtool make
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
安裝插件:
tar zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make insall
添加訪問頁面用戶nagiosadmin及密碼,這里要記住此密碼不要忘記了.(nagios 123456)
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
設(shè)置相關(guān)服務(wù)開機(jī)啟動
[root@localhost nagios-cn-3.2.3]#service nagios start
[root@localhost nagios-cn-3.2.3]#chkconfig --add nagios
[root@localhost nagios-cn-3.2.3]# chkconfig nagios on
[root@localhost nagios-cn-3.2.3]# chkconfig httpd on
[root@localhost nagios-cn-3.2.3]# chkconfig mysqld on
檢查配置文件是否正確
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
沒有錯(cuò)誤,表示通過。
現(xiàn)在可以通過http://IP/nagios訪問控制臺
六.安裝nrpe插件
[nrpe_plugins指標(biāo)采集程序主要是用來分析nrpe客戶端的plugin腳本采集性能指 標(biāo)數(shù)據(jù)。目前實(shí)現(xiàn)的有cpu、memory、disk、buffer、singleprocess、oracle、sybase等方面的性能指標(biāo)的分析, 這個(gè)插件需要分別安裝在主控端和被控端上,這個(gè)插件需要openssl的支持,沒有就直接在線安裝一下(yum install openssl-devel)所以還需在nagios主機(jī)和被控端安裝,感覺挺麻煩,沒辦法它需要咱們就跟著做哈.]
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
yum install openssl-devel (提示已經(jīng)安裝)
./configure
make && make install
完成以后沒有出錯(cuò)就可以看到以下生成的文件了
接下來按如下操作
mkdir /usr/local/nagios/etc
cp sample-config/nrpe.cfg /usr/local/nagios/etc/
cp init-script /etc/init.d/nrpe
chmod +x /etc/init.d/nrpe
啟動nrpe :service nrpe start
七、配置PNP
[PNP是一個(gè)基于php和perl,用rrdtool將nagios采集的數(shù)據(jù)繪制圖表的工具,所以安裝pnp之前必須先安裝php perl and rrdtool這里用yum直接來安裝rrdtool,單獨(dú)下載安裝有很多依存關(guān)系,挺麻煩.]
yum install rrdtool
wget http://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.15.tar.gz/download
tar zxvf pnp4nagios-0.6.15.tar.gz
cd pnp4nagios-0.6.15
./configure
報(bào)錯(cuò):
執(zhí)行:yum install perl-Time-HiRes
繼續(xù)編譯
make all
make install
根據(jù)提示
make install-webconf
make install-config
make install-init
然后把相關(guān)后綴帶sample文件變更成無sample后綴
[root@localhost pnp4nagios-0.6.15]# cd /usr/local/pnp4nagios/etc/
[root@localhost etc]# mv misccommands.cfg-sample misccommands.cfg
[root@localhost etc]# mv nagios.cfg-sample nagios.cfg
[root@localhost etc]# mv rra.cfg-sample rra.cfg
[root@localhost etc]# cd pages/
[root@localhost pages]# mv web_traffic.cfg-sample web_traffic.cfg
[root@localhost pages]# cd ../check_commands/
[root@localhost check_commands]# mv check_all_local_disks.cfg-sample check_all_local_disks.cfg
[root@localhost check_commands]# mv check_nrpe.cfg-sample check_nrpe.cfg
[root@localhost check_commands]# mv check_nwstat.cfg-sample check_nwstat.cfg
配置Nagios來啟用PNP
cd /usr/local/nagios/etc
vi nagios.cfg
pnp4nagios有很多種工作模式,這里我們選用同步模式,想選其它模式可以看說明都有詳細(xì)配置教程(不同模式配置不同)
這里我們按說明的設(shè)定方法來做
[這里先把pnp4nagios執(zhí)行數(shù)據(jù)收集的文件拷貝到nagios的libexec下,方便統(tǒng)一命令的執(zhí)行路徑.]
cp /usr/local/pnp4nagios/libexec/process_perfdata.pl /usr/local/nagios/libexec/
然后在commands.cfg里面加入如下(這里是同步模式設(shè)定方法)
cd /usr/local/nagios/etc/objects
vi commands.cfg
添加內(nèi)容并注釋掉原來的
#process-host-perfdata' command definition
define command{
command_name process-host-perfdata
command_line $USER1$/process_perfdata.pl -d HOSTPERFDATA
}
#process-service-perfdata' command definition
define command{
command_name process-service-perfdata
command_line $USER1$/process_perfdata.pl
}
然后添加小太陽模版,鑲嵌在nagios頁面上
[這里有兩種查看圖的方法,第一種方法是你當(dāng)太陽的圖標(biāo)的時(shí)候會在新窗口中打開圖形查看,第二種方法是你只需要把鼠標(biāo)移動到太陽圖標(biāo)上面就會自動彈出圖形出來,以下兩種方法你可以根據(jù)自己喜好選其中一種即可]
第一種方法在templates.cfg里面加入如下
vi templates.cfg
添加內(nèi)容:
define host {
name host-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
register 0
}
define service {
name srv-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}
為目標(biāo)主機(jī)圖標(biāo)旁邊添加一個(gè)小太陽標(biāo)記
vi localhost.cfg
為相關(guān)服務(wù)添加一個(gè)小太陽標(biāo)記
訪問http://IP/pnp3nagios,有一項(xiàng)出錯(cuò)
yum install php* -y
重啟后解決
按要求重命名install.php
cd /usr/local/pnp4nagios/share/
mv install.php install.php.bak
刷新網(wǎng)頁:
重啟nagios:service nagios restart
ok,到此總算配置好了PNP
八.Nagios WEB管理工具叫NagiosQL(注:還有同樣一個(gè)Nagios WEB管理工具叫Nconf)
下載安裝包:wget http://sourceforge.net/projects/nagiosql/files/nagiosql/NagiosQL%203.1.1/nagiosql_311.tar.gz/download
NagiosQL是一個(gè)WEB管理工具,只要把其放到下Apache即可。因?yàn)檫@里它要和Nagios整合到一起,為了方便管理,把其放在Nagios目錄下
tar zxvf nagiosql_311.tar.gz
mv nagiosql /usr/local/nagios/
建立nagiosQL導(dǎo)出nagios配置文件的目錄,并修改權(quán)限
建目錄和改權(quán)限
mkdir -p /etc/nagiosql/{hosts,services,backup/{,hosts,services},import}
chown -R apache:nagios /etc/nagiosql/
chmod -R 755 /etc/nagiosql
chmod 777 /usr/local/nagios/nagiosql/config
Nagios相關(guān)文件權(quán)限的設(shè)定
chown nagios:apache /usr/local/nagios/etc
chown nagios:apache /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}
chown nagios:apache /usr/local/nagios/etc/*
chmod 664 /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}
chmod 775 /usr/local/nagios/etc
設(shè)定nagios二進(jìn)制文件的權(quán)限,以便其能夠通過Web程序執(zhí)行
chown nagios:apache /usr/local/nagios/bin/nagios
chmod 750 /usr/local/nagios/bin/nagios
chown -R apache.nagios /usr/local/nagios/var/spool/
chown nagios:apache /usr/local/nagios/var/rw/nagios.cmd
chmod 660 /usr/local/nagios/var/rw/nagios.cmd
為apache添加nagiosQL虛擬目錄
vi /etc/httpd/conf.d/nagios.conf
#add virture directory for nagiossql
Alias /nagiosQL "/usr/local/nagios/nagiosql"
<Directory "/usr/local/nagios/nagiosql">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
重新加載httpd服務(wù)和啟動mysqld服務(wù)
service httpd reload
service mysqld restart
建立nagiosql安裝文件
touch /usr/local/nagios/nagiosql/install/ENABLE_INSTALLER
訪問http://ip/nagiosQL進(jìn)行安裝
開始安裝,測試環(huán)境通過,下一步
輸入mysql 密碼,設(shè)置nagiosQL默認(rèn)登錄密碼
刪除安裝目錄,這里使用改權(quán)限:chmod 000 /usr/local/nagios/nagiosql/install
完成安裝
管理-域-localhost---點(diǎn)“修改”
按如圖修改
工具-導(dǎo)入數(shù)據(jù) 右邊會列出一些配置文件,選擇導(dǎo)入即可。
導(dǎo)入只是把配置文件內(nèi)容導(dǎo)入到Mysql數(shù)據(jù)庫,而使用其配置文件時(shí),是一個(gè)個(gè)cfg文件,所以下面要進(jìn)行寫入過程
工具-nagios控制-寫入檢測數(shù)據(jù)-寫入其他數(shù)據(jù)
檢查配置文件成功
重新啟動nagios
寫入之后就可以看到相應(yīng)的cfg文件了,查看寫入是否成功,由下面的輸出可以看出寫入是成功滴.
修改nagios的配置文件,將原有以cfg_file開頭項(xiàng)全部注釋掉,加入上面新寫入的配置文件
vi /usr/local/nagios/etc/nagios.cfg
注釋掉
加入新的配置文件路徑
cfg_dir=/etc/nagiosql/hosts/
cfg_dir=/etc/nagiosql/services/
cfg_file=/etc/nagiosql/commands.cfg
cfg_file=/etc/nagiosql/contactgroups.cfg
cfg_file=/etc/nagiosql/contacts.cfg
cfg_file=/etc/nagiosql/contacttemplates.cfg
cfg_file=/etc/nagiosql/hostdependencies.cfg
cfg_file=/etc/nagiosql/hostescalations.cfg
cfg_file=/etc/nagiosql/hostextinfo.cfg
cfg_file=/etc/nagiosql/hostgroups.cfg
cfg_file=/etc/nagiosql/hosttemplates.cfg
cfg_file=/etc/nagiosql/servicedependencies.cfg
cfg_file=/etc/nagiosql/serviceescalations.cfg
cfg_file=/etc/nagiosql/serviceextinfo.cfg
cfg_file=/etc/nagiosql/servicegroups.cfg
cfg_file=/etc/nagiosql/servicetemplates.cfg
cfg_file=/etc/nagiosql/timeperiods.cfg
檢查nagios的配置文件是否有問題,然后生重啟nagios服務(wù),至此整個(gè)搭建過程終于完成了
后面續(xù)上添加監(jiān)控主機(jī)。