• 欢迎访问LLYCLOUD information technical share center (ITSC),Linux 安全,Linux 系统,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入LLYCLOUD QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏LLYCLOUD ITSC吧

1.Apache&AWStats

Linux安全与高级应用 Akide_Liu 10个月前 (02-01) 308次浏览 0个评论

Apache主要目录和文件:

  • 服务目录:/usr/local/httpd/
  • 主配置文件:/usr/local/httpd/conf/httpd.conf
  • 网页目录:/usr/local/httpd/htdocs/
  • 服务脚本:/usr/local/httpd/bin/apachectl
  • 执行程序:/usr/local/httpd/bin/httpd
  • 访问日志: /usr/local/httpd/log/access_log
  • 错误日志: /usr/local/httpd/log/error_log

一。需求描述

编译安装httpd服务器,要求支持动态模块扩展、地址重写、多字符集

配置并启动服务

安装并配置AWStats服务

二、实现思路

编译安装httpd软件包

配置并启动httpd服务器

部署及测试Web站点

构建AWStats日志分析系统

三、实验步骤 实验环境contos6.6

1.准备工作

卸载httpd包

[[email protected] 桌面]# yum -y remove httpd* 【必须配置yum】

挂载以及卸载光盘

[[email protected] ~]# umount /dev/cdrom

[[email protected] ~]# mount /dev/cdrom /media/

mount: block device /dev/sr0 is write-protected, mounting read-only

检测并安装gcc-c++环境

[[email protected] httpd-2.2.17]# yum -y install gcc-c++

2.编译安装Apache

切换到挂载目录下

[[email protected] chapter05]# cd /media/2.Linux_server/chapter05

[[email protected] chapter05]# ls

awstats-7.0.zip httpd-2.2.17.tar.gz

解压http包:

[[email protected] chapter05]# tar -zxvf httpd-2.2.17.tar.gz -C /usr/src/

却换到解压目录:

1.Apache&AWStats

配置:

1.Apache&AWStats

[[email protected] httpd-2.2.17]# ./configure –prefix=/usr/local/httpd –enable-so –enable-rewrite –enable-charset-lite –enable-cgi

源码编译相关参数解释:

  • –prefix=/usr/local/httpd,指定安装路径;
  • –enable-so,允许Apache核心动态加载模块,但是不实际编译任何动态模块;

Apache有两种使用模块的方法:一是静态连接进核心,二是作为DSO模块动态加载。

  • –enable-rewrite,支持rewrite功能;

可以实现以下功能:1.实现动态网站伪静态;2.防止盗链;3.网址规范化;4.实现301转向(永久性转到另一个网址);5.实现302转向(暂时转向到另外一个网址);6.禁止某些坏访问者;7.禁止某些URL被访问。

  • –enable-charset-lite,允许对页面进行字符集转换;
  • –enable-cgi,启用CGI Scripts。

编译安装

[[email protected] httpd-2.2.17]# make && make install

3.后续优化

命令优化:

[[email protected] httpd]# ln -s /usr/local/httpd/bin/* /usr/local/bin/

添加服务:

[[email protected] httpd]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd【复制到服务文件夹】

[[email protected] httpd]# vim /etc/init.d/httpd 【修改服务配置文件】

【添加语句 】

1.Apache&AWStats

【添加服务,并验证】

1.Apache&AWStats

4.验证

[[email protected] tools]# service httpd start 【开启服务】

httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain for ServerName

httpd (pid 27656) already running

[[email protected] tools]# firefox http://localhost【访问网页】

1.Apache&AWStats

【Httpd正常工作……】

5.部署awstats系统

[[email protected] chapter05]# cd /media/2.Linux_server/chapter05/

[[email protected] chapter05]# ls

awstats-7.0.zip httpd-2.2.17.tar.gz

[[email protected] chapter05]# unzip awstats-7.0.zip -d /usr/src/

【解压缩.zip 使用unzip命令 -d参数指定解压目录】

[[email protected] chapter05]# cd /usr/src/awstats-7.0/ 【切换到解压目录】

[[email protected] awstats-7.0]# ls

docs README.TXT tools wwwroot

进入tools目录

[[email protected] awstats-7.0]# cd tools/

[[email protected] tools]# ls

awstats_buildstaticpages.pl awstats_updateall.pl logresolvemerge.pl webmin

awstats_configure.pl geoip_generator.pl maillogconvert.pl xslt

awstats_exportlib.pl httpd_conf urlaliasbuilder.pl

【执行主配置文件】

[[email protected] 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

Warning: AWStats standard directory on Linux OS is ‘/usr/local/awstats’.

If you want to use standard directory, you should first move all content

of AWStats distribution from current directory:

/usr/src/awstats-7.0

to standard directory:

/usr/local/awstats

And then, run configure.pl from this location.

Do you want to continue setup from this NON standard directory [yN] ? y 【默认应答y】

—–> 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):

> /usr/local/httpd/conf/httpd.conf 【输入Apache主配置文件位置】

—–> Check and complete web server config file ‘/usr/local/httpd/conf/httpd.conf’

Warning: You Apache config file contains directives to write ‘common’ log files

