Nagios 配置教程詳解
安裝環境:linux rehl5.1 ,軟體為nagios-3.2.0,和插件nagios-plugins-1.4.13,系統需要
(一).安裝nagios
1. 創建
[root@UnixHot src]# useradd -m nagios
[root@UnixHot src]#groupadd nagcmd
[root@UnixHot src]# usermod -a -G nagcmd nagios
[root@UnixHot src]#usermod -a -G nagcmd apache
2,編譯安裝
[root@UnixHot src]# tar xvf nagios-3.2.0.tar.gz
[root@UnixHot src]# cd nagios-3.2.0
[…]#../configure --with-command-group=nagcmd --with-nagios-user=nagios --with-nagios-group=nagios
-
[root@UnixHot nagios-3.2.0]# make all
[root@UnixHot nagios-3.2.0]# make install
[root@UnixHot nagios-3.2.0]# make install-init (生成init 啟動腳本)
[root@UnixHot nagios-3.2.0]# make install-config (生成一些模板配置文件)
[root@UnixHot nagios-3.2.0]# make install-commandmode (設置相應的許可權)
[root@UnixHot nagios-3.2.0]# make install-webconf
3.為 Nagios 設置 Web 驗證的密碼.
[root@UnixHot ~]# chkconfig --add nagios
[root@UnixHot ~]# chkconfig nagios on
(二)安裝
[root@UnixHot src]# tar xvf nagios-plugins-1.4.13.tar.gz
[root@UnixHot src]# cd nagios-plugins-1.4.13
[root@UnixHot nagios-plugins-1.4.13]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios
--with-nagios-group=nagios
[root@UnixHot nagios-plugins-1.4.13]# make && make install
(三)配置nagios,
這時,你的/usr/local/nagios/下應該有下面幾個文件
drwxrwxr-x 2 nagios nagios 4096 02-14 15:35 bin
drwxrwxr-x 3 nagios nagios 4096 02-14 15:35 etc
drwxrwxr-x 2 nagios nagios 4096 02-14 15:35 libexec
drwxrwxr-x 2 nagios nagios 4096 02-13 00:52 sbin
drwxrwxr-x 10 nagios nagios 4096 02-14 14:15 share
drwxrwxr-x 5 nagios nagios 4096 02-14 16:36 var
mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin">1. Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:宋體;mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">主配置文件
cfg_file=/usr/local/nagios/etc/objects/commands.cfg (命令定義文件)
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg (聯繫人信息定義文件)
cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg (添加此行聯繫人組定義文件)
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg (添加此行主機定義文件)
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg (添加此行主機組定義文件)
cfg_file=/usr/local/nagios/etc/objects/services.cfg (添加此行服務定義文件)
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg (時間周期定義文件)
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
# Definitions for monitoring the local (Linux) host
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg (確定這行沒有註釋)
因為localhost.cfg文件裡面有一些配置文件,我當時做完后,一直出錯,然後移除了此文件,然後建立一個空的localhost.cfg文件,位置和nagios配置文件相符
然後修改許可權為-rwxrwxrwx 1 nagios nagios 1 2011-02-14 localhost.cfg
如果沒有cfg
mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin">2. Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:宋體;mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">文件的配置
我建立了三個主機,分別為lt-21188、lt-21187、nagios,節省空間,只貼出一個,其他複製修改一下即可.
主機定義文件的配置
[root@UnixHot etc]# vi objects/hosts.cfg
define host{
host_name lt-21188
alias lt-21188
address 192.168.21.188
check_command check-host-alive
check_interval 5
retry_interval 1
max_check_attempts 5
check_period 24x7
process_perf_data 0
contact_groups sagroup
notification_interval 30
notification_period 24x7
notification_options d,u,r
}
主機組的配置vi objects/hostgroups.cfg
define hostgroup {
hostgroup_name Enterprise manger
alias Enterprise manger
members lt-21188,lt-21187
}
聯繫人的配置
vi objects/contacts.cfg
define contact{
contact_name nagiosadmin
use generic-contact
alias Nagios Admin
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 15010306527@139.com }
聯繫人組的配置
vi objects/contactgroups.cfg
define contactgroup {
contactgroup_name sagroup
alias system administrator group
members nagiosadmin
}
伺服器的配置
vi objects/services.cfg
define service {
host_name lt-21188
service_description check-host-alive
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups sagroup
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check-host-alive}
ok,主要的幾個cfg文件已經配置完畢.
(四)檢查下配置文件夾並啟動
使用 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 這個命令,如果出現
Total Warnings: 0
Total Errors: 0
說明一切ok.
啟動
(五)出現的問題,
錯誤 1 :
細節決定結果,完成後,web頁面主機處於DOWN狀態,但是可以
Warning: Return code of 127 for check of host 'lt-21188' was out of bounds. Make sure the plugin you're trying to run actually exists
後來查看/usr/local/nagios/下面文件的許可權,然後還是出這個錯,發現/usr/local/nagios/libexec文件夾下面插件少了很多,覺得是nagios-plugins安裝問題,重新編譯安裝一次,問題解決.
錯誤 2 :
在使用“../libexec/check_nrpe -H 192.168.1.12 -c check_disk” 檢查check_disk的時候出錯:
NRPE: Command ‘check_disk’ not defined,經檢查,發現 /usr/local/nagios/etc/nrpe.cfg配置信息由問題,正確的命令為:
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 200% -c 10% -p /dev/hda1
以上部分參考與--趙舜東和官方http://nagios-cn.sourceforge.net/nagios-cn/ 的步驟.
本文出自 「linux學習路」 博客,請務必保留此出處http://fifeapple.blog.51cto.com/1566225/494254
[火星人 ] nagios 安裝步驟-1已經有520次圍觀