bestlong 怕失憶論壇's Archiver

bestlong 發表於 2006-10-15 22:19

Nagios 安裝設定與問題排除

官網:[url]http://www.nagios.org/[/url]
Nagios 是開放原始碼的監視程式,可用來監視伺服器、服務與網路。

在 FC4 用 yum install nagios 後
檢視 /etc/httpd/conf.d/nagios.conf[code]ScriptAlias /nagios/cgi-bin/ /usr/lib/nagios/cgi-bin/
<Directory /usr/lib/nagios/cgi-bin/>
   Options ExecCGI
   order deny,allow
   deny from all
   allow from 127.0.0.1 192.168
   AuthType Basic
   AuthUserFile /etc/nagios/passwd
   AuthName "nagios"
   require valid-user
</Directory>

Alias /nagios/ /usr/share/nagios/html/
<Directory /usr/share/nagios/html/>
   Options None
   order deny,allow
   deny from all
   allow from 127.0.0.1 192.168
   AuthType Basic
   AuthUserFile /etc/nagios/passwd
   AuthName "nagios"
   require valid-user
</Directory>[/code]依照上列設定內容知道密碼檔路徑與登入帳戶名稱,來建立 Apache 網頁認證用密碼檔[code][root@www nagios]# htpasswd -c /etc/nagios/passwd nagios
New password:
Re-type new password:
Adding password for user nagios
[root@www nagios]#[/code]到 /etc/nagios 目錄下將所有 *.cfg-sample 都複製或改名為 *.cfg
然後檢測 nagios.cfg 設定[code][root@www nagios]# nagios -v /etc/nagios/nagios.cfg