This means that some features can’t work (os, browsers and keywords detection).

Do you want me to setup Apache to write ‘combined’ log files [y/N] ? y【选择y,将日志记录方式由CustomLog /yourlogpath/yourlogfile common改为更详细的CustomLog /yourlogpath/yourlogfile combined】

Add ‘Alias /awstatsclasses “/usr/src/awstats-7.0/wwwroot/classes/”‘

Add ‘Alias /awstatscss “/usr/src/awstats-7.0/wwwroot/css/”‘

Add ‘Alias /awstatsicons “/usr/src/awstats-7.0/wwwroot/icon/”‘

Add ‘ScriptAlias /awstats/ “/usr/src/awstats-7.0/wwwroot/cgi-bin/”‘

Add ‘<Directory>’ directive

AWStats directives added to Apache config file.

—–> Update model config file ‘/usr/src/awstats-7.0/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【创建一个新的配置文件,选择y】

—–> Define config file name to create

What is the name of your web site or profile analysis ?

Example: http://www.mysite.com

Example: demo

Your web site, virtual server or profile name:

> http://www.benet.com 【输入站点名称,例如www.benet.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):

>

【输入配置文件存放路径,一般直接回车则使用默认路径/etc/awstats】

—–> Create config file ‘/etc/awstats/awstats.www.benet.com.conf’

Config file /etc/awstats/awstats.www.benet.com.conf created.

—–> Restart Web server with ‘/sbin/service httpd restart’

httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain for ServerName

httpd not running, trying to start

httpd not running, trying to start

—–> 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/src/awstats-7.0/wwwroot/cgi-bin/awstats.pl -update -config=www.benet.com

Or if you have several config files and prefer having only one command:

/usr/src/awstats-7.0/tools/awstats_updateall.pl now

Press ENTER to continue…

【按回车键结束】

A SIMPLE config file has been created: /etc/awstats/awstats.www.benet.com.conf

You should have a look inside to check and change manually main parameters.

You can then manually update your statistics for ‘www.benet.com’ with command:

> perl awstats.pl -update -config=www.benet.com

You can also read your statistics for ‘www.benet.com’ with URL:

> http://localhost/awstats/awstats.pl?config=www.benet.com

Press ENTER to finish…

【后续配置】

[[email protected] tools]# vim /etc/awstats/awstats.www.benet.com.conf

43 # Use 0 for n if you need current year, month, day, hour…

44 # Example: “/var/log/access_log.%YYYY-0%MM-0%DD-0.log”

45 # Example: “C:/WINNT/system32/LogFiles/W3SVC1/ex%YY-24%MM-24%DD-24.log”

46 # You can also use a pipe if log file come from a pipe :

47 # Example: “gzip -d </var/log/apache/access.log.gz |”

48 # If there are several log files from load balancing servers :

49 # Example: “/pathtotools/logresolvemerge.pl *.log |”

50 #

51 LogFile=”/usr/local/httpd/logs/access_log” 【修改成Apache的访问日志目录】

191 # When AWStats updates its statistics, it stores results of its analysis in

192 # files (AWStats database). All those files are written in the directory

193 # defined by the “DirData” parameter. Set this value to the directory where

194 # you want AWStats to save its database and working files into.

195 # Warning: If you want to be able to use the “AllowToUpdateStatsFromBrowser”

196 # feature (see later), you need “Write” permissions by web server user on this

197 # directory (and “Modify” for Windows NTFS file systems).

198 # Example: “/var/lib/awstats”

199 # Example: “../data”

200 # Example: “C:/awstats_data_dir”

201 # Default: “.” (means same directory as awstats.pl)

202 #

203 DirData=”/var/lib/awstats” 【指定用来存放统计数据的目录】

【创建统计数据缓存目录】

[[email protected] tools]# mkdir -p /var/lib/awstats

【执行数据库更新脚本】

[[email protected] cgi-bin]# cd /usr/src/awstats-7.0/wwwroot/cgi-bin/

[[email protected] cgi-bin]# perl awstats.pl -update -config=www.benet.com

【-config=网站域名】

Create/Update database for config “/etc/awstats/awstats.www.benet.com.conf” by AWStats version 7.0 (build 1.971)

From data in log file “/usr/local/httpd/logs/access_log”…

Phase 1 : First bypass old records, searching new record…

Direct access after last parsed record (after line 78)

Jumped lines in file: 78

Found 78 already parsed records.

Parsed lines in file: 0

Found 0 dropped records,

Found 0 comments,

Found 0 blank records,

Found 0 corrupted records,

Found 0 old records,

Found 0 new qualified records

【执行计划任务】

[[email protected] cgi-bin]# crontab -e

*/5 * * * * perl awstats.pl -update -config=www.benet.com

【启动crond进程】

[[email protected] cgi-bin]# /etc/init.d/crond restart

Stopping crond: [ OK ]

Starting crond: [ OK ]

【测试】

[[email protected] cgi-bin]# firefox http://localhost/awstats/awstats.pl?config=www.benet.com

1.Apache&AWStats

.


Llycloud ITSC , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:1.Apache&AWStats
喜欢 (1)
[]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址