Cents下Nagios的安裝-配置Apache服務
四.配置Apache服務:
1.備份Apache服務的主配置文件
- [root@KCentOS5C ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.backup
2.配置Apache服務的主配置文件
- [root@KCentOS5C ~]# vi /etc/httpd/conf/httpd.conf
這里主要改動以下這些參數:
-----------------------------------------------------
ServerName *:80
配置Apache的服務器名,如果有域名的話請?zhí)顚懻_的服務器名。
Include conf.d/*.conf
確認Apache擴展配置文件的存放路徑。
-----------------------------------------------------
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.
- ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
設定了Nagios的CGI執(zhí)行目錄對應的系統路徑。
- # 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
- Alias /nagios "/usr/local/nagios/share"
設定了Nagios的網頁URL對應的系統路徑。
- # 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
-----------------------------------------------------
基本上這個文件可以直接使用。根據這個配置文件中指定的AuthUserFile項,它指定的是通過Apache訪問Nagios的合法用戶的帳戶名單庫文件,需要使用htpasswd命令對這個名單庫進行用戶的添加。而默認安裝環(huán)境下在/usr/local/nagios/etc/目錄下是沒有htpasswd.user這個文件的,所以需要手動添加。請?zhí)貏e注意,用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
5.建立Nagios的網頁訪問用戶帳戶文件(這里必須要與Nagios網頁配置文件當中AuthUserFile指定的路徑文件名一致)
- [root@KCentOS5C ~]# touch /usr/local/nagios/etc/htpasswd.user
6.更改Nagios網頁訪問用戶帳戶文件的屬主
- [root@KCentOS5C ~]# chown nagios.nagios /usr/local/nagios/etc/htpasswd.users
7.對Nagios網頁訪問用戶帳戶文件增加同組成員讀寫權限(這主要是賦給apache這個系統用戶)
- [root@KCentOS5C ~]# chmod g+wr /usr/local/nagios/etc/htpasswd.users
8.察看Nagios網頁訪問用戶帳戶文件的屬性信息
- [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
9.添加htpasswd.user用戶
我添加了一個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
- -c Create a new file.
建立新的帳戶庫文件。
- -n Don't update file; display results on stdout.
- -m Force MD5 encryption of the password.
添加一個MD5口令加密的新用戶。
- -d Force CRYPT encryption of the password (default).
- -p Do not encrypt the password (plaintext).
添加一個口令不加密的新用戶。
- -s Force SHA encryption of the password.
添加一個SHA口令加密的新用戶。
- -b Use the password from the command line rather than prompting for it.
- -D Delete the specified user.
刪除一個指定的用戶
- On Windows, NetWare and TPF systems the '-m' flag is used by default.
在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
-------------------------------------------------------------
用戶添加正確,并且口令都以MD5的方式加密了。
上一節(jié):plugins插件程序 下一節(jié):Nagios的配置文件
【編輯推薦】