CentOSはAwstatsをインストールして、nginxログを分析し、htpasswd認証を介してそれらにアクセスします



Centos Installs Awstats Analyze Nginx Logs



このノートでは、CentOS7.6にAwstats7.7をインストールし、Awstatsを使用してnginxログを分析し、php + nginxを使用してhtpasswdを介してアクセスを認証するWeb管理インターフェイスを構築するプロセスについて説明します。

まず、システムにperlがインストールされていることを確認します



perl -version This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi (with 38 registered patches, see perl -V for more detail) Copyright 1987-2012, Larry Wall

1.インストールの依存関係、機器の不足

yum -y install gcc gcc-c++ zlib-devel perl-devel perl-ExtUtils-MakeMaker httpd-tools

nginxのログを分析したいのですが、認証アクセスにはhttpd-toolsツールが使用されます。httpd-toolsにはhttpdが付属しているため、インストール後、httpdが起動状態にないことを確認し、サービスを停止して、アンインストールする必要があります。ブーツ。



#centos6.x service httpd stop chkconfig httpd off #centos7.x systemctl stop httpd systemctl disable httpd

2.nginxアクセスログを開きます
nginx.confログ形式のセクションコードを開きます

log_format main '$remote_addr - $remote_user [$time_local] '$request' ' '$status $body_bytes_sent '$http_referer' ' ''$http_user_agent' '$http_x_forwarded_for''

分析するWebサイトがwww.testawstats.xyzであるとし、サイトのnginx構成を編集して、アクセスログを記録します。

access_log /var/log/nginx/www.testawstats.xyz.access.log main

3.GeoIPライブラリをインストールします



mkdir -p /usr/local/geoip cd /usr/local/geoip wget -c http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz wget -c http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz # gzip -d GeoLiteCity.dat.gz gzip -d GeoIP.dat.gz

4. GeoIPCライブラリをインストールします

#download wget -c https://www.maxmind.com/download/geoip/api/c/GeoIP-1.4.8.tar.gz tar -zxvf GeoIP-1.4.8.tar.gz cd GeoIP-1.4.8 #installation ./configure make && make install

5. GeoIPperlライブラリをインストールします

#download wget -c https://www.maxmind.com/download/geoip/api/perl/Geo-IP-1.40.tar.gz tar -zxvf Geo-IP-1.40.tar.gz cd Geo-IP-1.40 #installation perl Makefile.PL LIBS='-L/usr/local/lib' make && make install

6.CPANライブラリをインストールします。awstatsは中国語の使用をサポートします

#download wget -c https://cpan.metacpan.org/authors/id/G/GA/GAAS/URI-1.36.tar.gz #If the certificate is prompted, add the --no-check-certificate parameter. wget -c --no-check-certificate https://cpan.metacpan.org/authors/id/G/GA/GAAS/URI-1.36.tar.gz tar -zxvf URI-1.36.tar.gz cd URI-1.36 #installation perl Makefile.PL make make install

7.awstatsをインストールします
ソース保存ディレクトリを作成します

mkdir -p /usr/local/src/awstats cd /usr/local/src/awstats

ダウンロード、解凍

wget -c https://prdownloads.sourceforge.net/awstats/awstats-7.7.tar.gz tar -zxvf awstats-7.7.tar.gz

ソースコードを実行ディレクトリにコピーします

cp -r awstats-7.7 /usr/local/awstats

8.awstatsを設定します
awstatsツールディレクトリに入る

cd /usr/local/awstats/tools/

構成ファイルを作成する

./awstats_configure.pl ----- AWStats awstats_configure 1.0 (build 20140126) (c) Laurent Destailleur ----- This tool will help you to 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 filesapache groupapacheconfhttpd.conf Config file path ('none' to skip web server setup): > none

nginxログを分析したいので、noneと入力して続行します

Your web server config file(s) could not be found. You will need to setup your web server manually to declare AWStats script as a CGI, if you want to build reports dynamically. See AWStats setup documentation (file docs/index.html) -----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf' File awstats.model.conf updated. -----> 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] ? y

入力して続行します

-----> 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.testawstats.xyz

www.testawstats.xyzと入力して続行し、最後まで戻ります
終了する前に、構成ファイルのパスと分析ログコマンドを作成するように求められます。

...... Config file /etc/awstats/awstats.www.testawstats.xyz.conf created. -----> Add update process inside a scheduler Sorry, configure.pl does not support automatic add to cron yet. You can do it manually by adding the following command to your cron: /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.testawstats.xyz ......

