v2ray, shell,

V2ray原官方安装脚本已弃用 如何迁移至新的官方脚本

DolorHunter DolorHunter Follow Sep 13, 2020 · 5 mins read

V2ray原官方安装脚本已弃用 如何迁移至新的官方脚本
Share this

V2ray 在 2020.9.2 号更新到最新版本 v4.27.5 后, 也一并更新了官方的 linux 脚本. V2ray 这次直接弃置了原先的脚本, 改用了新的脚本 v2fly/fhs-install-v2ray.

我是在手动更新的时候发现改用了新的脚本的. 虽然我有配置自动更新, 不过偶尔还是会去手动执行更新命令. 不同与以往, 这次执行命令后并没有更新, 而是给出了一条错误色, 两条警告色的输出流.

$ bash <(curl -L -s https://install.direct/go.sh)

ERROR: This script has been DISCARDED, please switch to fhs-install-v2ray project.
HOW TO USE: https://github.com/v2fly/fhs-install-v2ray
TO MIGRATE: https://github.com/v2fly/fhs-install-v2ray/wiki/Migrate-from-the-old-script-to-this

我是知道 V2fly 社区一直有在开发新的安装脚本的, 之前我一直以为他们也许是在做自动配置一类的东西, 因此也没太关注. 没想到原来是要替换原先的脚本, 我可是对之前的脚本颇有好感.

不过既然旧的没法用了, 那就按照指示去完成旧版脚本到新版脚本的迁移吧. 错误信息写的很清楚, 进入网址后指南也写的很详细, 因此不用花太多时间就能完成迁移. 我唯一觉得怪怪的地方就是命令以 ‘#’ 开头而不是 ‘$’. 附一个超链接 脚本迁移指南.

脚本迁移

下面进入正题, 讲讲如何完成脚本迁移.

注: 代码框内每行前面有 $ 的为命令, 需要输入到 Linux 服务器内并执行. 如果命令的行末为 \ (换行符), 表示命令未结束, 需要把命令复制到没有换行符的那行. 命令后如果有空行, 空行后的内容为输出流(例如 命令运行结果)或者需要写入内容.

停止 V2Ray 服務

要想卸载 V2ray, 先得停止 V2ray 的服务

$ systemctl disable v2ray.service --now

移除原有文檔

把命令改成多行的, 这样复制一次就行了

$ rm -r /usr/bin/v2ray/ \
  rm /etc/systemd/system/v2ray.service \
  rm /lib/systemd/system/v2ray.service \
  rm /etc/init.d/v2ray

遷移配置文檔

如果你还想用原先的配置, 需要把配置 (config.json) 迁移到新的目录下. 如果目录下还有其他文件, 例如证书什么的, 请迁移单个配置文件而不是迁移整个目录.

$ mv /etc/v2ray/ /usr/local/etc/

如果你不想遷移配置文檔,請在下載腳本後自行修改:

$ vim install-release.sh

JSON_PATH='/etc/v2ray/'

修改 Log 權限

我没用设置成功, 不过我也很少使用 log 功能, 因此感觉也没什么差别. 如果你也没有配置成功, 不要太难过.

nobody:nogroup
$ id nobody

uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)

$ chown -R nobody:nogroup /var/log/v2ray/
nobody:nobody
$ id nobody

uid=65534(nobody) gid=65534(nobody) groups=65534(nobody)

$ chown -R nobody:nobody /var/log/v2ray/

安装依赖

新的脚本还是使用 curl 下载的, 跟之前相同. 因此如果你没有把 curl 删掉可以跳过这一步. (如果提示权限不够, 在命令前加 sudo)

Debian / Ubuntu

$ apt update
$ apt install curl

CentOS

$ dnf makecache
$ dnf install curl

应该大部分人都是用这三个发行版吧.

下載此指令碼

$ curl -O https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
100 21613  100 21613    0     0   8732      0  0:00:02  0:00:02 --:--:--  8736

執行此指令碼

$ bash install-release.sh

Downloading V2Ray archive: https://github.com/v2fly/v2ray-core/releases/download/v4.27.0/v2ray-linux-64.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   631  100   631    0     0    331      0  0:00:01  0:00:01 --:--:--   331
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
100 12.2M  100 12.2M    0     0   841k      0  0:00:14  0:00:14 --:--:-- 1899k
Downloading verification file for V2Ray archive: https://github.com/v2fly/v2ray-core/releases/download/v4.27.0/v2ray-linux-64.zip.dgst
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   636  100   636    0     0    294      0  0:00:02  0:00:02 --:--:--   295
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
100   590  100   590    0     0    133      0  0:00:04  0:00:04 --:--:--   282
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  zip
The following NEW packages will be installed:
  unzip
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 172 kB of archives.
After this operation, 580 kB of additional disk space will be used.
Get:1 http://mirrors.163.com/debian buster/main amd64 unzip amd64 6.0-23+deb10u1 [172 kB]
Fetched 172 kB in 1s (173 kB/s)   
Selecting previously unselected package unzip.
(Reading database ... 31383 files and directories currently installed.)
Preparing to unpack .../unzip_6.0-23+deb10u1_amd64.deb ...
Unpacking unzip (6.0-23+deb10u1) ...
Setting up unzip (6.0-23+deb10u1) ...
Processing triggers for mime-support (3.62) ...
Processing triggers for man-db (2.8.5-2) ...
info: unzip is installed.
info: Extract the V2Ray package to /tmp/tmp.vk9AF2EqKA/ and prepare it for installation.
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/00_log.json
installed: /usr/local/etc/v2ray/01_api.json
installed: /usr/local/etc/v2ray/02_dns.json
installed: /usr/local/etc/v2ray/03_routing.json
installed: /usr/local/etc/v2ray/04_policy.json
installed: /usr/local/etc/v2ray/05_inbounds.json
installed: /usr/local/etc/v2ray/06_outbounds.json
installed: /usr/local/etc/v2ray/07_transport.json
installed: /usr/local/etc/v2ray/08_stats.json
installed: /usr/local/etc/v2ray/09_reverse.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/[email protected]
removed: /tmp/tmp.vk9AF2EqKA/
info: V2Ray v4.27.0 is installed.
You may need to execute a command to remove dependent software: apt remove curl unzip
Please execute the command: systemctl enable v2ray; systemctl start v2ray

