您好,登錄后才能下訂單哦!
安裝
server 192.168.12.145
client 192.168.12.144
服務(wù)器端安裝
nagios-3.3.1.tar.gz
nagios-plugins-1.4.5
安裝環(huán)境
yum install httpd gcc gcc-c++ openssl openssl-devel perl
添加nagios用戶和組
useradd nagios ##若是指定-s 為nologin,則重啟nagios的時(shí)候可能會(huì)報(bào)錯(cuò),但是不影響功能
groupadd nagcmd
usermod -G nagcmd nagios
usermod -G nagcmd apache
安裝nagios
tar -xf nagios-2.2.1.tar.gz -C /usr/local/src
cd /usr/local/src/nagios-2.2.1
./configure --with-command-group=nagcmd
make all
make install ##安裝主程序
make install-init ##安裝啟動(dòng)腳本
make install-config ##創(chuàng)建配置文件
make install-commandmode ##配置目錄權(quán)限
make install-webconf
定義聯(lián)系人
vi /usr/local/nagios/etc/objects/contacts.cfg
定義聯(lián)系人和組
創(chuàng)建一個(gè)用戶用于在web頁面登陸nagios
htpasswd -c /usr/locl/nagios/etc/httpasswd.user nagiosadmin
重啟apache
chown -R nagios:nagios /usr/local/nagios/etc/htpasswd.users
若權(quán)限不對可能造成web界面沒有權(quán)限打開該文件,造成無法登陸
編輯http.conf配置文件
scriptAlias "/nagios/cgi-bin""/usr/local/nagios/sbin"
<Directory"/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users ##此處為之前建的用戶認(rèn)證文件位置
Require valid-user
</Directory>
Alias /nagios"/usr/local/nagios/share"
<Directory"/usr/local/nagios/share">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
重啟apache
安裝nagios-plugins-1.4.15
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make && make install
驗(yàn)證配置文件是否有錯(cuò)
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
關(guān)閉selinux
在瀏覽器輸入http://ip/nagios 輸入htpasswd命令生成的賬戶密碼即可以訪問
注意點(diǎn):php是否安裝 apache是否加載了php模塊
錯(cuò)誤:
apache access.log
10.13.115.1 - nagiosadmin[26/Jun/2011:13:01:10 +0800] "GET /nagios/side.php HTTP/1.1" 304
10.13.115.1- nagiosadmin [26/Jun/2011:13:01:10 +0800] "GET /nagios/p_w_picpaths/sblogo.pngHTTP/1.1" 304 –
10.13.115.1- nagiosadmin [26/Jun/2011:13:01:10 +0800] "GET/nagios/stylesheets/common.css HTTP/1.1" 304
10.13.115.1- nagiosadmin [26/Jun/2011:13:01:10 +0800] "GET/nagios/p_w_picpaths/greendot.gif HTTP/1.1" 304
apace error.log
[notice]Apache/2.2.19 (Unix) DAV/2 configured -- resuming normal operations
[error][client xx.xx.115.1] Directory index forbidden by Options directive: /usr/local/nagios/share
[error][client xx.xx.115.1] Directoryindex forbidden by Options directive: /usr/local/nagios/share
[error][client xx.xx.115.1] Directoryindex forbidden by Options directive: /usr/local/nagios/share
[error][client xx.xx.115.1] Directoryindex forbidden by Options directive: /usr/local/nagios/share
[error][client xx.xx.115.1] Directoryindex forbidden by Options directive: /usr/local/nagio/share
解決辦法:
php頁面無法被apache解析
解決:
在apache的配置文件httpd.conf修改
第一步:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
改成
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
第二步:
增加如下內(nèi)容,記得裝php
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php .phtml
AddType applicatoin/x-httpd-php-source .phps
問題2
輸入賬戶密碼無法登陸
查看apache配置文件添加的用戶認(rèn)證那一段
查看/usr/localnagios/etc/下面的用戶賬戶密碼文件htpasswd.users
發(fā)現(xiàn)apache的用戶和nagios下面的用戶文件名不一致,修改其中一個(gè)即可
問題3
[Tue Jan 27 01:51:51 2015] [error] [client 127.0.0.1] Directory index forbidden by Options directive: /var/www/html/
[Tue Jan 27 01:51:51 2015] [error] [client 192.168.12.27] (13)Permission denied: exec of '/usr/local/nagios/sbin/status.cgi' failed, referer: http://192.168.12.149/nagios/side.php
[Tue Jan 27 01:51:51 2015] [error] [client 192.168.12.27] Premature end of script headers: status.cgi, referer: http://192.168.12.149/nagios/side.php
[Tue Jan 27 01:51:55 2015] [error] [client 192.168.12.27] (13)Permission denied: exec of '/usr/local/nagios/sbin/status.cgi' failed, referer: http://192.168.12.149/nagios/side.php
[Tue Jan 27 01:51:55 2015] [error] [client 192.168.12.27] Premature end of script headers: status.cgi, referer: http://192.168.12.149/nagios/side.php
[Tue Jan 27 01:52:07 2015] [error] [client 192.168.12.27] (13)Permission denied: exec of '/usr/local/nagios/sbin/status.cgi' failed, referer: http://192.168.12.149/nagios/side.php
[Tue Jan 27 01:52:07 2015] [error] [client 192.168.12.27] Premature end of script headers: status.cgi, referer: http://192.168.12.149/nagios/side.php
[Tue Jan 27 01:52:08 2015] [error] [client 192.168.12.27] (13)Permission denied: exec of '/usr/local/nagios/sbin/status.cgi' failed, referer:
http://192.168.12.149/nagios/side.php
此問題導(dǎo)致nagios訪問頁面無法顯示,原因selinux沒關(guān)
問題4
u're trying to run actually exists.
Jan 27 02:30:42 localhost nagios: Warning: Return code of 127 for check of service 'LOAD' on host '192.168.12.145' was out of bounds. Make sure the plugin you're trying to run actually exists.
Jan 27 02:31:42 localhost nagios: Warning: Return code of 127 for check of service 'LOAD' on host '192.168.12.145' was out of bounds. Make sure the plugin you're trying to run actually exists.
用check_nrpe進(jìn)行監(jiān)控的需要在監(jiān)控命令前加上check_nrpe,如下
check_command check_nrpe!check_nrpe_load
監(jiān)控端服務(wù)器安裝nrpe
需要安裝openssl和openssl-devel,不然會(huì)出錯(cuò)
tar –xf nrpe-2.13.tar.gz
cd nrpe-2.12
./configure –enable-ssl –with-ssl-lib
make all
make install-plugin
make install-daemon
make install-daemon-config
下面這條監(jiān)控端可以不用執(zhí)行(監(jiān)控端nrpe只需要安裝即可),被監(jiān)控端的nrpe必須啟動(dòng)
/usr/local/nagios/bin/nrpe –c/usr/local/nagios/etc/nrpe.cfg –d啟動(dòng)nrpe,或者將nrpe嵌入xinetd中,由xinetd啟動(dòng)
必須關(guān)閉防火墻,可以用service iptables status查看規(guī)則,service iptablesstop關(guān)閉防火墻,或者配置一條規(guī)則允許5666號(hào)端口
被監(jiān)控端安裝
必須安裝openssl和openssl-devel,否則會(huì)出錯(cuò)
tar –xf nagios-plugins-1.3.13.tar.gz
cd nagios-plugins-1.3.13
useradd nagios
cd nagios-plugins-1.4.13
./configure –with-nagios-user=nagios –with-nagios-group=nagios
make
make install
chown –R nagios:nagios /usr/local/nagios
安裝nrpe
tar –xf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure –enable-ssl –with-lib
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd 將nrpe嵌入xinetd服務(wù)(也可以用上面的我上面用到的命令啟動(dòng))
vim /usr/local/nagios/etc/nrpe.cfg
修改allowed_host=127.0.0.1為allowed_host=127.0.0.1,192.168.12.145(監(jiān)控服務(wù)器的ip)
/usr/local/nagios/libexec/check_nrpe –Hlocalhost
如果出現(xiàn) NRPE v2.12則說明安裝成功
如果出現(xiàn)connection refused by host 則需要安裝openssl或者是防火墻或selinux沒關(guān)
修改nagios下面的object里面的commands.cfg文件增加check_nrpe的定義
definecommand{
command_name check_nrpe
command_line $USER1$/check_nrpe –H $HOSTADDRESS$ -c $ARG1$
}
在監(jiān)控機(jī)上測試與被監(jiān)控機(jī)的通訊是否正常
/usr/local/nagios/libexec/check_nrpe –Hlocalhost –c check_load
OK - loadaverage: 0.05, 0.06, 0.00|load1=0.050;15.000;30.000;0;load5=0.060;10.000;25.000;0; load15=0.000;5.000;20.000;0;
則說明正常
nagios配置文件
nagios安裝后下面共有bin etc libexec sbin share var幾個(gè)目錄
etc存放配置文件
bin存放nagios的命令
sbin存放通過web外部方式執(zhí)行的cgi
libexec存放的是所有插件
var存放log和pid文件
sharenagios網(wǎng)頁文件目錄,存放一些html文件
若是要添加web登陸的用戶,而不是用默認(rèn)的nagiosadmin,則需要在etc/cgi.cfg的authorized_for_system_commands=nagiosadmin后面加上需要添加到用戶,如:nagiosadmin,henshui 具體添加條目需要百度
在nagios.cfg添加一些目錄存放自己設(shè)定的相關(guān)配置文件,找到cfg_file部分
根據(jù)自己添加到目錄設(shè)定配置文件存放的位置,例如:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
配置文件里面的$USER1$和$USER$是變量,因原路徑太長,定義變量簡化(變量是在resource.cfg中定義的)
$USER1$=/usr/local/nagios/libexec
$USER7$=-C mypublic -2 (snmp插件的命令行中參數(shù)需要設(shè)置snmp相關(guān)的信息,為節(jié)省輸入,在此定義變量)
$HOSTADDRESS$為我們下面要定義的主機(jī),即我們定義的檢測對象。他的值就是主機(jī)IP地址
$ARG1$代表參數(shù)1,$ARG2$代表參數(shù)2
可以在service中定義組,屬于這個(gè)組的主機(jī)都會(huì)被監(jiān)控
check_command check_snmp_storage!-m "^VirtualMemory$"!70!90 定義監(jiān)控命令
這里的!代表帶入?yún)?shù),幾個(gè)!代表接收幾個(gè)參數(shù),每個(gè)參數(shù)之間用!分隔
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg 新建hosts.cfg文件,存放主機(jī)與主機(jī)組定義
cfg_file=/usr/local/nagios/etc/objects/services.cfg 新建services.cfg文件,存放服務(wù)與服務(wù)組定義
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg 定義監(jiān)控本機(jī)的狀態(tài)
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg 定義什么時(shí)間段進(jìn)行監(jiān)控
commands.cfg 命令配置文件
contacts.cfg 聯(lián)系人配置文件
#定義服務(wù)出了狀況通知的時(shí)間段,這個(gè)時(shí)間段就是在timeperiods.cfg中定義的
service_notification_period24x7
#主機(jī)出了狀況通知的時(shí)間段,同上
host_notification_period24x7
#當(dāng)服務(wù)出現(xiàn)w-(warning),u-(unkown),c-(critical),或者r-從一擦汗那個(gè)情況恢復(fù)正常,通知聯(lián)系人
service_notification_optionsw,u,c,r
#當(dāng)主機(jī)出現(xiàn)d-(down),u-(unreachable),r
#################################################################
此處可以無視
#################################################################
define host{
use linux-server
host_name 192.168.12.145
alias 192.168.12.145
address 192.168.12.145
}
define service{
use generic-service
host_name 192.168.12.145
service_description check_ping
check_command check_ping!100.0,20%!200.0,50%
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.12.145
service_description LOAD
check_command check_nrpe!check_nrpe_load
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.12.145
service_description check_ssh
check_command check_ssh
max_check_attempts 5
normal_check_interval 1
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。