Optimization and configuration services for Apache (a) - log file optimization

For optimization and configuration of Apache services

  1. Log split
  2. Log file analysis
  3. Apache compression
  4. Setting Apache Cache

First, log splitting

Apache log files default storage location:

/var/log/httpd/

Default divided Access log and error log

Embodiment log object segmentation:

With the increase of traffic to your site, Apache's default single log file will be growing.

Log files take up a lot of disk space

View the information is not convenient

Conduct of split logs:

Use built-in rotatelogs segmentation tool to achieve (loop reads the log file)

Third-party tools cronolog division

1-1 rotatelogs segmentation tool

Tool storage location:

/usr/sbin/Directory, after installing http service included.

Configuration format:

ErrorLog "| rotatelogs命令的绝对路径 -l 日志文件路径/网站名-error_%Y%m%d.log 86400"

CustomLog "| rotatelogs命令路径 -l 日志文件路径/网站名-access_%Y%m%d.log 86400" combined

among them,

In the double quotes "what", the path must be an absolute path, a relative path can not be changed

84600: split log file Every time, in seconds. (84600s = 24h)

Specific configuration examples:

(1) install and start the service (this time there will be access, error two log files log files in the directory)

[root@localhost ~]# yum install httpd -y
[root@localhost logs]# systemctl start httpd

(2) modify the configuration file

[root@localhost ~]# cd /etc/httpd/conf
[root@localhost conf]# vim httpd.conf 
40、41行,开启IPV4监听,关闭IPV6监听
 41 Listen 192.168.116.131:80
 42 #Listen 80
95行,开启域名(万一要有解析呢)
 95 ServerName www.kgc.com:80
182行,修改为
 182 ErrorLog "| /usr/sbin/rotatelogs -l logs/error_%Y%m%d.log 84600"
217行,修改为
 217    CustomLog "| /usr/sbin/rotatelogs -l logs/access_%Y%m%d.log 84600" combined
wq保存退出

(3) to restart the service, and turn off the firewall

[root@localhost conf]# systemctl stop httpd
[root@localhost conf]# systemctl start httpd
[root@localhost conf]# systemctl stop firewalld.service 
[root@localhost conf]# setenforce 0

(4) using the client to access, verify whether the log split

Optimization and configuration services for Apache (a) - log file optimization

[root@localhost conf]# ls /var/log/httpd/
  access_20191023.log  access_log  error_log                 //实验成功!!

1-1 third-party cronolog segmentation tools

Tool storage location:

/usr/sbin/Directory, to be installed manually.

Configuration format:

ErrorLog "| cronolog命令的绝对路径 -l 日志文件路径/网站名-error_%Y%m%d.log"

CustomLog "| cronolog命令路径 -l 日志文件路径/网站名-access_%Y%m%d.log" combined

Specific configuration examples:

(1) installation services and third-party http log splitting tool

[root@localhost ~]# yum install httpd -y 
[root@localhost ~]# rpm -ivh cronolog-1.6.2-14.el7.x86_64.rpm 
警告:cronolog-1.6.2-14.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 352c64e5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:cronolog-1.6.2-14.el7            ################################# [100%]

(2) modify the configuration file

[root@localhost ~]# cd /etc/httpd/conf
[root@localhost conf]# vim httpd.conf 
40、41行,开启IPV4监听,关闭IPV6监听
 41 Listen 192.168.116.131:80
 42 #Listen 80
95行,开启域名(万一要有解析呢)
 95 ServerName www.kgc.com:80
182行,修改为
 182 ErrorLog "| /usr/sbin/cronolog -l logs/www.kgc.com.error_%Y%m%d.log"
217行,修改为
 217    CustomLog "| /usr/sbin/cronolog -l logs/www.kgc.com.access_%Y%m%d.log" combined
wq保存退出

(3) to restart the service, and turn off the firewall

[root@localhost conf]# systemctl stop httpd
[root@localhost conf]# systemctl start httpd
[root@localhost conf]# systemctl stop firewalld.service 
[root@localhost conf]# setenforce 0

(4) using the client to access, verify whether the log split

[ root@localhost httpd]# ls /var/1og/httpd/
www.kgc.com.error_20191023.log www.kgc.com.error.20191024.log
[root@localhost httpd]#

Two, AWStats log file analysis

Per language is developed by an open source log analysis system

It can be used to analyze access logs Apache, Samba, Vsftpd, IIS servers, etc.

And other information in conjunction with scheduled tasks crond service can log content analysis on a regular basis