运行 V2ray

首次安装完成或者完成迁移之后,V2Ray 不会自动启动,需要手动运行启动命令。

注意: 如果首次安装记得写配置文件!!

$ systemctl start v2ray

设置开机自启动 V2Ray

$ systemctl enable v2ray

检查一下 V2ray 运行状态

检查一下运行状态, 确保配置读入没有问题, 且运行正常.

看看是不是 active (显示绿色), 如果显示红色表示运行不正常.

$ systemctl status v2ray

● v2ray.service - V2Ray Service
   Loaded: loaded (/etc/systemd/system/v2ray.service; disabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-08-16 23:17:13 CST; 41min ago
 Main PID: 1984 (v2ray)
    Tasks: 6 (limit: 2359)
   Memory: 6.9M
   CGroup: /system.slice/v2ray.service
           └─1984 /usr/local/bin/v2ray -confdir /usr/local/etc/v2ray/

Aug 16 23:17:13 debian v2ray[1984]: v2ctl> Read config:  /usr/local/etc/v2ray/01_api.json
Aug 16 23:17:13 debian v2ray[1984]: v2ctl> Read config:  /usr/local/etc/v2ray/02_dns.json
Aug 16 23:17:13 debian v2ray[1984]: v2ctl> Read config:  /usr/local/etc/v2ray/03_routing.json
Aug 16 23:17:13 debian v2ray[1984]: v2ctl> Read config:  /usr/local/etc/v2ray/04_policy.json
Aug 16 23:17:13 debian v2ray[1984]: v2ctl> Read config:  /usr/local/etc/v2ray/05_inbounds.json
Aug 16 23:17:13 debian v2ray[1984]: v2ctl> Read config:  /usr/local/etc/v2ray/06_outbounds.json
Aug 16 23:17:13 debian v2ray[1984]: v2ctl> Read config:  /usr/local/etc/v2ray/07_transport.json
Aug 16 23:17:13 debian v2ray[1984]: v2ctl> Read config:  /usr/local/etc/v2ray/08_stats.json
Aug 16 23:17:13 debian v2ray[1984]: v2ctl> Read config:  /usr/local/etc/v2ray/09_reverse.json
Aug 16 23:17:13 debian v2ray[1984]: 2020/08/16 23:17:13 [Warning] v2ray.com/core: V2Ray 4.27.0 start
lines 1-19/19 (END)

运行不正常通常是因为配置的问题, 先关闭 V2ray 调整一下配置再启动 V2ray 检查一下运行状态.

$ systemctl stop v2ray
$ systemctl start v2ray

或者直接 restart 重启 V2ray

$ systemctl restart v2ray

调整配置直到 V2ray 运行状态正常即可.

升级更新

重新执行一遍安装脚本就可以更新了,在更新过程中会自动重启 V2Ray,配置文件保持不变。跟之前完全一样.

$ bash install-release.sh

设置 Crontab 任务定时自动更新

这部分为进阶内容, 可能会比较难, 如果配不成也没什么关系. P.S.本来打算写到新白话里的被拒了. 哭哭.

Crontab 是 Linux 内建的机制,可以根据设置的时间参数来执行例行性的工作排程。如果你不想手动更新 V2ray,可以创建一个 Crontab 任务定时自动更新。

编辑该使用者的 Crontab 指令

$ crontab -e

初次使用可能要选择编辑器, 如果没有特别偏好选择推荐的 nano 就行了.

crontab 任务参数依序是分钟, 小时, 日期, 月份, 星期, 命令 (参数范围为 0-59, 0-23, 1-31, 1-12, 0-6)

* * * * * command

举个例子:

  • 每日 3 点 0 分定时更新
0 3 * * * bash install-release.sh > /dev/null
  • 每周四 3,15 点 0 分定时更新
0 3,15 * * 4 bash install-release.sh > /dev/null

其中, > /dev/null 表示把输出流丢弃.

注意: 如果无法自动执行, 请把命令改为全路径形式 /usr/bin/bash /root/install-release.sh.

在 nano 编辑器内, 完成编辑后 Ctrl+S 保存, Ctrl+X 退出.

设定完成后重新载入 crontab 配置, 以完成定时任务的设置.

$ /etc/init.d/cron reload
[ ok ] Reloading configuration files for periodic command scheduler: cron.

参考资料:

Join Newsletter
Get the latest news right in your inbox. We never spam!
DolorHunter
Written by DolorHunter
Developer & Independenet Blogger