好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

apache中与日志有关的模块|--enable-module-Apache教程

在维护 服务器 的 工作 中, 日志 占很大的一部分,本文详细介绍了 apache 服务器与日志相关的模块。 软件
mod_log_sql 把日志记到 mysql 中的模块  http://www.apache.org
apache  web服务器   http://www.apache.org

准备工作( 安装 apache)
./configure --prefix=/www/apache --disable-module=all --enable-module=alias
--enable-module=access --enable-module=auth --enable-module=log_config  --enable-module=log_agen
--enable-module=log_common
--enable-module=dir --enable-module=mime --enable-module=so
make
make install


Core模块,提供ErrorLog,LogLevel
ErrorLog /www/apache/logs/error_log #定义error log的存放位置
LogLevel warn  #定义error log的级别。只有满足级别的事件才被记录


log_config模块
LogFormat format [nickname]   #定义访问日志的格式
LogFormat "%{User-agent}i" agent   
Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)

LogFormat "%h %l %u %t "%r" %>;s %b" common
192.168.0.15 - - [26/Sep/2003:18:22:09 +0800] "GET / HTTP/1.1" 404 272

LogFormat中参数含义
   %a    访问者ip
   %A    local ip
   %B    不包括HTTP 头发送的数据字节数
   %b     以CLF格式表示的发送字节数
   %c     在response后的 连接 状态
   %f     请求的文件名
   %h     客户端host
   %H     请求使用的协议
   %m     请求的方法get,put...
   %P     提供服务的端口
   %p     为请求提供服务的子进程ID
   %r     请求的第一行
   %s     status/
   %u     remote user
   %U     请求的URL path
CustomLog  file|pipe  format
CustomLog  logs/access.log common
CustomLog  "|/bin/gzip -c >;>; logs/access.log.gz" common

mod_log_mysql模块
这个apache模块允许你把日志记录到mysql 数据库 中去。Combined Log Format格式会被记录到 数据库 中。
DSO方式 安装 该模块
# tar zxf mod_log_sql.tar.gz -C /usr/local/src  
# cd /usr/local/src/mod_log_sql
修改Makefile文件,修改下面的路径信息以符合你的安装
APACHEINSTALLED:  
APACHEHEADERS: 用'locate httpd.h'查找路径
MYSQLLIBRARIES: 用'locate libmysqlclient.so'查找路径
MYSQLHEADERS: 用'locate mysql.h'查找路径
#make dso
#make dsoinstall

为使用mod_log_mysql准备mysql
创建数据库accesslog
mysqladmin -u username -p create accesslog
mysql accesslog < /path/mod_log_sql/create_tables.sql
grant insert on accesslog.* to weblog@localhost identified by 'pass';


把下面两行加入httpd.conf
LoadModule sql_log_module libexec/mod_log_sql.so
AddModule mod_log_sql.c
LogSQLLoginInfo localhost weblog pass
LogSQLDatabase accesslog
LogSQLSocketFile /tmp/mysql.sock
LogSQLTransferLogTable access_log

重起服务
#apachectl restart   
ok!mod_log_sql的安装配置就到这里了。 网站 运行一段时间以后你可以从mysql数据库里获得访问日志了 《 apache中与日志有关的模块 》由 第二电脑网 原创提供,转载请注明: http://www.002pc.com/master/College/Server/Apache/17971.html

查看更多关于apache中与日志有关的模块|--enable-module-Apache教程的详细内容...

  阅读:75次