实验需求:
搭建一个HTTP服务器,可通过域名www.jinjianjun.com访问,部署Awstats统计Http访问日志。
一、搭建DNS(host与DNS任选一个即可)
1)host文件
192.168.100.1www.jinjianjun.com www
2)构建DNS(tarena.com)服务器
1、安装软件包
[root@http-server ~]# yum -y install bind bind-chroot
2、修改主配置文件
[root@http-server named]# vim /etc/named.conf
...
11 listen-on port 53 { 192.168.100.1; }; //本地IP
...
17 allow-query { any; }; //开放给任何人查询
……
42 zone "jinjianjun.com" IN {
43 type master;
44 file "jinjianjun.com.zone";
45 };
46
47 zone "100.168.192.in-addr.arpa" IN {
48 type master;
49 file "192.168.100.zone";
50 };
[root@http-server ~]# named-checkconf /etc/named.conf
3、修改数据库文件
[root@http-server ~]# cd /var/named/
[root@http-server named]# cp -p named.localhost jinjianjun.com.zone //让named对配置文件有读取权限
[root@http-server named]# cat jinjianjun.com.zone
$TTL 1D
@ IN SOA jinjianjun.com. root.jinjianjun.com. (
20140141701; serial
1D; refresh
1H; retry
1W; expire
3H ); minimum
NS dns.jinjianjun.com.
dns A 192.168.100.1
www A 192.168.100.1
[root@http-server named]# cp -p jinjianjun.com.zone 192.168.100.zone
[root@http-server named]# cat 192.168.100.zone
$TTL 1D
@ IN SOA jinjianjun.com. root.jinjianjun.com. (
2014041701; serial
1D; refresh
1H; retry
1W; expire
3H ); minimum
NS dns.jinjianjun.com.
1 PTR www.jinjianjun.com.
1 PTR dns.jinjianjun.com.
4、启动服务
[root@http-server named]#service named start
[root@http-server named]#chkconfig named on
5.测试DNS解析
[root@http-server named]# nslookup www.jinjianjun.com 192.168.100.1 //测试正向解析
Server:192.168.100.1
Address:192.168.100.1#53
Name:www.jinjianjun.com
Address: 192.168.100.1
[root@http-server named]# nslookup 192.168.100.1 192.168.100.1 //测试反向解析
Server:192.168.100.1
Address:192.168.100.1#53
1.100.168.192.in-addr.arpaname = www.jinjianjun.com.
1.100.168.192.in-addr.arpaname = dns.jinjianjun.com.
二、搭建http服务
1、安装软件包
[root@http-server ~]# rpm -q httpd
httpd-2.2.15-26.el6.x86_64
2、修改主配置文件
[root@http-server ~]# vim /etc/httpd/conf/httpd.conf
……
76 KeepAlive On //建议开启此选项
...
276 ServerName www.jinjianjun.com:80
3.制作测试主页
[root@http-server ~]# cat /var/www/html/index.html
<h1>Test Page!!!</h1>
4、启动服务
[root@http-server ~]# service httpd start
[root@http-server ~]# chkconfig httpd on
5.测试:
[root@http-server ~]# vim /etc/resolv.conf //指向DNS服务器
nameserver 192.168.100.1
[root@http-server ~]# elinks -dump http://www.jinjianjun.com //也可使用浏览器测试
Test Page!!!
三.部署Awstats统计Http访问日志
1.安装软件
[root@http-server Desktop]# tar zxvf awstats-7.1.tar.gz -C /usr/local/
[root@http-server Desktop]# cd /usr/local/
[root@http-server local]# mv awstats-7.1/ awstats
[root@http-server Desktop]# cd /usr/local/awstats/tools/
2、为站点建立配置文件
[root@http-server tools]# ./awstats_configure.pl
----- AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to ‘understand‘ all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).
-----> Running OS detected: Linux, BSD or Unix
-----> Check for web server install
Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path (‘none‘ to skip web server setup):
> /etc/httpd/conf/httpd.conf //web配置路径
-----> Check and complete web server config file ‘/etc/httpd/conf/httpd.conf‘
Add ‘Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"‘
Add ‘Alias /awstatscss "/usr/local/awstats/wwwroot/css/"‘
Add ‘Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"‘
Add ‘ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"‘
Add ‘<Directory>‘ directive
AWStats directives added to Apache config file.
-----> Update model config file ‘/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf‘
File awstats.model.conf updated.
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y //同意创建新的站点配置
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> www.jinjianjun.com //指定网站名称
-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default): //回车,接受默认配置文件
>
-----> Create config file ‘/etc/awstats/awstats.www.jinjianjun.com.conf‘
Config file /etc/awstats/awstats.www.jinjianjun.com.conf created.
-----> Restart Web server with ‘/sbin/service httpd restart‘
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.jinjianjun.com
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue... //回车
A SIMPLE config file has been created: /etc/awstats/awstats.www.jinjianjun.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for ‘www.jinjianjun.com‘ with command:
> perl awstats.pl -update -config=www.jinjianjun.com
You can also read your statistics for ‘www.jinjianjun.com‘ with URL:
> http://localhost/awstats/awstats.pl?config=www.jinjianjun.com
Press ENTER to finish... //回车,完成
[root@http-server tools]# ls /etc/awstats/awstats.www.jinjianjun.com.conf
/etc/awstats/awstats.www.jinjianjun.com.conf //为站点www.jinjianjun.com新建的统计配置文件
3、指定统计的目标日志文件
[root@http-server tools]# vim /etc/awstats/awstats.www.jinjianjun.com.conf
51 LogFile="/var/log/httpd/access_log"
[root@http-server tools]# mkdir /var/lib/awstats //根据配置文件建立数据目录
4.将日志文件导入Awstats
[root@http-server tools]# ./awstats_updateall.pl now //手动导入
[root@http-server tools]# crontab -e //使用计划任务每5分钟导入一次
*/5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now
[root@http-server tools]# service crond restart
[root@http-server tools]# chkconfig crond on
5.浏览器测试
http://www.jinjianjun.com/awstats/awstats.pl?config=www.jinjianjun.com
6.给awstats设置访问权限
[root@http-server tools]# vim /etc/httpd/conf/httpd.conf
……
1029 <Files "awstats.pl"> //在最后添加对此文件访问权限
1030 AuthType Basic
1031 AuthName "awstat access"
1032 AuthUserFile "/etc/httpd/.authusers"
1033 Require valid-user
1034 </Files>
[root@http-server tools]# htpasswd -c /etc/httpd/.authusers awuser //创建登录账号和密码
New password:
Re-type new password:
Adding password for user awuser
[root@http-server tools]# service httpd restart //重启服务
7.验证
http://www.jinjianjun.com/awstats/awstats.pl?config=www.jinjianjun.com //出现登录窗口