linux系统下科学上网

1、同步系统时间

安装ntpdate工具yum -y install ntp ntpdate

设置系统时间与网络时间同步ntpdate cn.pool.ntp.org

2、下载脚本

wget https://raw.githubusercontent.com/wulabing/V2Ray_ws-tls_bash_onekey/master/install.sh

3、按照需求安装v2ray和bbr

4、 编辑 /etc/v2ray/config.json 文件来配置你需要的代理方式

/usr/local/bin/v2ray:V2Ray 程序;
/usr/local/bin/v2ctl:V2Ray 工具;
/usr/local/etc/v2ray/config.json:配置文件;
/usr/local/share/v2ray/geoip.dat:IP 数据文件
/usr/local/share/v2ray/geosite.dat:域名数据文件

5、相关命令

## 启动systemctl start v2ray

## 停止systemctl stop v2ray

## 重启systemctl restart v2ray

## 开机自启systemctl enable v2ray

6、修改全局变量,所有用户生效

编辑文件/etc/profile,增加如下两行

export http_proxy=http://proxy.com:8080/
export https_proxy=http://proxy.com:8080/

7、 添加多用户

运用指令:cat /proc/sys/kernel/random/uuid 再创建一个用户 id ,并记住这个id号;

用指令编辑config.json文件,指令: vi /etc/v2ray/config.json ,输入 i 进入编辑模式,复制inbounds[ ]中的内容,再粘贴一个出来,如下格式,记住格式,很重要,直接看下面的代码。接下来,按esc推出,输入:号,退出编辑状态,然后输入wq,保存并退出。 然后重启V2Ray服务

8、用户流量统计功能

参见:https://guide.v2fly.org/advanced/traffic.html#%E9%85%8D%E7%BD%AE%E7%BB%9F%E8%AE%A1%E5%8A%9F%E8%83%BD

配置实例

{
    "stats": {},
    "api": {
        "tag": "api",
        "services": [
            "StatsService"
        ]
    },
    "policy": {
        "levels": {
            "0": {
                "statsUserUplink": true,
                "statsUserDownlink": true
            }
        },
        "system": {
            "statsInboundUplink": true,
            "statsInboundDownlink": true,
            "statsOutboundUplink": true,
            "statsOutboundDownlink": true
        }
    },
    "inbounds": [
        {
            "tag": "tcp",
            "port": 3307,
            "protocol": "vmess",
            "settings": {
                "clients": [
                    {
                        "email": "auser",
                        "id": "e731f153-4f31-49d3-9e8f-ff8f396135ef",
                        "level": 0,
                        "alterId": 64
                    },
                    {
                        "email": "buser",
                        "id": "e731f153-4f31-49d3-9e8f-ff8f396135ee",
                        "level": 0,
                        "alterId": 64
                    }
                ]
            }
        },
        {
            "listen": "127.0.0.1",
            "port": 10085,
            "protocol": "dokodemo-door",
            "settings": {
                "address": "127.0.0.1"
            },
            "tag": "api"
        }
    ],
    "outbounds": [
        {
            "tag": "direct",
            "protocol": "freedom",
            "settings": {}
        }
    ],
    "routing": {
        "settings": {
            "rules": [
                {
                    "inboundTag": [
                        "api"
                    ],
                    "outboundTag": "api",
                    "type": "field"
                }
            ]
        },
        "strategy": "rules"
    }
}

查看流量信息

#!/bin/bash

_APISERVER=127.0.0.1:10085
_V2CTL=/usr/local/bin/v2ctl

apidata () {
    local ARGS=
    if [[ $1 == "reset" ]]; then
      ARGS="reset: true"
    fi
    $_V2CTL api --server=$_APISERVER StatsService.QueryStats "${ARGS}" \
    | awk '{
        if (match($1, /name:/)) {
            f=1; gsub(/^"|link"$/, "", $2);
            split($2, p,  ">>>");
            printf "%s:%s->%s\t", p[1],p[2],p[4];
        }
        else if (match($1, /value:/) && f){ f = 0; printf "%.0f\n", $2; }
        else if (match($0, /^>$/) && f) { f = 0; print 0; }
    }'
}

print_sum() {
    local DATA="$1"
    local PREFIX="$2"
    local SORTED=$(echo "$DATA" | grep "^${PREFIX}" | sort -r)
    local SUM=$(echo "$SORTED" | awk '
        /->up/{us+=$2}
        /->down/{ds+=$2}
        END{
            printf "SUM->up:\t%.0f\nSUM->down:\t%.0f\nSUM->TOTAL:\t%.0f\n", us, ds, us+ds;
        }')
    echo -e "${SORTED}\n${SUM}" \
    | numfmt --field=2 --suffix=B --to=iec \
    | column -t
}

DATA=$(apidata $1)
echo "------------Inbound----------"
print_sum "$DATA" "inbound"
echo "-----------------------------"
echo "------------Outbound----------"
print_sum "$DATA" "outbound"
echo "-----------------------------"
echo
echo "-------------User------------"
print_sum "$DATA" "user"
echo "-----------------------------"

运行效果:

$ ./traffic.sh
------------Inbound----------
inbound:ws->up      0B
inbound:ws->down    0B
inbound:tcp->up     47B
inbound:tcp->down   0B
inbound:kcp->up     259MB
inbound:kcp->down   2.4GB
inbound:api->up     2.0KB
inbound:api->down   6.6KB
SUM->up:            259MB
SUM->down:          2.4GB
SUM->TOTAL:         2.6GB
-----------------------------

-------------User------------
user:me@kcp->up    240MB
user:me@kcp->down  2.3GB
SUM->up:           240MB
SUM->down:         2.3GB
SUM->TOTAL:        2.5GB
-----------------------------

脚本使用 reset 参数让调用的计数单元置零

最近在Centos7安装一些软件./configure时出现configure: error: C preprocessor “/lib/cpp” fails sanity check

可能原因没有安装kernel-headersyum install kernel-headers

已经升级到最新版本并出现问题的,退回到 v4.34.0之前的版本

bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) --version v4.34.0

八合一共存脚本+伪装站点

wget -P /root -N –no-check-certificate “https://raw.githubusercontent.com/mack-a/v2ray-agent/master/install.sh” && chmod 700 /root/install.sh && /root/install.sh

安装完毕后,shell输入【vasma】即可打开脚本

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注