一、时间校准

确保服务端与客户端时间相差在90秒内,否则会连接失败,具体命令如下:

1
2
3
4
5
6
7
8
# 查看设置之前系统时间
date -R
# 将硬件时钟设置为本地时区
timedatectl set-local-rtc 1
# 将本地时区设置为中国上海上海,也就是东八区
timedatectl set-timezone Asia/Shanghai
# 查看设置之后系统时间,确认是否设置成功
# 正确示例:Thu, 09 Jun 2022 22:01:50 +0800

二、用官方脚本安装服务端

1、下载脚本

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

下载完当前目录会多出一个install-release.sh文件

2、执行脚本

1
bash install-release.sh

以下是正确的安装信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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/v2ray@.service
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

3、安装后重要文件说明

  • /etc/systemd/system/v2ray.service 是v2ray启动的执行文件
  • /usr/local/etc/v2ray/config.json 是v2ray的配置文件,后续配置主要在这里
  • /var/log/v2ray/access.log和/var/log/v2ray/error.log 是v2ray的日志文件

三、启动前的配置

1、打开配置文件

1
vim /usr/local/etc/v2ray/config.json

2、将下面配置粘贴进去

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"inbounds": [
{
"port": 16788, // 服务器监听端口
"protocol": "vmess", // 主传入协议
"settings": {
"clients": [
{
"id": "b831381d-6324-4d53-ad4f-8cda48b30811", // 用户 ID,客户端与服务器必须相同
"alterId": 0
}
]
}
}
],
"outbounds": [
{
"protocol": "freedom", // 主传出协议
"settings": {}
}
]
}

3、执行如下命令推出保存

1
wq

四、启动

1、执行启动命令

1
systemctl start v2ray

2、其他重要的命令

1
2
3
4
5
6
7
8
# 设置开机自启动V2Ray
systemctl enable v2ray
# 查看v2ray运行状态
systemctl status v2ray
# 停止v2ray
systemctl stop v2ray
# 重启v2ray
systemctl restart v2ray