Apache optimized Application II (log management)
Directory
The first part of the preparatory work
Second part installs Apache service
Part Three log management one (configuration log split)
Part IV Log Management II (configuration Awstats log analysis software)
The first part of the preparatory work
One: server: Linux system-centos 7.4;
IP Address: 192.168.80.10
Client: Take WIN7 as an example, test the result of verification, and the server in the same network segment;
IP Address: 192.168.80.2
Two: Prepare the package for compression
Apr-1.6.2.tar.gz and apr-util-1.6.0.tar.gz are required plugins for httpd2.4 later versions and must be installed
Third: Close the firewall with SELinux
Second part installs Apache service
One: Install the compilation tools and plugins
[[email protected] ~]# yum-y install \
GCC \
gcc-c++ \
Make \
Pcre-devel \
Expat-devel \
Perl
Two: Unzip:
[Email protected] ~]# Tar XF apr-1.6.2.tar.gz
[Email protected] ~]# Tar XF apr-util-1.6.0.tar.gz
[Email protected] ~]# Tar XF httpd-2.4.29.tar.bz2
[Email protected] ~]# MV apr-1.6.2 HTTPD-2.4.29/SRCLIB/APR
[Email protected] ~]# MV apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
Three: Configuration (custom personalization)
[[Email protected] ~]# CD httpd-2.4.29//must enter the installation directory
[Email protected] httpd-2.4.29]#/configure \
--PREFIX=/USR/LOCAL/HTTPD \//Specifies to install the HTTPD program into the/USR/LOCAL/HTTPD directory
--ENABLE-SO \//Enable dynamic load module function
--enable-rewrite \//Enable Web page address rewriting for website optimization and Directory Migration
--enable-charset-lite \//enable character set support to support Web pages that are encoded using a variety of character sets
--ENABLE-CGI//Enable CGI scripting support for extended Web site application access
IV: Compilation and Installation
[[email protected] httpd-2.4.29]# make && make install
To add a httpd service to a system service
[Email protected] httpd-2.4.29]# CP/USR/LOCAL/HTTPD/BIN/APACHECTL/ETC/INIT.D/HTTPD
[Email protected] httpd-2.4.29]# VI/ETC/INIT.D/HTTPD
Add the following two lines (Note that "#" cannot be omitted):
Save exit
[[email protected] httpd-2.4.29]# chkconfig--add httpd//Add httpd to service Manager
[[email protected] httpd-2.4.29]# Systemctl daemon-reload//heavy-duty system System Manager
V: Edit httpd master configuration file
[Email protected] httpd-2.4.29]# vi/usr/local/httpd/conf/httpd.conf
Modify the following content:
ServerName localhost
Save exit
Optimized execution path (the original path of the executing program file is not in the PATH environment variable, do a soft link to make it executable)
[Email protected] httpd-2.4.29]# ln-s/usr/local/httpd/conf/httpd.conf/etc/
[Email protected] httpd-2.4.29]# ln-s/usr/local/httpd/bin/*/usr/local/bin/
Check for syntax errors
[Email protected] httpd-2.4.29]# httpd–t
Or: [[email protected] httpd-2.4.29]# apachectl–t
View Program version
Six: Start the service
[Email protected] httpd-2.4.29]# systemctl start httpd
[[email protected] httpd-2.4.29]# Systemctl enable httpd//set httpd to boot
[Email protected] httpd-2.4.29]# NETSTAT-ANPT | grep 80//View httpd service Run status
Seven: Validation
Accessing the server with the WIN7 client
Browser access: http://192.168.80.10
Validation successful
(Note that the default content of the Web page is:/usr/local/httpd/htdocs/index.html)
Part Three log management one (configuration log split)
[[email protected] logs]# cd/usr/local/httpd/logs///apache default log path
One: The following configuration log splits:
[[email protected] ~]# vi/etc/httpd.conf//Enter HTTP Master config file
- Error log Configuration
Pass the log to the Rotatelogs tool by pipe-l refers to using local time 86400 to indicate that the log is separated by 1 days, in seconds
Save exit
[[email protected] ~]# apachectl–t//Check syntax error
No errors
- Correct log configuration
[Email protected] ~]# vi/etc/httpd.conf
[[email protected] ~]# systemctl start httpd//Restart Service
Three: Verify, Win7 Access Apache Web page, and then view log information
Split Success (note: The log is generated only after access, the error log is an operation error, if there is no error, it is not displayed)
Part IV Log Management II (configuration Awstats log analysis software)
Note: Awstats does not support parsing the split log, if the log is split, it needs to be modified back
[Email protected] logs]# vi/etc/httpd.conf
Save exit
One: Loading the CGI module
[Email protected] ~]# apachectl-d dump_modules | grep CGI//Verify that the CGI module is loaded
[Email protected] ~]# ls/usr/local/httpd/modules/| grep CGI//Verify that the CGI module has been compiled
, the CGI module was not loaded, but the CGI module was compiled
[[email protected] ~]# vi/usr/local/httpd/conf/httpd.conf//manual loading
Add the following content:
LoadModule Cgid_module modules/mod_cgid.so
LoadModule Cgi_module modules/mod_cgi.so
Save exit
[[Email protected] ~]# tar xzvf awstats-7.6.tar.gz//decompression Awstats software
[[Email protected] ~]# MV Awstats-7.6/usr/local/awstats//Create configuration directory
Two: Set up the DNS service (here directly modify the Hosts file, equivalent to build a DNS service)
- Modifications on the server:
[Email protected] ~]# vi/etc/hosts
Last added:
192.168.80.10 www.aa.com
Exit Save
- Win7 under Change:
Path C:\WINDOWS\SYSTEM32\DRIVERS\ETC
Open the Hosts file in Notepad, and finally add a line: 192.168.80.10 www.aa.com, save exit
Three: Awstats simultaneous analysis of data from multiple sites
- Modify Host Name
[[email protected] ~]# vi/etc/httpd.conf//Edit Apache master configuration file
ServerName www.aa.com//define host name
Save exit
[[email protected] ~]# grep "ServerName"/etc/httpd.conf//See if the changes were successful.
- Edit Awstats Configuration Script
[Email protected] ~]# cd/usr/local/awstats/tools/
[[email protected] tools]#./awstats_configure.pl//automatic configuration script, according to the prompt to fill
then enter to finish
[[email protected] tools]# systemctl restart httpd//Restart HTTP service for log format to take effect
- Edit the master configuration file for the Awstats program
[[email protected] tools]# vi/etc/awstats/awstats.www.aa.com.conf//Modify the program's main configuration file
Logfile= "/usr/local/httpd/logs/access_log"//modify log file location
Dirdata= "/var/lib/awstats"//Manually establish data storage location for each fetch
Save exit
- Create a Awstats data log file
[[email protected] tools]# mkdir/var/lib/awstats//Create data file
[Email protected] tools]# systemctl restart httpd
If you have previously modified the log format, you need to clear
[Email protected] tools]# cd/usr/local/httpd/logs/
[Email protected] logs]# rm-f *log
[Email protected] logs]# systemctl restart httpd
[Email protected] logs]# cd/usr/local/awstats/tools/
[Email protected] tools]# chmod +x awstats_updateall.pl
[[email protected] tools]#./awstats_updateall.pl now//manually collect data once
- Do a recurring planning task
[Email protected] tools]# crontab–e
/5 */usr/local/awstats/tools/awstats_updateall.pl now//manual capture every five minutes
[Email protected] tools]# systemctl status Crond
[Email protected] tools]# Systemctl enable Crond
[Email protected] tools]# Systemctl list-unit-files | grep Crond
- Check Virtual directory Authorization
[Email protected] tools]# vi/etc/httpd.conf
At the end of the file, add the following
Save exit
[[email protected] tools]# systemctl restart httpd//Restart Service
Four: Validation
Win7 under browser access
http://192.168.80.10/awstats/awstats.pl?config=www.aa.com//Access test log system working condition
V: Optimize Statistics page access by configuring page Auto Jump
[Email protected] ~]# vi/usr/local/httpd/htdocs/index.html
<meta Http-equiv=refresh content= "0;url=http://www.aa.com/awstats/awstats.pl? Config=www.aa.com ">//Jump, when accessing www.aa.com, jump to the analysis system
<body></body>
Save exit
[[Email protected] ~]# service httpd restart//restart HTTP Services
Six: Win7 under browser access www.aa.com
Note: The Hosts file must be modified on both the server and the client if the server does not do DNS
Centos7.4-apache Optimization Application II (log management)