v2ray安装

v2ray安装

服务端安装

## v2ray
bash <(curl -s -L https://git.io/v2ray.sh)  
## ui+v2ray
[旧版,失效]
bash <(curl -Ls https://blog.sprov.xyz/v2-ui.sh)
[新版,失效]
bash <(curl -Ls https://raw.githubusercontent.com/vaxilu/x-ui/master/install.sh)
> https://github.com/vaxilu/x-ui
[LESS]
wget -N --no-check-certificate -q -O install.sh "https://raw.githubusercontent.com/wulabing/V2Ray_ws-tls_bash_onekey/dev/install.sh" && chmod +x install.sh && bash install.sh
> https://github.com/wulabing/V2Ray_ws-tls_bash_onekey

[docker]
docker pull wulabing/xray_docker_reality:latest
EXTERNAL_PORT=443
docker run -d --name xray_reality --restart=always -p $EXTERNAL_PORT:443 -e EXTERNAL_PORT=$EXTERNAL_PORT wulabing/xray_docker_reality:latest
> https://github.com/wulabing/xray_docker

原始版本安装v2ray

Linux 安装脚本 V2Ray 提供了一个在 Linux 中的自动化安装脚本。这个脚本会自动检测有没有安装过 V2Ray,如果没有,则进行完整的安装和配置;如果之前安装过 V2Ray,则只更新 V2Ray 二进制程序而不更新配置。

以下指令假设已在 su 环境下,如果不是,请先运行 sudo su。

运行下面的指令下载并安装 V2Ray。当 yum 或 apt-get 可用的情况下,此脚本会自动安装 unzip 和 daemon。这两个组件是安装 V2Ray 的必要组件。如果你使用的系统不支持 yum 或 apt-get,请自行安装 unzip 和 daemon

// 安裝執行檔和 .dat 資料檔

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

此脚本会自动安装以下文件:

/usr/bin/v2ray/v2ray:V2Ray 程序; /usr/bin/v2ray/v2ctl:V2Ray 工具; /etc/v2ray/config.json:配置文件; /usr/bin/v2ray/geoip.dat:IP 数据文件 /usr/bin/v2ray/geosite.dat:域名数据文件 此脚本会配置自动运行脚本。自动运行脚本会在系统重启之后,自动运行 V2Ray。目前自动运行脚本只支持带有 Systemd 的系统,以及 Debian / Ubuntu 全系列。

运行脚本位于系统的以下位置:

/etc/systemd/system/v2ray.service: Systemd /etc/init.d/v2ray: SysV 脚本运行完成后,你需要:

编辑 /etc/v2ray/config.json 文件来配置你需要的代理方式; 运行 service v2ray start 来启动 V2Ray 进程; 之后可以使用 service v2ray start|stop|status|reload|restart|force-reload 控制 V2Ray 的运行。

原始版本安装xray

bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install

客户端安装

  1. 下载当前最新版本v2ray-linux-64,解压到/opt目录下

  2. 解压并修改config.json配置,示例如下

    {
     "policy": null,
     "log": {
       "access": "",
       "error": "",
       "loglevel": "warning"
     },
     "inbounds": [
       {
         "tag": "proxy",
         "port": 10808,
         "listen": "0.0.0.0",
         "protocol": "socks",
         "sniffing": {
           "enabled": false,
           "destOverride": [
             "http",
             "tls"
           ]
         },
         "settings": {
           "auth": "noauth",
           "udp": true,
           "ip": null,
           "address": null,
           "clients": null
         },
         "streamSettings": null
       }
     ],
     "outbounds": [
       {
         "tag": "proxy",
         "protocol": "vmess",
         "settings": {
           "vnext": [
             {
               "address": "152.32.185.152",
               "port": 1990,
               "users": [
                 {
                   "id": "92d875e7-b505-4202-cf9c-f190f7d3f9db",
                   "alterId": 64,
                   "email": "t@t.tt",
                   "security": "auto"
                 }
               ]
             }
           ],
           "servers": null,
           "response": null
         },
         "streamSettings": {
           "network": "tcp",
           "security": null,
           "tlsSettings": null,
           "tcpSettings": {
             "connectionReuse": true,
             "header": {
               "type": "http",
               "request": {
                 "version": "1.1",
                 "method": "GET",
                 "path": [
                   "/"
                 ],
                 "headers": {
                   "Host": [
                     ""
                   ],
                   "User-Agent": [
                     "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36",
                     "Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46"
                   ],
                   "Accept-Encoding": [
                     "gzip, deflate"
                   ],
                   "Connection": [
                     "keep-alive"
                   ],
                   "Pragma": "no-cache"
                 }
               },
               "response": null
             }
           },
           "kcpSettings": null,
           "wsSettings": null,
           "httpSettings": null,
           "quicSettings": null
         },
         "mux": {
           "enabled": true
         }
       },
       {
         "tag": "direct",
         "protocol": "freedom",
         "settings": {
           "vnext": null,
           "servers": null,
           "response": null
         },
         "streamSettings": null,
         "mux": null
       },
       {
         "tag": "block",
         "protocol": "blackhole",
         "settings": {
           "vnext": null,
           "servers": null,
           "response": {
             "type": "http"
           }
         },
         "streamSettings": null,
         "mux": null
       }
     ],
     "stats": null,
     "api": null,
     "dns": null,
     "routing": {
       "domainStrategy": "IPIfNonMatch",
       "rules": [
         {
           "type": "field",
           "port": null,
           "inboundTag": "api",
           "outboundTag": "api",
           "ip": null,
           "domain": null
         },
         {
           "type": "field",
           "port": null,
           "inboundTag": null,
           "outboundTag": "direct",
           "ip": [
             "152.32.185.152"
           ],
           "domain": null
         },
         {
           "type": "field",
           "port": null,
           "inboundTag": null,
           "outboundTag": "direct",
           "ip": [
             "geoip:private"
           ],
           "domain": null
         },
         {
           "type": "field",
           "port": null,
           "inboundTag": null,
           "outboundTag": "direct",
           "ip": [
             "geoip:cn"
           ],
           "domain": null
         },
         {
           "type": "field",
           "port": null,
           "inboundTag": null,
           "outboundTag": "direct",
           "ip": null,
           "domain": [
             "geosite:cn"
           ]
         }
       ]
     }
    }
  3. 修改v2ray目录下systemed/v2ray.service,如下

    ExecStart=ExecStart=/opt/v2ray-linux-64/v2ray -config /opt/v2ray-linux-64/config.json
  4. 执行命令

    cp systemd/v2ray.service /lib/systemd/system/
    systemctl start v2ray
    systemctl enable v2ray

PAC代理模式

  • 安装pip后安装genpac
sudo apt install python3-pip
sudo pip3 install genpac
  • 生成pac文件
genpac --pac-compress --pac-proxy 'SOCKS5 127.0.0.1:10808' --format pac  -o /opt/v2ray-linux-64/auto.pac
# 其他语法
genpac [-h|--help] [-v|version]
       [-p PROXY|--proxy=PROXY]
       [--gfwlist-url=URL] [--gfwlist-proxy=PROXY]
       [--gfwlist-local=FILE] [--update-gfwlist-local]
       [--user-rule=RULE] [--user-rule-from=FILE]
       [-c|--config-from=FILE] [-o|--output=FILE]
       [-z|--compress]
       [--base64]

可选参数:
  -h, --help                帮助
  -v, --version             版本信息
  -p PROXY, --proxy=PROXY   PAC文件中使用的代理信息,如:
                              SOCKS 127.0.0.1:8080
                              SOCKS5 127.0.0.1:8080; SOCKS 127.0.0.1:8080
                              PROXY 127.0.0.1:8080
  --gfwlist-proxy=PROXY     获取gfwlist时的代理设置,如果你可以正常访问gfwlist,则无必要使用该选项
                            格式为 "代理类型 [用户名:密码]@地址:端口" 其中用户名和密码可选,如:
                              SOCKS5 127.0.0.1:8080
                              SOCKS5 username:password@127.0.0.1:8080
  --gfwlist-url=URL         gfwlist地址,一般不需要更改,默认:
                              https://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt
  --gfwlist-local=FILE      本地gfwlist文件地址,当在线地址获取失败时使用
  --update-gfwlist-local    当在线gfwlist成功获取且gfwlist-local存在时,更新gfwlist-local内容
  --user-rule=RULE          自定义规则,该选项允许重复使用,如:
                              --user-rule="@@sina.com"
                              --user-rule="||youtube.com"
  --user-rule-from=FILE     从文件中读取自定义规则,该选项允许重复使用
  -c FILE, --config-from=FILE
                            从文件中读取配置信息
  -o FILE, --output=FILE    输出生成的文件,如果没有此选项,将直接打印结果
  -z, --compress            压缩输出
  --base64                  base64加密输出,注意:部分浏览器并不支持经过base64加密的pac文件
  • 在deepin的 设置–网络–系统代理–自动 填入pac文件位置:

    file:///opt/v2ray-linux-64/auto.pac
  • chrome设置 chrome在linux环境不支持系统代理时,许通过第三方扩展选取pac文件进行代理控制。