Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Optimization and configuration of Apache Services (1)-- Log File Optimization

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

For the optimization and configuration of Apache services log segmentation log file analysis Apache compression settings Apache cache 1. Log segmentation

The default location for Apache log files is:

/ var/log/httpd/

The default is access log and error log.

The purpose of implementing log segmentation is:

As the number of visits to the site increases, so does the single log file for Apache by default.

Log files take up a lot of disk space.

It is not convenient to view relevant information

How the log is segmented:

Using the built-in rotatelogs segmentation tool (reading log files in a loop)

Third-party tool cronolog segmentation

1-1 rotatelogs Segmentation tool

Where the tools are stored:

Under the ​ / usr/sbin/ directory, include it after installing the http service.

Configuration format:

| ErrorLog "| absolute path of the rotatelogs command-l log file path / website name-error_%Y%m%d.log 86400" CustomLog "| rotatelogs command path-l log file path / website name-access_%Y%m%d.log 86400" combined

Among them

For the content in double quotes "", the path must be absolute and cannot be changed to relative.

84600: the time in seconds for each split of log files. (84600s=24h)

Specific configuration examples:

(1) install and start the service (access and error log files will appear in the log file 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 lines 40, 41, turn on IPV4 snooping, turn off IPV6 snooping 41 Listen 192.168.116.131 root@localhost conf 80 42 # Listen 8095 lines, open the domain name (in case of resolution) 95 ServerName www.kgc.com:80182 lines, change it to 182 ErrorLog "| / usr/sbin/rotatelogs-l logs/error_%Y%m%d.log 84600" 217lines Change to 217 CustomLog "| / usr/sbin/rotatelogs-l logs/access_%Y%m%d.log 84600" combinedwq save exit

(3) 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) use the client to access and verify whether the log is segmented

[root@localhost conf] # ls / var/log/httpd/ access_20191023.log access_log error_log / / experiment successful! 1-1 third Party cronolog Segmentation tool

Where the tools are stored:

Under the ​ / usr/sbin/ directory, you need to install it manually.

Configuration format:

| ErrorLog "| absolute path of the cronolog command-l log file path / website name-error_%Y%m%d.log" CustomLog "| cronolog command path-l log file path / website name-access_%Y%m%d.log" combined

Specific configuration examples:

(1) install http service and third-party log segmentation tools

[root@localhost ~] # yum install httpd-y [root@localhost ~] # rpm-ivh cronolog-1.6.2-14.el7.x86_64.rpm warning: cronolog-1.6.2-14.el7.x86_64.rpm: header V3 RSA/SHA256 Signature Key ID 352c64e5: NOKEY preparation. # # [100%] upgrading / installing... 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 lines 40, 41, turn on IPV4 snooping, turn off IPV6 snooping 41 Listen 192.168.116.131 root@localhost conf 80 42 # Listen 8095 lines, open the domain name (in case of resolution) 95 ServerName www.kgc.com:80182 lines, change it to 182 ErrorLog "| / usr/sbin/cronolog-l logs/www.kgc.com.error_%Y%m%d.log" 217 lines Change to 217 CustomLog "| / usr/sbin/cronolog-l logs/www.kgc.com.access_%Y%m%d.log" combinedwq save exit

(3) 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) use the client to access and verify whether the log is segmented

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

It is an open source log analysis system developed by Per language

It can be used to analyze the access logs of Apache, Samba, Vsftpd, IIS and other servers.

Combined with crond and other scheduled task services, the log content can be analyzed regularly.

Install DNS, http services and set up a website

(this is not the main point. I won't repeat it too much. I'll take it quickly. )

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

The domain name of the established website is:

​ www.zhy.com

The corresponding IP address to be resolved is:

​ 192.168.116.143

Adjust the listening port and domain name in the http master configuration file

[root@localhost ~] # cd / etc/httpd/conf [root@localhost conf] # vim httpd.conf 40, line 41, enable IPV4 snooping, turn off IPV6 snooping 41 Listen 192.168.116.143 etc/httpd/conf 80 42 # Listen 8095 line, open the domain name 95 ServerName www.zhy.com:80 the following is the formal process of installing and configuring the AWStats log file analysis system. (1) install [root@localhost] # tar xzvf awstats-7.6.tar.gz / / decompress AWStats package awstats-7.6/awstats-7.6/tools/awstats-7.6/tools/awstats_buildstaticpages.plawstats-7.6/tools/awstats_updateall.pl. Omit [root@localhost ~] # mv awstats-7.6 / usr/local/awstats/ / install in / usr/local/ directory [root@localhost ~] # cd / usr/local/awstats/tools/ enter the tool directory of the package [root@localhost tools] # / awstats_configure.pl / / execute the configuration tool 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 / / fill in the http service profile address at the first place. Omit Do you want me to build a new AWStats config/profile file (required if first install) [ygamma N]? The second part is whether to use the new analysis system. Omit Your web site, virtual server or profile name: > www.zhy.com / / the third place configures the domain name of the website for you. Omit 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): > / / the fourth place is the location of the analysis system configuration file, which is followed by the default enter.

You'll end up with a url address: http://www.zhy.com/awstats/awstats.pl?config=www.zhy.com, which is the web page where the analysis system is located, but it can't be used at this time.

(2) configure [root@localhost tools] # cd / etc/awstats/ Analysis system configuration file location [root@localhost awstats] # vim awstats.www.zhy.com.conf50 line, fill in the log file address, change to 50 LogFile= "/ var/log/httpd/access_log" 220 lines, view 220 DirData= "/ var/lib/awstats" # Analysis system site Need to manually create (error will be reported if not built) [root@localhost awstats] # mkdir / var/lib/awstats / / create a site [root@localhost awstats] # vim / etc/httpd/conf/httpd.conf / / modify the http service configuration file to locate the last line by G Modify Options None AllowOverride None # Order allow,deny / / comment out # Allow from all / / comment out Require all granted / / add manually as follows to allow all users to access [root@localhost awstats] # systemctl restart httpd

At this time, the web page where the log analysis system is located has been configured, but it is a pity that the web page is completely blank and does not have any data, so we need to restart the web page manually.

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

After this step, the system web page will refresh the data, but every time you want to refresh, you need to execute the awstats_updateall.pl. Therefore, if you want to refresh once and for all on a regular basis, you need crontab.

[root@localhost tools] # crontab-e add * / 3 *. / awstats_updateall.pl now # every 3 minutes, execute refresh command wq save exit [root@localhost tools] # systemctl start crond [root@localhost tools] # systemctl enable crond / / start and set boot self-boot optimization (4)

At present, if you want to enter the log analysis system, you need to enter the super-long url of http://www.zhy.com/awstats/awstats.pl?config=www.zhy.com, and if you want to simplify, you need to create a new page in the website to simplify.

[root@localhost tools] # cd / var/www/html/ [root@localhost html] # vim houtai.html / / add # to the web page where the log analysis system is located wq save and exit (5) Verification

You only need to enter www.zhy.com/houtai.html in the address bar to enter the journal file system.

The above are the optimization and configuration operations related to the log of Apache service. We will continue to bring you follow-up experiments tomorrow and the day after tomorrow.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report