您好,登錄后才能下訂單哦!
安裝
server 192.168.12.145
client 192.168.12.144
服務器端安裝
nagios-3.3.1.tar.gz
nagios-plugins-1.4.5
安裝環境
yum install httpd gcc gcc-c++ openssl openssl-devel perl
添加nagios用戶和組
useradd nagios ##若是指定-s 為nologin,則重啟nagios的時候可能會報錯,但是不影響功能
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 ##安裝啟動腳本
make install-config ##創建配置文件
make install-commandmode ##配置目錄權限
make install-webconf
定義聯系人
vi /usr/local/nagios/etc/objects/contacts.cfg
定義聯系人和組
創建一個用戶用于在web頁面登陸nagios
htpasswd -c /usr/locl/nagios/etc/httpasswd.user nagiosadmin
重啟apache
chown -R nagios:nagios /usr/local/nagios/etc/htpasswd.users
若權限不對可能造成web界面沒有權限打開該文件,造成無法登陸
編輯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 ##此處為之前建的用戶認證文件位置
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
驗證配置文件是否有錯
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
關閉selinux
在瀏覽器輸入http://ip/nagios 輸入htpasswd命令生成的賬戶密碼即可以訪問
注意點:php是否安裝 apache是否加載了php模塊
錯誤:
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>
第二步:
增加如下內容,記得裝php
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php .phtml
AddType applicatoin/x-httpd-php-source .phps
問題2
輸入賬戶密碼無法登陸
查看apache配置文件添加的用戶認證那一段
查看/usr/localnagios/etc/下面的用戶賬戶密碼文件htpasswd.users
發現apache的用戶和nagios下面的用戶文件名不一致,修改其中一個即可
問題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
此問題導致nagios訪問頁面無法顯示,原因selinux沒關
問題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進行監控的需要在監控命令前加上check_nrpe,如下
check_command check_nrpe!check_nrpe_load
監控端服務器安裝nrpe
需要安裝openssl和openssl-devel,不然會出錯
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
下面這條監控端可以不用執行(監控端nrpe只需要安裝即可),被監控端的nrpe必須啟動
/usr/local/nagios/bin/nrpe –c/usr/local/nagios/etc/nrpe.cfg –d啟動nrpe,或者將nrpe嵌入xinetd中,由xinetd啟動
必須關閉防火墻,可以用service iptables status查看規則,service iptablesstop關閉防火墻,或者配置一條規則允許5666號端口
被監控端安裝
必須安裝openssl和openssl-devel,否則會出錯
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服務(也可以用上面的我上面用到的命令啟動)
vim /usr/local/nagios/etc/nrpe.cfg
修改allowed_host=127.0.0.1為allowed_host=127.0.0.1,192.168.12.145(監控服務器的ip)
/usr/local/nagios/libexec/check_nrpe –Hlocalhost
如果出現 NRPE v2.12則說明安裝成功
如果出現connection refused by host 則需要安裝openssl或者是防火墻或selinux沒關
修改nagios下面的object里面的commands.cfg文件增加check_nrpe的定義
definecommand{
command_name check_nrpe
command_line $USER1$/check_nrpe –H $HOSTADDRESS$ -c $ARG1$
}
在監控機上測試與被監控機的通訊是否正常
/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幾個目錄
etc存放配置文件
bin存放nagios的命令
sbin存放通過web外部方式執行的cgi
libexec存放的是所有插件
var存放log和pid文件
sharenagios網頁文件目錄,存放一些html文件
若是要添加web登陸的用戶,而不是用默認的nagiosadmin,則需要在etc/cgi.cfg的authorized_for_system_commands=nagiosadmin后面加上需要添加到用戶,如:nagiosadmin,henshui 具體添加條目需要百度
在nagios.cfg添加一些目錄存放自己設定的相關配置文件,找到cfg_file部分
根據自己添加到目錄設定配置文件存放的位置,例如:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
配置文件里面的$USER1$和$USER$是變量,因原路徑太長,定義變量簡化(變量是在resource.cfg中定義的)
$USER1$=/usr/local/nagios/libexec
$USER7$=-C mypublic -2 (snmp插件的命令行中參數需要設置snmp相關的信息,為節省輸入,在此定義變量)
$HOSTADDRESS$為我們下面要定義的主機,即我們定義的檢測對象。他的值就是主機IP地址
$ARG1$代表參數1,$ARG2$代表參數2
可以在service中定義組,屬于這個組的主機都會被監控
check_command check_snmp_storage!-m "^VirtualMemory$"!70!90 定義監控命令
這里的!代表帶入參數,幾個!代表接收幾個參數,每個參數之間用!分隔
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg 新建hosts.cfg文件,存放主機與主機組定義
cfg_file=/usr/local/nagios/etc/objects/services.cfg 新建services.cfg文件,存放服務與服務組定義
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg 定義監控本機的狀態
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg 定義什么時間段進行監控
commands.cfg 命令配置文件
contacts.cfg 聯系人配置文件
#定義服務出了狀況通知的時間段,這個時間段就是在timeperiods.cfg中定義的
service_notification_period24x7
#主機出了狀況通知的時間段,同上
host_notification_period24x7
#當服務出現w-(warning),u-(unkown),c-(critical),或者r-從一擦汗那個情況恢復正常,通知聯系人
service_notification_optionsw,u,c,r
#當主機出現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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。