一、vnStat 安装及配置

1、更新系统并安装:apt update && apt -y upgrade && apt install vnstat

2、查看网卡名称:apt install net-tools -y && ifconfig

3、修改网卡名称:

# nano /etc/vnstat.conf

Interface "eth0"    # 若不是 eth0 则更改

4、创建对应网卡数据库:vnstat -u -i eth0

5、设置开机启动:systemctl enable vnstatd

6、重启:systemctl restart vnstatd

二、vnStat PHP 图形界面配置

1、安装 Nginx 及 PHP:

# nano /etc/apt/sources.list

# 添加如下两行
deb http://nginx.org/packages/debian/ buster nginx
deb https://packages.sury.org/php/ buster main

# apt install gnupg2 -y
# apt update && apt upgrade -y
# apt install nginx php7.4-fpm php7.4-mysql php7.4-curl php7.4-gd php7.4-mbstring php7.4-xmlrpc
# groupadd www && useradd -g www www

2、vnstat php frontend 下着地址:http://soft.vpser.net/status/vnstat/

3、新建 www 目录,tar -xvzf vnstat_php_frontend-1.5.1.tar.gz 解压到 www 目录中并赋予权限 chown -R www:www vnstat

4、编辑 vnstat/config.php 文件,将数据目录改为 /var/lib/vnstat,即 $data_dir = '/var/lib/vnstat/';

5、Nginx vnStat 配置文件:

server {
    listen 443 ssl http2;
    server_name domain.com;
    ssl_certificate /domain.cer;
    ssl_certificate_key /domain.key;
    charset utf-8;
    root /[www目录位置]/vnstat;
    index index.php index.html index.htm;

    location ~ /\. {
        deny all;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

server {
   listen 80;
   server_name domain.com;
   rewrite ^(.*)$ https://$host$1  permanent;
}

6、部分汉化,lang 文件夹新建 zh.php,内容如下:

<?php

// 侧边栏标签
$L['summary'] = '摘要';
$L['hours'] = '每时';
$L['days'] = '每日';
$L['months'] = '每月';

// 主表头
$L['Summary'] = '摘要';
$L['Top 10 days'] = '最近 10 天';
$L['Last 24 hours'] = '最近 24 小时';
$L['Last 30 days'] = '最近 30 天';
$L['Last 12 months'] = '最近 12 个月';

// 流量表列
$L['In'] = '流入';
$L['Out'] = '流出';
$L['Total'] = '统计';

// 摘要行
$L['This hour'] = '本小时';
$L['This day'] = '本日';
$L['This month'] = '本月';
$L['All time'] = '全部时间';

// 图形文字
$L['Traffic data for'] = '流量统计';
$L['bytes in'] = 'bytes 流入';
$L['bytes out'] = 'bytes 流出';

// 日期格式
$L['datefmt_days'] = '%d %B';
$L['datefmt_days_img'] = '%d';
$L['datefmt_months'] = '%B %Y';
$L['datefmt_months_img'] = '%b';
$L['datefmt_hours'] = '%l%P';
$L['datefmt_hours_img'] = '%l';
$L['datefmt_top'] = '%d %B %Y';

接着编辑 vnstat/config.php 文件,修改 $language = 'nl';$language = 'zh';

流量实时查看:vnstat -l -i eth0

Last modification:September 10th, 2020 at 01:07 pm
如果觉得我的文章对你有用,请随意赞赏