V2Ray 多用户配置

Page content

自行搭建好v2ray科学上网环境后,可以设置一个不同的端口或者id再分享。

v2ray一键脚本 运行完后,会输出配置文件路径,默认是 /etc/v2ray/config.json,其内容类似这样:

{
  "log": {
    "loglevel": "info",
    "access": "/var/log/v2ray/access.log",
    "error": "/var/log/v2ray/error.log"
  },
  "inbounds": [{
    "port": 8888,
    "protocol": "vmess",
    "settings": {
      "clients": [
        {
          "id": "6be0aa25-xxxx-xxxx-xxxx-75cd3485021f",
          "level": 1,
          "alterId": 53
        }
      ]
    }
  }],
  "outbounds": [{
    "protocol": "freedom",
    "settings": {}
  },{
    "protocol": "blackhole",
    "settings": {},
    "tag": "blocked"
  }],
  "routing": {
    "rules": [
      {
        "type": "field",
        "ip": ["geoip:private"],
        "outboundTag": "blocked"
      }
    ]
  }
}

v2ray多用户分成两种:同端口不同id,不同端口不同id。v2ray两种类型都支持,接下来分别做介绍。

同端口不同id

这是最简单的配置多用户方式。方法是编辑 /etc/v2ray/config.json 文件,在”clients“一节中增加新增用户配置。

例如在上面配置基础上增加一个用户:

{
  "log": {
    "loglevel": "info",
    "access": "/var/log/v2ray/access.log",
    "error": "/var/log/v2ray/error.log"
  },
  "inbounds": [{
    "port": 8888,
    "protocol": "vmess",
    "settings": {
      "clients": [
        {
          "id": "12345625-xxxx-xxxx-xxxx-75cd3485021f",
          "level": 1,
          "alterId": 53
        },
        {
          "id": "12345625-xxxx-xxxx-xxxx-75cd3485021f",
          "level": 1,
          "alterId": 63 # 建议50-150之间的一个整数
        }
      ]
    }
  }],
# 下面的内容保持不变

注意:“#”和后面的东西都不能出现在配置文件中,上面只是为了解释说明。

编辑好文件后,先检查修改后的配置是否有语法错误 cat /etc/v2ray/config.json | python -m json.tool, 然后重启 v2ray:service v2ray restart

如果命令失败,或者 netstat -nltp | grep v2ray 输出为空,说明配置文件有错误,请仔细检查,改好后再重启。

接下来就可以用新的id和alterId配置客户端,其余信息保持不变。

不同端口不同id

如果希望端口也不一样,请按照如下步骤做:

首先编辑 /etc/v2ray/config.json 文件,按照”inbounds“格式新增入口和用户。例如新增一个端口和用户后,配置文件变成:

{
  "log": {
    "loglevel": "info",
    "access": "/var/log/v2ray/access.log",
    "error": "/var/log/v2ray/error.log"
  },
  "inbounds": [{
    "port": 8888,
    "protocol": "vmess",
    "settings": {
      "clients": [
        {
          "id": "12345625-xxxx-xxxx-xxxx-75cd3485021f",
          "level": 1,
          "alterId": 53
        }
      ]
    }
  }, # 逗号不能省,原来这里是"}],"
  # 以下是新增的配置
  {
    "port": 8889, # 端口是1000-65535之间的一个整数
    "protocol": "vmess", # 也可以改成其他协议,如果你知道怎么配置的话
    "settings": {
      "clients": [
        {
          "id": "12345625-xxxx-xxxx-xxxx-75cd3485021f", # id可以用 /usr/bin/v2ray/v2ctl uuid生成
          "level": 1, # 0或1都可以
          "alterId": 57 # 建议50-150之间的一个整数
        }
      ]
    }
  }],
 # 新增内容结束
 # 下面的内容保持不变

注意:“#”和后面的东西都不能出现在配置文件中,上面只是为了解释说明。

编辑好文件后,重启 v2ray:service v2ray restart。 如果命令失败,或者 netstat -nltp | grep v2ray 输出为空,说明配置文件有错误,请仔细检查,改好后再重启。

本文由 络壳 原创或整理,转载请注明出处