[root@KCentOS5C ~]# yum install httpd*
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
httpd i386 2.2.3-6.el5.centos.1 base 1.1 M
httpd-devel i386 2.2.3-6.el5.centos.1 base 145 k
httpd-manual i386 2.2.3-6.el5.centos.1 base 830 k
Installing for dependencies:
apr-devel i386 1.2.7-11 base 237 k
apr-util-devel i386 1.2.7-6 base 54 k
=============================================================================
[root@KCentOS5C ~]# chkconfig httpd on
添加Nagios系統用戶和同名組:
[root@KCentOS5C ~]# useradd nagios
準備好Nagios的源代碼包:
[root@KCentOS5C ~]# ll
total 3712
-rw------- 1 root root 928 Oct 3 10:33 anaconda-ks.cfg
-rw-r--r-- 1 root root 22760 Oct 3 10:33 install.log
-rw-r--r-- 1 root root 2888 Oct 3 10:33 install.log.syslog
-rw-r--r-- 1 root root 1738698 Sep 30 22:42 nagios-2.9.tar.gz
這個就是Nagios主程序的源代碼包
-rw-r--r-- 1 root root 1693979 Sep 30 22:51 nagios-plugins-1.4.10.tar.gz
這個是Nagios-plugin插件程序源代碼包
1.解壓縮Nagios主程序源代碼包
[root@KCentOS5C ~]# tar -zxvf nagios-2.9.tar.gz
2.進入Nagios主程序包的解壓目錄
[root@KCentOS5C ~]# cd nagios-2.9
[root@KCentOS5C nagios-2.9]# ./configure --prefix=/usr/local/nagios
預配置成功後將返回配置環境信息
----------------------------------------------------
*** Configuration summary for nagios 2.9 04-10-2007 ***:
-------------------------
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagios
Embedded Perl: no
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Lock file: ${prefix}/var/nagios.lock
Init directory: /etc/rc.d/init.d
Host OS: linux-gnu
------------------------
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /bin/traceroute
Review the options above for accuracy. If they look okay,
type 'make all' to compile the main program and CGIs.
請注意看最後的提示,如果對以上反饋信息接受的話,則需要繼續執行“make all”命令來編譯主程序以及CGI。
-----------------------------------------------------
4.編譯Nagios主程序
[root@KCentOS5C nagios-2.9]# make all
Nagios主程序編譯成功後將返回信息
-----------------------------------------------------
*** Compile finished ***
can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
如果在編譯當中沒有發生錯誤的話,那麼可以照以下這些命令繼續操作。
- This installs the main program, CGIs, and HTML files
執行“make install”命令來對主程序,CGI以及HTML網頁進行安裝。
- This installs the init script in /etc/rc.d/init.d
執行“install-init”命令來在/etc/rc.d/init.d/目錄中安裝啓動腳本。
- This installs and configures permissions on the
directory for holding the external command file
執行“install-commandmode”命令來安裝和配置外部命令對Nagios主路徑操作的權限。(這裏所謂的外部命令主要是指Apache服務通過CGI來對Nagios的進行的操作。用戶將通過Web以執行CGI程序腳本的方式來對Nagios的檢測結果進行讀取和調用。)
- This installs *SAMPLE* config files in /usr/local/nagios/etc
You'll have to modify these sample files before you can
use Nagios. Read the HTML documentation for more info
on doing this. Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!
執行“make install-config”命令將會在/usr/local/etc/這個Nagios編譯安裝的主配置路徑下安裝示例配置模板,這將對於之後的配置制定幫助很大。
這些關於支持的信息就不再詳細講了
please make sure that you:
- Read the HTML documentation
- Read the FAQs online at http://www.nagios.org/faqs
Also make sure to include pertinent information that could
help others help you. This might include:
- What version of the plugins you are using
- Relevant snippets from your config files
- Relevant error messages from the Nagios log file
-----------------------------------------------------
5.安裝Nagios主程序、CGI以及網頁
[root@KCentOS5C nagios-2.9]# make install
安裝完Nagios主程序、CGI和網頁的之後將提示安裝成功信息以及剩餘可操作的步驟
-----------------------------------------------------
*** Main program, CGIs and HTML files installed ***
without any arguments for a list of all possible options):
- This installs the init script in /etc/rc.d/init.d
- This installs and configures permissions on the
directory for holding the external command file
- This installs *SAMPLE* config files in /usr/local/nagios/etc
You'll have to modify these sample files before you can
use Nagios. Read the HTML documentation for more info
on doing this. Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!
-----------------------------------------------------
6.安裝Nagios的系統啓動腳本
[root@KCentOS5C nagios-2.9]# make install-init
安裝完Nagios的系統啓動腳本之後將提示腳本安裝成功信息以及剩餘可操作的步驟
-----------------------------------------------------
*** Init script installed ***
without any arguments for a list of all possible options):
- This installs and configures permissions on the
directory for holding the external command file
- This installs *SAMPLE* config files in /usr/local/nagios/etc
You'll have to modify these sample files before you can
use Nagios. Read the HTML documentation for more info
on doing this. Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!
-----------------------------------------------------
7.將Nagios的啓動腳本添加到系統服務當中去
[root@KCentOS5C ~]# chkconfig --add nagios
[root@KCentOS5C ~]# chkconfig nagios on
[root@KCentOS5C nagios-2.9]# make install-commandmode
安裝配置外操作權限後將提示配置成功信息以及剩餘可操作步驟
-----------------------------------------------------
*** External command directory configured ***
without any arguments for a list of all possible options):
- This installs *SAMPLE* config files in /usr/local/nagios/etc
You'll have to modify these sample files before you can
use Nagios. Read the HTML documentation for more info
on doing this. Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!
-----------------------------------------------------
10.將Apache服務宿主用戶加到nagios組裏面
這樣做是爲了讓Apache有適當的權限能夠通過CGI腳本程序對Nagios進行調用,否則Apache將沒有權限調用Nagios,用戶通過Web將無法訪問Nagios處理的所有信息。
[root@KCentOS5C nagios-2.9]# usermod -G nagios apache
11.安裝Nagios的配置模板
[root@KCentOS5C nagios-2.9]# make install-config
安裝完畢Nagios的配置模板後將反饋安裝成功的提示信息。
-----------------------------------------------------
*** Sample config file installed ***
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.
- Look at the sample config files
- Read the HTML documentation
- Read the FAQs online at http://www.nagios.org/faqs
*BEFORE* you post a question to one of the mailing lists.
-----------------------------------------------------
1.解壓縮Nagios-plugins插件源代碼包
[root@KCentOS5C ~]# tar -zxvf nagios-plugins-1.4.10.tar.gz
[root@KCentOS5C ~]# cd nagios-plugins-1.4.10
[root@KCentOS5C nagios-plugins-1.4.10]# ./configure --prefix=/usr/local/nagios/
預配置完成的話將會建立Makefile並反饋檢測系統環境的結果。
-----------------------------------------------------
config.status: creating po/Makefile
--with-apt-get-command:
--with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
--with-ping-command: /bin/ping -n -U -w %d -c %d %s
--with-ipv6: yes
--with-mysql: no
--with-openssl: yes
--with-gnutls: no
--with-perl: /usr/bin/perl
--enable-perl-modules: no
--with-cgiurl: /nagios/cgi-bin
--with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
-----------------------------------------------------
[root@KCentOS5C nagios-plugins-1.4.10]# make
total 28
drwxrwxr-x 2 nagios nagios 4096 Oct 5 13:25 bin
drwxrwxr-x 2 nagios nagios 4096 Oct 5 19:03 etc
drwxr-xr-x 2 root root 4096 Oct 5 19:07 libexec
drwxrwxr-x 2 nagios nagios 4096 Oct 5 13:25 sbin
drwxrwxr-x 9 nagios nagios 4096 Oct 5 19:07 share
drwxrwxr-x 4 nagios nagios 4096 Oct 5 19:08 var
1.備份Apache服務的主配置文件
[root@KCentOS5C ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.backup
[root@KCentOS5C ~]# vi /etc/httpd/conf/httpd.conf
這裏主要改動以下這些參數:
-----------------------------------------------------
ServerName *:80
-----------------------------------------------------
3.察看Nagios網頁配置模板文件
[root@KCentOS5C ~]# less nagios-2.9/sample-config/httpd.conf
-----------------------------------------------------
# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
# Last Modified: 11-26-2005
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file. Customize the paths, etc. as
# needed to fit your system.
# SSLRequireSSL
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
-----------------------------------------------------
基本上這個文件可以直接使用。根據這個配置文件中指定的AuthUserFile項,它指定的是通過Apache訪問Nagios的合法用戶的帳戶名單庫文件,需要使用htpasswd命令對這個名單庫進行用戶的添加。而默認安裝環境下在/usr/local/nagios/etc/目錄下是沒有htpasswd.user這個文件的,所以需要手動添加。請特別注意,用root身份建立的htpasswd.user文件的權限問題,應該在建立該文件完畢後立即更改爲nagios用戶nagios組的所有權,並且要增加Nagios同組用戶讀寫權限。
4.整合Nagios網頁配置文件到Apache中
將Nagios網頁配置文件作爲Apache的擴展配置文件複製改名到Apache的擴展配置文件目錄/etc/httpd/conf.d/目錄下
[root@KCentOS5C ~]# cp nagios-2.9/sample-config/httpd.conf /etc/httpd/conf.d/nagios-httpd.conf
[root@KCentOS5C ~]# touch /usr/local/nagios/etc/htpasswd.user
[root@KCentOS5C ~]# chown nagios.nagios /usr/local/nagios/etc/htpasswd.users
[root@KCentOS5C ~]# chmod g+wr /usr/local/nagios/etc/htpasswd.users
[root@KCentOS5C ~]# ll /usr/local/nagios/etc/htpasswd.users
-rw-rw-r-- 1 nagios nagios 0 Oct 5 14:05 /usr/local/nagios/etc/htpasswd.users
我添加了一個kanecruise用戶,口令是123456。
[root@KCentOS5C ~]# htpasswd -m /usr/local/nagios/etc/htpasswd.user kanecruise
------------------------------------------------------------
New password: 123456
Re-type new password: 123456
Adding password for user kanecruise
------------------------------------------------------------
10.察看htpasswd的使用方法,這裏我就解釋一些比較重要和常用的。
[root@KCentOS5C ~]# htpasswd
-------------------------------------------------------------
Usage:
htpasswd [-cmdpsD] passwordfile username
htpasswd -b[cmdpsD] passwordfile username password
htpasswd -n[mdps] username
htpasswd -nb[mdps] username password
建立新的帳戶庫文件。
添加一個MD5口令加密的新用戶。
添加一個口令不加密的新用戶。
添加一個SHA口令加密的新用戶。
刪除一個指定的用戶
在Windows、NetWare以及TPF這些操作系統中“-m”參數(啓用MD5對口令加密)是默認使用的
On all other systems, the '-p' flag will probably not work.
在其他的所有操作系統中“-p”(不對口令啓用加密)參數將可能會引起失敗。
-------------------------------------------------------------
11.檢查htpasswd帳戶文件
[root@KCentOS5C ~]# cat /usr/local/nagios/etc/htpasswd.users
-------------------------------------------------------------
kanecruise:$apr1$Qwk9h/..$HaRakpabADGZL10dwPcrx1
-------------------------------------------------------------
用戶添加正確,並且口令都以MD5的方式加密了。
默認下Nagios編譯安裝後都沒有現成的配置文件,它們都以模板配置文件的方式在/usr/local/nagios/etc/這個主配置路徑下,需要手動複製並配置成可用的配置文件。
Nagios的主配置文件爲nagios.cfg。
[root@KCentOS5C ~]# cp /usr/local/nagios/etc/nagios.cfg-sample /usr/local/nagios/etc/nagios.cfg
[root@KCentOS5C ~]# vi /usr/local/nagios/etc/nagios.cfg
主要修改和確認以下幾個較重要的配置項,其餘的類似優化涉及到的配置調整這裏暫不交待了。這次不像上回我用RPM包安裝Nagios那次的配置方式,這次我打算將所有Nagios功能定義配置都集中在localhost.cfg這一個文件當中去,而命令定義文件commands.cfg獨立保存一個文件,因此除了這兩個文件不註釋外,其他的Nagios功能定義文件都保持註釋狀態。
-------------------------------------------------------------
log_file=/usr/local/nagios/var/nagios.log
確認Nagios服務的日誌記錄文件,需要確認此項是解注狀態的。默認編譯安裝後沒有該文件,要手動添加並指定適當的讀寫權限。
在Nagios中將對應功能插件定義成命令的命令定義文件,需要確認此項是解注狀態的。默認編譯安裝後也沒有該文件,需要從模版複製。
設定Naigos對象功能定義的配置文件,需要確認此項是解注狀態的。默認編譯安裝後也沒有該文件,需要從模版複製。
#cfg_file=/usr/local/nagios/etc/contacts.cfg
#cfg_file=/usr/local/nagios/etc/dependencies.cfg
#cfg_file=/usr/local/nagios/etc/escalations.cfg
#cfg_file=/usr/local/nagios/etc/hostgroups.cfg
#cfg_file=/usr/local/nagios/etc/hosts.cfg
#cfg_file=/usr/local/nagios/etc/services.cfg
#cfg_file=/usr/local/nagios/etc/timeperiods.cfg
#cfg_dir=/usr/local/nagios/etc/servers
#cfg_dir=/usr/local/nagios/etc/printers
#cfg_dir=/usr/local/nagios/etc/switches
#cfg_dir=/usr/local/nagios/etc/routers
以上這些分塊功能的定義配置文件需要保持註釋,因爲這些文件的作用都已經集中到localhost.cfg這一個文件當中去了。
nagios_group=nagios
設定Nagios服務的宿主用戶和組。
check_external_commands=1
設定Nagios外部檢查命令功能開關,默認是值0。將原來的註釋掉,更改爲值1,必須要打開該功能,否則CGI將不能調用。
#command_check_interval=-1
設定命令檢查的時間間隔,將原來值-1的項註釋掉,啓用原來備用值爲15s(15秒)。這項的時間間隔值請按實際需求情況設定。
-------------------------------------------------------------
[root@KCentOS5C ~]# touch /usr/local/nagios/var/nagios.log
改變Nagios主日誌文件的屬主。
添加同組成員的讀寫權限。
查看日誌文件的屬性。
-rw-rw-r-- 1 nagios nagios 0 Oct 5 15:28 /usr/local/nagios/var/nagios.log
3.處理Nagios的CGI配置文件:
[root@KCentOS5C ~]# cp /usr/local/nagios/etc/cgi.cfg-sample /usr/local/nagios/etc/cgi.cfg
[root@KCentOS5C ~]# vi /usr/local/nagios/etc/cgi.cfg
這裏主要注意關於訪問用戶身份驗證的配置項的設定。Nagios系統將各種操作行爲的授權用戶分的非常的仔細,所以在實際應用當中可以分的非常細,什麼用戶可以做哪些操作而哪些用戶又沒有權限做哪些操作。但是這裏我只簡單的授權給同一個用戶。請特別注意,這裏的授權用戶的對象必須只能夠是在htpasswd中添加註冊過的用戶。
-------------------------------------------------------------
use_authentication=1
設定啓用身份驗證。
設定系統信息的授權用戶。
設定配置信息的授權用戶。
設定系統命令的授權用戶。
設定全部監測服務的授權用戶。
設定全部被監測主機的授權用戶。
設定全部監測服務命令的授權用戶。
設定全部主機命令的授權用戶。
-------------------------------------------------------------
[root@KCentOS5C ~]# cp /usr/local/nagios/etc/commands.cfg-sample /usr/local/nagios/etc/commands.cfg
目前來說暫時不需要對Nagios命令定義文件做什麼修改。但是如果要添加新的命令或者修改現有命令的定義的話,則需要修改該文件。