尝试 V2Ray:一步步指南

Home PDF Audio

V2Ray 是一个多功能的平台,用于构建代理以绕过网络限制并增强在线隐私。在本指南中,我们将带您在 Ubuntu 服务器上安装和配置 V2Ray。我们将涵盖安装步骤、配置文件、常见问题以及验证方法,确保一切顺利运行。

目录

  1. 安装
  2. 配置
  3. 管理 V2Ray 服务
  4. 常见问题与故障排除
  5. 验证
  6. 结论
  7. 附加提示

安装

首先,使用提供的安装脚本下载并安装 V2Ray。

ubuntu@ip-172-26-0-236:~$ curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh > in.sh

运行安装脚本:

chmod +x in.sh
sudo ./in.sh

安装输出:

[Install]
WantedBy=multi-user.target

info: V2Ray v5.22.0 已安装。

注意: 脚本建议在必要时移除依赖软件:

apt purge curl unzip

配置

V2Ray 配置 (config.json)

此 JSON 文件定义了 V2Ray 的入站和出站设置。

{
    "inbounds": [
        {
            "port": 1080,
            "listen": "0.0.0.0",
            "protocol": "vmess",
            "settings": {
                "clients": [
                    {
                        "id": "9f02f6b2-1d7d-4b10-aada-69e050f1be6b",
                        "level": 0,
                        "alterId": 0,
                        "email": "example@v2ray.com",
                        "security": "auto"
                    }
                ]
            },
            "streamSettings": {
                "network": "tcp"
            },
            "sniffing": {
                "enabled": true,
                "destOverride": [
                    "http",
                    "tls"
                ]
            },
            "tag": "vmess-inbound",
            "udp": true
        }
    ],
    "outbounds": [
        {
            "protocol": "freedom",
            "settings": {},
            "tag": "outbound-freedom",
            "udp": true
        }
    ],
    "log": {
        "loglevel": "debug",
        "access": "/var/log/v2ray/access.log",
        "error": "/var/log/v2ray/error.log"
    },
    "stats": {
        "enabled": false
    },
    "environment": {
        "v2ray.vmess.aead.forced": "false"
    }
}

关键点:

代理配置 (config.yaml)

此 YAML 文件配置了代理设置、DNS 和流量路由规则。

port: 7890
socks-port: 7891
mixed-port: 7892
allow-lan: true
mode: Rule
log-level: info
external-controller: 0.0.0.0:9090
experimental:
  ignore-resolve-fail: true

dns:
  enable: false
  listen: 0.0.0.0:53
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  default-nameserver:
    - 119.29.29.29
    - 223.5.5.5
  nameserver:
    - https://223.5.5.5/dns-query
    - https://1.12.12.12/dns-query
  fake-ip-filter:
    - "*.lan"
    - "*.localdomain"
    - "*.example"
    - "*.invalid"
    - "*.localhost"
    - "*.test"
    - "*.local"

proxies:
  - name: "My VMess Proxy"
    type: vmess
    server: 54.254.0.0
    port: 1080
    uuid: "9f02f6b2-1d7d-4b10-aada-0000"
    alterId: 0
    cipher: "aes-128-gcm"
    udp: true

proxy-groups:
  - name: "Proxy"
    type: select
    proxies:
      - "My VMess Proxy"

rules:
  - IP-CIDR,192.168.0.0/16,DIRECT
  - IP-CIDR,10.0.0.0/8,DIRECT
  - IP-CIDR,127.0.0.0/8,DIRECT
  - GEOIP,CN,DIRECT
  - MATCH,Proxy

关键点:

注意: 确保代理配置中的 cipherconfig.json 中的 security 设置相匹配。


管理 V2Ray 服务

安装和配置完成后,您需要使用 systemctl 来管理 V2Ray 服务。

启用并启动 V2Ray

启用 V2Ray 开机自启:

sudo systemctl enable v2ray

启动 V2Ray 服务:

sudo systemctl start v2ray

预期输出:

Created symlink /etc/systemd/system/multi-user.target.wants/v2ray.service → /etc/systemd/system/v2ray.service.

验证服务状态:

sudo systemctl status v2ray

示例输出:

● v2ray.service - V2Ray Service
   Loaded: loaded (/etc/systemd/system/v2ray.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2024-04-27 12:55:00 UTC; 1min 30s ago
 Main PID: 14425 (v2ray)
    Tasks: 8 (limit: 4915)
   Memory: 36.7M
   CGroup: /system.slice/v2ray.service
           └─14425 /usr/local/bin/v2ray run -config /usr/local/etc/v2ray/config.json

常见问题与故障排除

启用 V2Ray 时的认证失败

错误信息:

==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-unit-files ====
Authentication is required to manage system service or unit files.
Authenticating as: Ubuntu (ubuntu)
Password:
polkit-agent-helper-1: pam_authenticate failed: Authentication failure
==== AUTHENTICATION FAILED ====
Failed to enable unit: Access denied

解决方案:

确保使用 sudo 来执行需要管理员权限的命令。

正确的命令:

sudo systemctl enable v2ray

验证

启动 V2Ray 服务后,验证其是否正常运行。

检查正在运行的进程

ps aux | grep v2ray

示例输出:

nobody     14425  4.4  8.6 5460552 36736 ?       Ssl  12:55   0:00 /usr/local/bin/v2ray run -config /usr/local/etc/v2ray/config.json
ubuntu     14433  0.0  0.5   7076  2176 pts/1    S+   12:55   0:00 grep --color=auto v2ray

使用 Telnet 测试连接性

telnet your_server_ip 1080

预期行为:


结论

在 Ubuntu 服务器上设置 V2Ray 包括安装软件、配置入站和出站设置、使用 systemctl 管理服务以及验证其运行情况。通过遵循本指南,您应该能够拥有一个功能齐全的 V2Ray 设置,提升网络隐私并有效绕过限制。

如果您遇到任何问题或有疑问,欢迎在下方留言!


附加提示

祝您代理顺利!


Back 2025.02.27 Donate