設定を変更する

vim /etc/awstats/awstats.www.testawstats.xyz.conf LogFile='/var/log/nginx/www.testawstats.xyz.access.log' DirData='/var/lib/awstats' LoadPlugin='decodeutfkeys' LoadPlugin='geoip GEOIP_STANDARD /usr/local/geoip/GeoIP.dat' LoadPlugin='geoip_city_maxmind GEOIP_STANDARD /usr/local/geoip/GeoLiteCity.dat'

データディレクトリを作成する

mkdir /var/lib/awstats

9.分析ログ

/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.testawstats.xyz Create/Update database for config '/etc/awstats/awstats.www.testawstats.xyz.conf' by AWStats version 7.7 (build 20180105) From data in log file '/var/log/nginx/www.testawstats.xyz.access.log'... Phase 1 : First bypass old records, searching new record... Searching new records from beginning of log file... Phase 2 : Now process new records (Flush history on disk after 20000 hosts)... Jumped lines in file: 0 Parsed lines in file: 12 Found 0 dropped records, Found 0 comments, Found 0 blank records, Found 0 corrupted records, Found 0 old records, Found 12 new qualified records.

ログファイルの分析に成功しました
10.Webインターフェイスを構築します
サイトディレクトリを作成します。ディレクトリは空になります。主にconfとサイトディレクトリが1対1で対応します。confが一緒である必要があるだけでなく、サイトディレクトリが一緒である必要があり、管理が混乱することはありません。

mkdir -p /www/awstats/wwwroot

phpファイルawstatsのwwwrootディレクトリをコピーします

cp /usr/local/awstats/tools/nginx/awstats-fcgi.php /usr/local/awstats/wwwroot/cgi-bin/fcgi.php

キーファイルを生成する

htpasswd -c -m /usr/local/htpasswd.pass youname New password: Re-type new password: Adding password for user youname

nginx構成を作成する

cp /usr/local/awstats/tools/nginx/awstats-nginx.conf /etc/nginx/conf.d/awstats-nginx.conf

nginx構成を変更します
私のawstatsインターフェースドメイン名がawstats.testawstats.xyzであるとすると、私のnginx構成は次のようになります。

server { listen 80 server_name awstats.testawstats.xyz access_log /var/log/nginx/localhost.access_log main error_log /var/log/nginx/localhost.error_log info root /www/awstats/wwwroot index index.html # Restrict access auth_basic 'Restricted' auth_basic_user_file /usr/local/htpasswd.pass # Static awstats files: HTML files stored in DOCUMENT_ROOT/awstats/ location /classes/ { alias /usr/local/awstats/wwwroot/classes/ } location /css/ { alias /usr/local/awstats/wwwroot/css/ } location /icon/ { alias /usr/local/awstats/wwwroot/icon/ } location /awstats-icon/ { alias /usr/local/awstats/wwwroot/icon/ } location /js/ { alias /usr/local/awstats/wwwroot/js/ } # Dynamic stats. location ~ ^/cgi-bin/(awredir|awstats).pl { gzip off fastcgi_pass 127.0.0.1:9000 fastcgi_param SCRIPT_FILENAME /usr/local/awstats/wwwroot/cgi-bin/fcgi.php fastcgi_param X_SCRIPT_FILENAME /usr/local/awstats/wwwroot/$fastcgi_script_name fastcgi_param X_SCRIPT_NAME $fastcgi_script_name include fastcgi_params } }

11.Webインターフェイスにアクセスします
http://awstats.testawstats.xyz/cgi-bin/awstats.pl?config=www.testawstats.xyz

このインターフェースが表示された場合、htpasswd認証設定は成功しています。ユーザー名とパスワードを入力し、続行します

わかりました、プロセス全体が開いています
12.タイミング分析ログ

#editing timed tasks crontab -e #Set time and script, execute once every day at 00:01 1 0 * * * /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.testawstats.xyz #esc Then: wq save and exit

Centosはnginxとphpをインストールします。次のアドレスに移動してください。
CentOS7ソースコードはnginx + php7.2 + mysql5.7をコンパイルしてインストールし、systemctl管理を使用します
CentOS7yumインストールnginx + php7 + mysql
nginx + php7 + mysql環境をコンパイルしてインストールするためのCentOS6.9ソースコード
CentOS6.9yumはnginx + php7 + mysql環境をインストールします
元の住所: https://www.jmsite.cn/blog-351.html