centos7部署AWStats日志分析系统

发布于:2025-06-10 ⋅ 阅读:(329) ⋅ 点赞:(0)

1.基础环境准备(http)

yum install -y httpd    # 安装Apache服务
systemctl enable httpd  # 设置Apache开机自启
systemctl start httpd   # 启动Apache

2.安装AWStats(两种方法)

方法一:使用yum安装

yum install -y awstats

方法二:源码安装

# 1. 下载最新版本(访问 https://github.com/eldon/awstats/releases 找最新tar.gz 链接)
cd /tmp
wget https://github.com/eldon/awstats/archive/refs/tags/7.8.tar.gz  #若7.8失效,换其他版本
 
# 2. 解压并移动到指定目录
tar -zxvf 7.8.tar.gz
mv awstats-7.8 /usr/local/awstats
 
# 3. 创建软链接(方便 Apache 访问)
ln -s /usr/local/awstats/wwwroot/cgi-bin/ /var/www/cgi-bin/awstats
ln -s /usr/local/awstats/wwwroot/icon/ /var/www/html/awstatsicons

3.配置AWStats

一:创建站点配置文件

# yum 安装路径
cp /etc/awstats/awstats.model.conf /etc/awstats/awstats.ip.conf
 
# 源码安装路径
cp /usr/local/awstats/config/awstats.model.conf /usr/local/awstats/config/awstats.ip.conf

替换ip为你的域名或服务器IP(如192.168.17.128)

二:编辑配置文件

# yum 安装路径
vim /etc/awstats/awstats.ip.conf
 
# 源码安装路径
vim /usr/local/awstats/config/awstats.ip.conf

修改以下关键参数(根据实际情况调整):

LogFile="/var/log/httpd/access_log"   # Apache 访问日志路径(默认)
SiteDomain="192.168.17.128"             # 你的域名或服务器 IP
HostAliases="localhost 127.0.0.1"     # 别名
DirData="/var/lib/awstats"            # 统计数据存储目录
Lang="cn"                             # 启用中文界面(新增)

4.配置配置Apache访问(两种方法)

方法一:yum安装的Apache配置

# 1. 创建 Apache 配置文件
vim /etc/httpd/conf.d/awstats.conf


# 2. 写入以下内容(限制访问 IP,增强安全)
<Directory "/usr/share/awstats/wwwroot">
    Options None
    AllowOverride None
    <IfModule mod_authz_core.c>
        # Apache 2.4    
          Require all granted
    </IfModule>
    <IfModule !mod_authz_core.c>
        # Apache 2.2
        Order allow,deny
        Allow from all
    </IfModule>
</Directory>

# 3. 重启 Apache 生效
systemctl restart httpd

方式二:源码安装的Apache配置

# 1. 创建 Apache 配置文件
vim /etc/httpd/conf.d/awstats.conf
 
# 2. 写入以下内容(基于软链接路径)
Alias /awstats /var/www/cgi-bin/awstats
<Directory "/var/www/cgi-bin/awstats">
    Options ExecCGI -Indexes
    AddHandler cgi-script .pl
    Order allow,deny
    Allow from 127.0.0.1        # 允许本地访问
    Allow from 10.10.10.128     # 允许服务器自身 IP 访问
</Directory>
 
# 3. 重启 Apache 生效
systemctl restart httpd

5.访问AWStats页面

浏览器访问以下地址

http://192.168.17.128/awstats/awstats.pl?config=ip

ip替换为你的域名或服务器IP

如图


网站公告

今日签到

点亮在社区的每一天
去签到