This is the 19th day of my participation in the Genwen Challenge


A lifelong learner, practitioner and sharer committed to the path of technology, a busy and occasionally lazy original blogger, an occasionally boring and occasionally humorous teenager.

Welcome to dig friends wechat search “Jie Ge’s IT journey” attention!

How do I deploy an AWStats analysis system to monitor Web sites in Linux?

preface

In the last article “detail deployment of HTTPD service in Linux environment” we introduce the Linux environment deployment of HTTPD service basic construction, related configuration and related description, then put up the HTTPD service is definitely need to provide services for us. At the same time, the HTTPD server access log file, also recorded a large number of client access information. This information allows you to learn about Web site access, and so on;

In this article, we will introduce AWStats, a powerful free tool that presents statistics graphically to automate log analysis and statistics.

AWStats

AWStats is an open source log analysis system developed in Perl language. It can be used to analyze the Apache web server access log information, Samba, Vsftpd and other services log information, and the scheduled task Crond service to analyze the increasing log content on a regular basis.

AWStats software package download address:

Sourceforge.net/projects/aw…

www.awstats.org/

Install the AWStats software package

Unpack the downloaded AWStats package into the /usr/local/ directory on the HTTPD server.

# tar zxf awstats-7.3.tar.gz
# mv awstats-7.3 /usr/local/awstats
Copy the code

Create profiles for the sites to be counted. The AWStats system allows you to count log files for multiple sites, distinguishing different sites by their names. Before performing log file analysis, create a site statistics configuration file for each web site. In this case, run the awStats_configure. pl script provided by the AWSTATS system in the awSTATS /tools directory.

After execution, the interactive configuration terminal will be entered, and the user will be prompted to manually enter the path to the main HTTPD configuration file.

# cd /usr/local/awstats/tools/ # chmod +x awstats_configure.pl # ./awstats_configure.pl ----- AWStats awstats_configure 1.0 (Build 20140126) (c) Laurent Destailleur ----- This tool will help you 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 -----> 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. Input the conf # HTTPD. Conf configuration file pathCopy the code

After performing the preceding operations, you need to set the log type. When prompted whether to change the log type, enter “y” and the configuration script will automatically modify the httpd.conf configuration file to access the AWStats analysis system.

-----> 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
Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'
Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"'
Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"'
Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"'
Add '<Directory>' directive
AWStats directives added to Apache config file.

-----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
File awstats.model.conf updated.
Copy the code

To create a configuration file for a specific Web site, enter y as prompted to create a configuration file and specify the name of the target site to be counted www.jacktiangjwan.com directory where the configuration file is stored (/etc/awSTATS), etc. Press Enter to exit the configuration tool.

-----> 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] ? -----> Define config file name to create What is the name of your web site or profile analysis? Example: www.mysite.com Example: demo Your web site, virtual server or profile name: > www.jacktiangjwan.com # specify the target website name to be counted -----> 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): > # directly press Enter to accept the default Settings -- -- -- -- - > Create config file '/ etc/awstats/awstats.www.jacktiangjwan.com.conf config file /etc/awstats/awstats.www.jacktiangjwan.com.conf created.Copy the code

The site statistics configuration file created according to the target site name www.jacktiangjwan.com will be stored in the /etc/awstats directory, named as: Awstats. www.jacktiangjwan.con.conf, then need to modify the site specified in the configuration file is statistical analysis of web log files and specifies the directory in which the used to store data, modify the configuration is as follows;

  • LogFile: specifies the log path and the location of the web LogFile.
  • SiteDomain: specifies the site name;
  • DirData: specifies the data directory, but the specified directory needs to be created.
# # vi/etc/awstats/awstats.www.jacktiangjwan.com.conf modify configuration files, will be replaced with the following three lines of the original configuration is as follows; LogFile="/usr/local/httpd/logs/access_log" SiteDomain="www.jacktiangjwan.com" DirData="/var/lib/awstats" # mkdir /var/lib/awstatsCopy the code

Update log statistics for all sites using the awStats_updateall.pl script provided by AWStats. When the script is executed, the system automatically analyzes the newly added log content and updates the analysis result to the statistics database.

# chmod +x awstats_updateall.pl # ./awstats_updateall.pl now Running '"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=www.jacktiangjwan.com -configdir="/etc/awstats"' to update config www.jacktiangjwan.com Create/Update The database for the config "/ etc/awstats/awstats.www.jacktiangjwan.com.conf" by AWStats version 7.3 (build 20140126) From the data in log file "/usr/local/httpd/logs/access_log"... Phase 1 : First bypass old records, searching new record... Searching new records from beginning of log file... Jumped lines in file: 0 Parsed lines in file: 4 Found 0 dropped records, Found 0 comments, Found 0 blank records, Found 4 corrupted records, Found 0 old records, Found 0 new qualified records.Copy the code

Because the contents of the Web log file are constantly updated, we can set up a scheduled task to perform log analysis periodically and automatically.

# crontab -e */5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now # /etc/init.d/crond start # chkconfig --level  35 crond onCopy the code

Add the IP address of the client and the specified website name to the /etc/hosts file, and restart the HTTPD service and crond scheduled task.

Localdomain localhost4 localhost4. Localdomain4 ::1 localhost Localhost. Localhost 6 localhost6. Localdomain6 192.168.3.123 www.jacktiangjwan.com # service HTTPD restart # Service crond restart Stop crond: [OK] Crond: [OK]Copy the code

Access the AWStats analysis system

On the client side to open the access to the site in the browser address bar: www.jacktiangjwan.com/awstats/aws… After that, you can see the page of AWStats log analysis system (as shown in the figure below), which lists the detailed website visits according to the visit time, user source, browser and other categories respectively. You can also view the number of website visits, pages and files per hour, day, week or month in the left column. In addition, there are many other functions, here is not a demonstration, interested friends can build the environment to study.

When accessing the AWStats analysis system, you need to specify AWStats directory, script location, statistical target and other related information, so it is not convenient for everyone to remember, input more trouble, so we can set up an automatic jump HTML page file in the web root directory. Create a file named abc.html in /usr/local/httpd/htdocs/ and write the url of the above visit into the file. Users only need to visit www.jacktiangjwan.com/abc.html, you can automatically redirect to www.jacktiangjwan.com site AWStats Japanese page analysis system.

# vi /usr/local/httpd/htdocs/abc.html
<html>
<head>
<meta http-equiv=refresh content="0;
url=http://www.jacktiangjwan.com/awstats/awstats.pl?config=www.jacktiangjwan.com">
</head>
<body></body>
</html>
Copy the code

Recommended reading

Nginx series (a) | taught you how to setup Nginx services under Linux environment

Nginx series (2) | article take you read Nginx forward and reverse proxy

Nginx series (3) | show you read Nginx load balancing

Nginx series (4) | show you read Nginx noise separation

Nginx series (5) | using Nginx + Keepalived high availability technology

Nginx series (6) | taught you how to build LNMP architecture and deployment of a system

Deploying HTTPD in Linux


Original is not easy, if you think this article is useful to you, please kindly like, comment or forward this article, because this will be my power to output more high-quality articles, thank you!

By the way, please give me some free attention! In case you get lost and don’t find me next time.

See you next time!