Install DNS, http service and build web site

(This is not a major, not too much to say, quickly passing.)

[root@localhost ~]# yum install bind httpd -y 

Domain established for:

www.zhy.com

Parsing the corresponding IP address is:

192.168.116.143

Http adjust the master configuration file and domain listening port

[root@localhost ~]# cd /etc/httpd/conf
[root@localhost conf]# vim httpd.conf 
40、41行,开启IPV4监听,关闭IPV6监听
 41 Listen 192.168.116.143:80
 42 #Listen 80
95行,开启域名
 95 ServerName www.zhy.com:80

The following is officially AWStats log file analysis system installation and configuration process.

(1) Installation
[root@localhost ~]# tar xzvf awstats-7.6.tar.gz         //解压AWStats软件包
awstats-7.6/
awstats-7.6/tools/
awstats-7.6/tools/awstats_buildstaticpages.pl
awstats-7.6/tools/awstats_updateall.pl
......省略
[root@localhost ~]# mv awstats-7.6 /usr/local/awstats        //安装在/usr/local/目录下
[root@localhost ~]# cd /usr/local/awstats/tools/             //进入软件包的工具目录中
[root@localhost tools]# ./awstats_configure.pl              //执行配置工具
    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                      //第一处填写http服务配置文件地址
    ......省略
    Do you want me to build a new AWStats config/profile
    file (required if first install) [y/N] ? y        //第二处为是否使用新的分析系统
    ......省略
    Your web site, virtual server or profile name:
    > www.zhy.com                                     //第三处为你配置网站的域名
    ......省略
    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):
    >                                                //第四处为分析系统配置文件位置,使用默认即可

    后面都是默认回车

Finally, get a url address: http://www.zhy.com/awstats/awstats.pl?config=www.zhy.comThis is where web analytics system, but this time can not be used.

(2) Configuration
[root@localhost tools]# cd /etc/awstats/             //分析系统配置文件位置
[root@localhost awstats]# vim awstats.www.zhy.com.conf
50行,填写日志文件地址,改为
  50 LogFile="/var/log/httpd/access_log"
220行,查看
 220 DirData="/var/lib/awstats"
 #分析系统站点,需手动创建(不建会报错)
[root@localhost awstats]# mkdir /var/lib/awstats              //创建站点
[root@localhost awstats]# vim /etc/httpd/conf/httpd.conf      //修改http服务配置文件
按G定位末行,按照下面进行修改
  <Directory "/usr/local/awstats/wwwroot">
      Options None
      AllowOverride None
  #    Order allow,deny                         //注释掉
  #    Allow from all                           //注释掉
      Require all granted                       //手动添加,允许所有用户访问
  </Directory>
[root@localhost awstats]# systemctl restart httpd

At this time, where web log analysis system has been configured, but unfortunately this time the page is completely blank, without any data, so we need to manually restart the web pages.

(3) Refresh
[root@localhost var]# cd /usr/local/awstats/tools
[root@localhost tools]# ./awstats_updateall.pl now
Running '"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=www.zhy.com -configdir="/etc/awstats"' to update config www.zhy.com
    .......省略

This step is done, the system will refresh the page data, but each want to refresh you need to awstats_updateall.plbe executed. So, you want once and for all, regular refresh, you need to crontab.

[root@localhost tools]# crontab -e 
添加
*/3 * * * * ./awstats_updateall.pl now
  #每隔3分钟,执行刷新命令
 wq保存退出
[root@localhost tools]# systemctl start crond
[root@localhost tools]# systemctl enable crond          //启动并设置开机自启
(4) optimization

At present want to enter log analysis system, you need to enter http://www.zhy.com/awstats/awstats.pl?config=www.zhy.comthis long url, want to simplify the page you need to create a special point to simplify the site.

[root@localhost tools]# cd /var/www/html/
[root@localhost html]# vim houtai.html                //新建网页
添加
  <html>
   <head>
    <meta http-equiv=refresh content="0;url=http://www.zhy.com/awstats/awstats.pl?     config=www.zhy.com">
   </head>
   <body></body>
  </html>
#专门指向日志分析系统所在网页
wq保存退出
(5) Verify

Only in the address bar www.zhy.com/houtai.htmlto enter the log file system.

Optimization and configuration services for Apache (a) - log file optimization


The above is related to Apache optimization services and related logs, configuration operation, tomorrow or the day will continue to bring follow-up experiment for you \ ~ \ ~ \ ~

Guess you like

Origin blog.51cto.com/14484404/2445256