標籤:http linux 日誌分析工具
伺服器IP地址:192.168.4.5
伺服器主機名稱:srv5.tarena.com
1.在伺服器端安裝httpd軟體包
[[email protected] /]# yum -y install httpd
[[email protected] /]# service httpd start
[[email protected] /]# chkconfig httpd on
2.在客戶機端驗證
在瀏覽器中輸入192.168.4.5
如果顯示歡迎頁面表示伺服器搭建成功
3.部署網頁文檔
首先將歡迎頁面配置移除
[[email protected] 案頭]# cd /etc/httpd/conf.d/
[[email protected] conf.d]# mv welcome.conf welcome.conf.bak
建立測試首頁
[[email protected] ~]# cd /var/www/html/
[[email protected] html]# vim index.html
Hello World!
瀏覽器驗證
4.網站目錄遷移和預設首頁設定
[[email protected] html]# mkdir /var/ftp
[[email protected] html]# echo "wo shi ftp" > /var/ftp/index.html
[[email protected] html]# vim /etc/httpd/conf/httpd.conf
修改配置如下
DocumentRoot "/var/ftp"
將原來<Directory "/var/www/html">修改為<Directory "/var/ftp">
DirectoryIndex index.php index.html index.html.var
重新載入設定檔
[[email protected] html]# service httpd reload
瀏覽器驗證
5.禁止使用符號連結和自動索引
[[email protected] ftp]# ln -s /var/www/html/index.html haha.html
瀏覽器輸入驗證http://192.168.4.5/haha.html
通過驗證知道預設可以使用符號連結
下面禁用符號連結
[[email protected] ftp]# vim /etc/httpd/conf/httpd.conf
<Directory "目錄路徑">
Options -FollowSymlinks
.. ..
</Directory>
[[email protected] ~]# service httpd restart
預設情況下首頁不存在時訪問網站會出現該目錄的索引
[[email protected] ftp]# rm -rf index.html
瀏覽器驗證出現索引
下面禁用自動索引
[[email protected] ~]# vim /etc/httpd/conf/httpd.conf
<Directory "目錄路徑">
Options -Indexes
.. ..
</Directory>
[[email protected] ~]# service httpd restart
瀏覽器驗證出現錯誤頁面
6.使用目錄別名
[[email protected] ftp]# echo "index" > /usr/src/index.html
[[email protected] ftp]# vim /etc/httpd/conf/httpd.conf
在檔案末尾添加一行alias /tools "/usr/src/"
[[email protected] ftp]# service httpd reload
瀏覽器輸入http://192.168.4.5/tools/能夠訪問伺服器/usr/src/下的首頁
7.客戶機存取控制
允許從任何地址訪問
<Directory /var/www/html>
Order allow,deny
Allow from all
</Directory>
僅允許從個別網段、IP地址訪問
<Directory /var/www/html>
Order allow,deny
Allow from 192.168.4.0/24 192.168.7.200
</Directory>
8.為指定目錄啟用使用者授權
在網站根目錄下建一個子目錄test
能訪問 http://伺服器位址/test/
給studir添加使用者授權,只允許使用者stu01訪問(密碼123456)
建立首頁和測試目錄
[[email protected] ftp]# echo "Hello World" > index.html
[[email protected] ftp]# mkdir test
建立兩個對test有許可權的使用者(不必是系統使用者)
[[email protected] ftp]# htpasswd -c /etc/httpd/authpwd stu01
[[email protected] ftp]# htpasswd /etc/httpd/authpwd stu02
[[email protected] ftp]# vim /etc/httpd/conf/httpd.conf
<Directory "/var/ftp/test">
AuthName "Tarena Library."
AuthType basic
AuthUserFile /etc/httpd/authpwd
#Require valid-user //允許對test有許可權的使用者訪問
Require user stu01 //只允許stu01訪問test目錄 (和上面Require兩個不能同時使 用)
</Directory>
[[email protected] ftp]# service httpd reload
瀏覽器輸入http://192.168.4.5可以訪問
輸入http://192.168.4.5/test/需要輸入賬戶和密碼驗證
9.構建AWStats日誌分析系統
下載awstats工具
[[email protected] ~]# tar zxf awstats-7.1.tar.gz
[[email protected] ~]# mv awstats-7.1 /usr/local/awstats
[[email protected] ~]# cd /usr/local/awstats/tools/
[[email protected] tools]# ./awstats_configure.pl
> /etc/httpd/conf/httpd.conf (填寫httpd的設定檔路徑)
file (required if first install) [y/N] ? y
> srv5.tarena.com(填寫做要日誌分析的網站網域名稱)
>
Press ENTER to continue...
> http://localhost(伺服器名)/awstats/awstats.pl?config=srv5.tarena.com(網站網域名稱)
//查看日誌分析的網址
Press ENTER to finish...
修改awstats設定檔,指定要做日誌分析的日誌路徑
[[email protected] tools]# vim /etc/awstats/awstats.srv5.tarena.com.conf
LogFile="/var/log/httpd/access_log" (指定日誌路徑)
建立日誌分析出的資料指定目錄
[[email protected] tools]# mkdir /var/lib/awstats
執行日誌分析,並設定cron計劃任務
[[email protected] tools]# ./awstats_updateall.pl now
.. ..
[[email protected] tools]# crontab -e
*/5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now
查看分析結果
http://192.168.4.5/awstats/awstats.pl?config=srv5.tarena.com
為方便查看分析結果,可以將此超連結放到網站根目錄的一個網頁中
[[email protected] ~]# vim /網站根目錄/aw-svr5.html
<html> <head>
<meta http-equiv=refresh content="0;
url=http://伺服器位址/awstats/awstats.pl?config=網站網域名稱">
</head>
<body> </body> </html>
訪問http://伺服器位址/aw-svr5.html
10.建立基於網域名稱的虛擬機器主機
在沒有配置DNS伺服器的情況下通過修改/etc/hosts檔案來實現客戶機對伺服器的網域名稱解析
[ser5 /]# vim /etc/hosts (在伺服器和用戶端同時做這個步驟)
192.168.4.5 www.baidu.com www.google.com
建立兩個虛擬機器主機的主目錄和首頁
[[email protected] /]# mkdir /var/www/baidu
[[email protected] /]# echo "baidu.com" > /var/www/baidu/index.html
[[email protected] /]# mkdir /var/www/google
[[email protected] /]# echo "google.com" > /var/www/google/index.html
建立虛擬機器主機的設定檔
[[email protected] /]# vim /etc/httpd/conf.d/Vhost.conf
NameVirtualHost 192.168.4.5
<VirtualHost 192.168.4.5>
ServerName www.baidu.com
DocumentRoot "/var/www/baidu"
</VirtualHost>
<VirtualHost 192.168.4.5>
ServerName www.google.com
DocumentRoot "/var/www/google"
</VirtualHost>
[[email protected] /]# service httpd reload
在客戶機上分別輸入www.baidu.com和www.google.com
註:如果輸入伺服器IP地址,開啟的是設定的第一個虛擬機器主機,因為當設定虛擬機器主機時,原來在httpd.conf中設定的網站將不能生效,如果想將原來在httpd.conf生效需要在虛擬機器主機設定檔修改如下
NameVirtualHost 192.168.4.5
<VirtualHost 192.168.4.5>
ServerName 192.168.4.5
DocumentRoot "/var/ftp"
</VirtualHost>
<VirtualHost 192.168.4.5>
ServerName www.baidu.com
DocumentRoot "/var/www/baidu"
</VirtualHost>
<VirtualHost 192.168.4.5>
ServerName www.google.com
DocumentRoot "/var/www/google"
</VirtualHost>
然後輸入http://伺服器IP 進行驗證