2021年12月26日星期日

Linux系统 v2rayA 安装

v2rayA 是一个 V2Ray Linux 客户端,同时兼容SS、SSR、Trojan(trojan-go)、PingTunnel协议。 支持使用http://localhost:2017 网页端进行管理.

项目地址https://github.com/v2rayA/v2rayA

二进制包下载https://github.com/v2rayA/v2rayA/releases

v2rayA用户文档https://v2raya.org/docs/prologue/introduction

本地安装命令参考:

sudo apt install /root/installer_debian_arm64_1.5.9.1698.1.deb

官方安装参考:https://v2raya.org/docs/prologue/installation/debian/

Debian / Ubuntu
v2rayA 的功能依赖于 V2Ray 内核,因此需要安装内核。
安装 V2Ray 内核 / Xray 内核
V2Ray / Xray 的官方脚本

V2Ray 安装参考:https://github.com/v2fly/fhs-install-v2ray
镜像脚本安装(推荐):
curl -Ls https://ghproxy.com/https://github.com/scdlyh/install-release/blob/main/v2ray-install-release.sh | sudo bash
  更新内核时可直接替换相同文件;
installed: /usr/local/bin/v2ray
installed: /usr/local/bin/v2ctl
installed: /usr/local/share/v2ray/geoip.dat
installed: /usr/local/share/v2ray/geosite.dat
installed: /usr/local/etc/v2ray/config.json
installed: /var/log/v2ray/
installed: /var/log/v2ray/access.log
installed: /var/log/v2ray/error.log
installed: /etc/systemd/system/v2ray.service
installed: /etc/systemd/system/v2ray@.service
镜像脚本安装(推荐):
curl -Ls https://ghproxy.com/https://github.com/scdlyh/install-release/blob/main/Xray-install-release.sh | sudo bash
安装后可以关掉服务,因为 v2rayA 不依赖于内核的 systemd 服务。
sudo systemctl disable v2ray --now
sudo systemctl disable xray --now
替换服务为 xray:

下面将以指定V2RAYA_V2RAY_BIN为xray为例,介绍各个环境下的设置方法。
systemd 管理的 v2rayA
使用 apt 等包管理器,或直接使用安装包进行安装的,一般都为这种方式。

新建文件夹 /etc/systemd/system/v2raya.service.d,然后新建一个 xray.conf 的文件,添加以下内容:
[Service] Environment="V2RAYA_V2RAY_BIN=/usr/local/bin/xray"
 
注意检查 Xray 的路径是否正确。
重载服务:
sudo systemctl daemon-reload && sudo systemctl restart xray.service
安装 v2rayA:
方法一:通过软件源安装
添加公钥
wget -qO - https://apt.v2raya.mzz.pub/key/public-key.asc | sudo apt-key add -
添加 V2RayA 软件源
echo "deb https://apt.v2raya.mzz.pub/ v2raya main" | sudo tee /etc/apt/sources.list.d/v2raya.list sudo apt updatenft
安装 V2RayA
sudo apt install v2raya

方法二:手动安装 deb 包
下载 deb 包后可以使用 Gdebi、QApt 等图形化工具来安装,
也可以使用命令行:(自行替换 deb 包所在的实际路径)
sudo apt install /root/installer_debian_arm64_1.5.9.1698.1.deb  

连续命令示例:(注意替换文件 installer_debian_arm64_1.5.9.1698.1.deb 的最新名称 最新deb 包 )
wget https://ghproxy.com/https://github.com/v2rayA/v2rayA/releases/download/v1.5.9.1698.1/installer_debian_arm64_1.5.9.1698.1.deb && sudo apt install /root/installer_debian_arm64_1.5.9.1698.1.deb && rm -rf installer_debian_arm64_1.5.9.1698.1.deb && systemctl daemon-reload && sudo systemctl start v2raya.service
启动 v2rayA / 设置 v2rayA 自动启动
从 1.5 版开始将不再默认为用户启动 v2rayA 及设置开机自动。
刷新systemctl配置
systemctl daemon-reload
启动 v2rayA
sudo systemctl start v2raya.service
停止 v2rayA
sudo systemctl stop v2raya.service
设置开机自动启动 
sudo systemctl enable v2raya.service
禁止开机自动启动
sudo systemctl disable v2raya --now
默认端口:
2017: v2rayA后端端口
20170: SOCKS协议
20171: HTTP协议
20172: 带分流规则的HTTP协议
其他端口:
32345: tproxy,透明代理所需
32346: 插件协议端口,如trojan、ssr和pingtunnel
ssh终端使用如下命令进入代理状态:
export http_proxy=http://127.0.0.1:20172
export ALL_PROXY=socks5://127.0.0.1:20170
export ALL_PROXY=socks5://192.168.0.24:7890  (局域网内设备)
执行命令  curl cip.cc (仅适用于全局代理) 或  wget http://www.google.com && rm -rf index.html  检查终端是否处于代理状态。
更多代理类型参考:Linux 让终端走代理的几种方法

附:

v2raya.service 文件内容

[Unit]
Description=v2rayA Service
Documentation=https://github.com/v2rayA/v2rayA/wiki
After=network.target nss-lookup.target iptables.service ip6tables.service
Wants=network.target

[Service]
Type=simple
User=root
LimitNPROC=500
LimitNOFILE=1000000
ExecStart=/usr/bin/v2raya --log-disable-timestamp
Environment=V2RAYA_LOG_FILE=/var/log/v2raya/v2raya.log
Restart=on-failure

[Install]
WantedBy=multi-user.target
切换 iptables 为 iptables-nft(非必要项):

对于 Debian11 用户来说,iptables 已被弃用。使用 nftables 作为 iptables 的后端以进行适配:
update-alternatives --set iptables /usr/sbin/iptables-nft update-alternatives --set ip6tables /usr/sbin/ip6tables-nft update-alternatives --set arptables /usr/sbin/arptables-nft update-alternatives --set ebtables /usr/sbin/ebtables-nft
如果你想切换回 legacy 版本:
update-alternatives --set iptables /usr/sbin/iptables-legacy update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy update-alternatives --set arptables /usr/sbin/arptables-legacy update-alternatives --set ebtables /usr/sbin/ebtables-legacy
切换后重启即可。