學習linux系統服務時,你可能會遇到多種問題,這裡将介紹在linux系統中配置Apache服務問題的解決方法,在這裡拿出來和大家分享一下。
1.備份Apache服務的主配置檔案
[root@KCentOS5C ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.backup
2.linux系統中配置Apache服務的主配置檔案
[root@KCentOS5C ~]# vi /etc/httpd/conf/httpd.conf
這裡主要改動以下這些參數:
ServerName *:80
配置Apache的伺服器名,如果有域名的話請填寫正确的伺服器名。
Include conf.d/*.conf (/etc/httpd/conf.d)
确認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.
#setting for nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" ###設定了Nagios的CGI執行目錄對應的系統路徑。
# 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.user ###這裡指定了通路使用者帳戶庫檔案。
Require valid-user
Alias /nagios "/usr/local/nagios/share" ###設定了Nagios的網頁URL對應的系統路徑。
Options None
AuthUserFile /usr/local/nagios/etc/htpasswd.user ###這裡指定了通路使用者帳戶庫檔案
{######将#setting for nagios --這一段加到/usr/local/apache/conf/httpd.conf的末尾。
用/usr/local/apache/bin/apachctl configtest 檢測配置 --help檢視##########}
基本上這個檔案可以直接使用。根據這個配置檔案中指定的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
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.user
7.對Nagios網頁通路使用者帳戶檔案增加同組成員讀寫權限(這主要是賦給apache這個系統使用者)
[root@KCentOS5C ~]# chmod g+wr /usr/local/nagios/etc/htpasswd.user
8.察看Nagios網頁通路使用者帳戶檔案的屬性資訊
[root@KCentOS5C ~]# ll /usr/local/nagios/etc/htpasswd.user
-rw-rw-r-- 1 nagios nagios 0 Oct 5 14:05 /usr/local/nagios/etc/htpasswd.user
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.user
kanecruise:$apr1$Qwk9h/..$HaRakpabADGZL10dwPcrx1
使用者添加正确,并且密碼都以MD5的方式加密了。
以上講解的是在linux系統中配置Apache服務。