版本:nagios-plugins-1.4.15.tar.gzphp
nagios-3.3.1.tar.gzhtml
nrpe-2.13.tar.gzlinux
nagios 3.3 是變化很大的 他須要apache和PHP 結合 加CGI 原來只用CGI 。ios
由於主頁原來是/usr/local/nagios/share/index.html nginx
如今是 index.php 可是感受頁面沒原來好看了。web
本章 是結合前面的LAMP 環境nginx代理沒了使用正常的80端口。apache
vim /usr/local/apache-2.2.21/conf/httpd.confvim
#setting for nagios
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
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
Require valid-user
</Directory>centos
#groupadd nagcmd服務器
#usermod -G nagcmd nagios
# id nagios
uid=1000(nagios) gid=1000(nagios) 組=1000(nagios),1001(nagcmd)
#tar zxvf nagios-3.3.1.tar.gz
#cd nagios/
#./configure --with-command-group=nagcmd
#make all
#make install
這裏會報錯。。。
/usr/bin/install: omitting directory `includes/rss/extlib’
/usr/bin/install: omitting directory `includes/rss/htdocs’
/usr/bin/install: omitting directory `includes/rss/scripts’
make[1]: *** [install] Error 1
make[1]: Leaving directory `/tmp/nagios-3.3.1/nagios/html’
make: *** [install] Error 2
解決方法:
sed -i 's:for file in includes/rss/*;:for file in includes/rss/*.*;:g' ./html/Makefile
sed -i 's:for file in includes/rss/extlib/*;:for file in includes/rss/extlib/*.*;:g' ./html/Makefile
或者手動 vim html/Makefile
#make install
# make install-init
# make install-config
# make install-commandmode
# /usr/local/apache-2.2.21/bin/htpasswd -c /usr/local/nagios/etc/htpasswd houzc
New password:
Re-type new password:
Adding password for user houzc
define contact{
contact_name
houzc
use generic-contact
alias nagiosadmin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email
houzaicunsky@gmail.com
}
define contactgroup{
contactgroup_name
admins
alias Nagios Administrators
members nagiosadmin,houzc #定義聯繫組的成員
|
define host{
host_name 192.168.3.107
address 192.168.3.107
check_command check-host-alive
max_check_attempts 5
check_period 24x7
contact_groups
admins
notification_interval 10
notification_period 24x7
notification_options d,u,r
}
|
#vim /usr/local/nagios/etc/objects/services.cfg
#service definition
define service{
host_name 192.168.3.107 #被監控的主機,hosts.cfg中定義的
service_description check-host-alive #被監控服務的描述
check_command check-host-alive #所用的命令,是commands.cfg中定義的
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups admins # 聯繫人組,是contactgroups.cfg中定義的
}
|
…………..前面省略
Checking host dependencies...
Checked 0 host dependencies.
Checking commands...
Checked 24 commands.
Checking time periods...
Checked 5 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors:
0
Things look okay - No serious problems were detected during the pre-flight check
|
service nagios start
nagios 是一個主動與被動的監控,什麼是主動和被動?
主動 :就是被監控端不用受權或者被監控是提供對外的服務。如:ping HTTP
下面圖是本地監控
若是想監控URL 不一樣參數 還要本身修改他的插件的參數。
看這篇:http://hzcsky.blog.51cto.com/1560073/493599
被動監控須要經過SLL 加入 隧道而後 NRPE ->libexec的監控插件採集數據。
apt-get install libssl-dev libssl0.9.8
|
注:藍色標註的是命令名,即check_users就是等號後面/usr/local/nagios/libexec/check_users -w 5 -c 10的簡稱。這五個命令,分別是監控登陸用戶數、cpu負載、/ 分區使用狀況、殭屍進程和總的進程數。 具體能夠-h 查看相應參數。
|
apt-get
install libssl-dev libssl0.9.8
|
添加以下內容:
# 'check_nrpe ' command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
$USER1 是/usr/local/nagios/etc/resource.cfg 聲明的 $USER1$=/usr/local/nagios/libexec |
define service{
host_name 192.168.3.101 #被監控的主機名,這裏注意必須是linux且運行着nrpe,並且必須是hosts.cfg中定義的
service_description check-load # 監控項目的名稱
check_command check_nrpe!check_load
#監控命令是check_nrpe,是在commands.cfg中定義的,帶的參數是check_load,是在nrpe.cfg中定義的
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
}
這裏只添加一個測試。 |
host 配置文件添加和107 修改沒區別只是IP地址變了。
define host{ host_name 192.168.3.101 address 192.168.3.101 check_command check-host-alive max_check_attempts 5 check_period 24x7 contact_groups admins notification_interval 10 notification_period 24x7 notification_options d,u,r } |
測試nagios配置# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
nagios發警告郵件是採用本機的smtp服務,能夠查看commands.cfg中關於發郵件的命令進行定義。使用本機的mail命令,就須要開啓本機的smtp服務。
我是用的公司的郵件服務器創建了個用戶而已,否則本身用postfix 搭建個SMTP端只爲nagios用更好!
# tar –zxvf sendEmail-v1.55.tar.gz -c /usr/src
# cp sendEmail-v1.55/sendEmail /usr/local/bin
若是你不帶-m參數的話,就會提示你自行輸入,輸入完成後使用CTRL-D來結束
vim /usr/local/nagios/etc/objects/commands.cfg
#文件前面有最後先註釋 直接複製修改本身的郵件用戶和認證就能夠! # 'notify-host-by-email' command definition # 'notify-service-by-email' command definition |
若有問題請加羣:71922203!!!!