Nagios 2.5
Copyright (c) 1999-2006 Ethan Galstad (http://www.nagios.org)
Last Modified: 07-13-2006
License: GPL

Reading configuration data...

Error: Command 'check-host-alive' has already been defined
Error: Could not register command (config file '/etc/nagios/minimal.cfg', starting on line 76)[/code]從訊息中知道 check-host-alive 被重複定義了,執行 grep -n -i check-host-alive * 列出了[code]bigger.cfg:177: check_command           check-host-alive
bigger.cfg:194: check_command           check-host-alive
bigger.cfg:211: check_command           check-host-alive
bigger.cfg:228: check_command           check-host-alive
bigger.cfg:245: check_command           check-host-alive
bigger.cfg:263: check_command           check-host-alive
bigger.cfg:280: check_command           check-host-alive
bigger.cfg:297: check_command           check-host-alive
bigger.cfg:314: check_command           check-host-alive
bigger.cfg:331: check_command           check-host-alive
bigger.cfg:348: check_command           check-host-alive
bigger.cfg:365: check_command           check-host-alive
bigger.cfg:382: check_command           check-host-alive
bigger.cfg:398: check_command           check-host-alive
bigger.cfg:414: check_command           check-host-alive
checkcommands.cfg:169:# 'check-host-alive' command definition
checkcommands.cfg:171:        command_name    check-host-alive
minimal.cfg:77:        command_name    check-host-alive
minimal.cfg:200:        check_command           check-host-alive[/code]因為 /etc/nagios/nagios.cfg 所引入的 cfg_file 是先 checkcommands.cfg 然後是 minimal.cfg 設定檔。剛好兩個檔案中都有定義 check-host-alive 的部分。列出相關片段:[code]### checkcommands.cfg 部分 ###
# Command to check to see if a host is "alive" (up) by pinging it
define command{
        command_name    check-host-alive
        command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w 99,99% -c 100,100% -p 1
        }[/code][code]### minimal.cfg 部分 ###
# 'check-host-alive' command definition
define command{
        command_name    check-host-alive
        command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 1
        }[/code]因為在 checkcommands.cfg 是獨立的設定,目前先用 # 註解掉該部分再檢查就排除此錯誤訊息。
不過卻又冒出不同錯誤:[code][root@www nagios]# nagios -v /etc/nagios/nagios.cfg

Nagios 2.5
Copyright (c) 1999-2006 Ethan Galstad (http://www.nagios.org)
Last Modified: 07-13-2006
License: GPL

Reading configuration data...

Error: Command 'check_local_disk' has already been defined
Error: Could not register command (config file '/etc/nagios/minimal.cfg', starting on line 92)[/code]很熟悉的狀況吧,也是先用同樣去註解的方式解決。不過後續也是一堆類似的問題,覺得這樣的解決問題不對,先復原所有修改並回到原點 nagios.cfg 設定檔檢查。乾脆將下列兩個項目註解掉試試看:[code]cfg_file=/etc/nagios/checkcommands.cfg
cfg_file=/etc/nagios/misccommands.cfg[/code]果然,檢測 nagios.cfg 設定通過[code][root@www nagios]# nagios -v /etc/nagios/nagios.cfg

Nagios 2.5
Copyright (c) 1999-2006 Ethan Galstad (http://www.nagios.org)
Last Modified: 07-13-2006
License: GPL

Reading configuration data...

Running pre-flight check on configuration data...

Checking services...
        Checked 5 services.
Checking hosts...
        Checked 1 hosts.
Checking host groups...
        Checked 1 host groups.
Checking service groups...
        Checked 0 service groups.
Checking contacts...
        Checked 1 contacts.
Checking contact groups...
        Checked 1 contact groups.
Checking service escalations...
        Checked 0 service escalations.
Checking service dependencies...
        Checked 0 service dependencies.
Checking host escalations...
        Checked 0 host escalations.
Checking host dependencies...
        Checked 0 host dependencies.
Checking commands...
        Checked 8 commands.
Checking time periods...
        Checked 1 time periods.
Checking extended host info definitions...
        Checked 0 extended host info definitions.
Checking extended service info definitions...
        Checked 0 extended service info definitions.
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
[root@www nagios]#[/code]試著啟動服務也 OK 了[code][root@www nagios]# /etc/init.d/nagios start
Starting network monitor: nagios
[root@www nagios]#[/code]不過這樣僅僅是可以啟動服務而已,還需要針對需要監視的伺服器、服務或網路進行設定。

bestlong 發表於 2009-10-6 10:35

若網頁畫面中出現下列訊息:

It appears as though you do not have permission to view information for any of the services you requested...

If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.

可以去修改 cgi.cfg 設定將 use_authentication=1 改成 use_authentication=0 
就可以看到資料了,不過可能會有網站安全性的問題。

bestlong 發表於 2009-10-7 09:59

中文說明手冊
[url]http://nagios-cn.sourceforge.net/[/url]
[url]http://nagios-cn.sourceforge.net/nagios-cn/[/url]

bestlong 發表於 2011-6-23 09:42

在 Fedora 13 環境用 yum 安裝 Nagios 3.2.3

登入 root 權限後執行下列幾行指令

# yum install nagios nagios-plugins-all
# service nagios start
# service httpd restart

這樣就安裝好了,不過要趕快修改登入密碼,因為是使用 http 認證所以請先確認 /etc/httpd/conf.d/nagios.conf 設定檔中的 AuthUserFile 屬性所指定的密碼檔位置,例如:

AuthUserFile /etc/nagios/passwd

這樣就可以用 htpasswd 指令來修改密碼,若是 AuthUserFile 所指定的檔案不存在請用下列指令來修改密碼

# htpasswd -c /etc/nagios/passwd nagiosadmin

若是密碼檔已存在就使用下列指令來修改密碼

# htpasswd /etc/nagios/passwd nagiosadmin

這樣就可以開啟瀏覽器到 [url]http://your.host.name/nagios[/url] 登入系統
頁: [1]

Powered by Discuz! X1.5 Archiver   © 2001-2010 Comsenz Inc.