篇首语:科学上网(fanqiang)的大体原理都是通过一台在防火墙之外的VPS作为媒介,实现国内网络和防火墙之外的网络之间的互通,因此一台不受防火墙骚扰的VPS是必备的。而v2ray负责的是你的网络和VPS之间的网络通信功能。借助V2ray你可以实现透过防火墙,自由穿梭于网络。你需要做的是分别在你的设备(手机、PC等)和VPS上分别部署一下V2ray。
搭建v2ray的步骤大体如下:
- 购买一个VPS,购买后你会获得VPS的IP、root用户及密码、SSH端口等信息;
- 登录VPS,可以借助
Xshell
这个工具; - 安装v2ray,使用xshell成功登录VPS后,开始搭建;
- 在你的设备上配置与VPS对应的v2ray信息,就可以成功使用了;
在开始下面的搭建工作之前,请自行购买VPS并获得VPS的相关连接信息,保证能通过Xshell等远程连接工作连接后才能进行搭建,不论使用哪家的VPS,第一步是购买完VPS之后,获取到VPS的IP、root用户及密码、SSH端口等信息,本文主要说明搭建过程,因此这里将购买VPS及使用XSHELL进行连接的过程放在:史上最详细搬瓦工VPS注册/购买图文教程(内附优惠券) 。
下面再来通过图文,来详细说明上面的步骤。
一、环境信息
- 服务器系统: 搬瓦工(BandwagonHost) Centos 7 x86_64 bbr ;
- v2ray版本:v4.20.0
- 客户端系统:Windows 10
- VPS:我使用的是BandwagonHost 基本套餐 CN2 GIA,本博客也是在此VPS搭建
二、福利
1.搬瓦工(Bandwagon Host)
新用户通过我的推广链接(https://bwh88.net//aff.php?aff=5573 ),然后在此页面获取最新优惠券:获取搬瓦工优惠码 ,可以折扣价购买。
2.Vultr抵用券
通过此【推广链接】注册Vultr,即可获得$100,推荐刚上新的韩国机房,参见: Vultr韩国机房上线,韩国SK线路,附简单测试和新用户优惠 。
3.Digitalocean抵用券:
通过此推荐链接注册DIGITALOCEAN账号,可获得$100抵用券,推荐链接:https://m.do.co/c/e71526d11cd5
三、搭建v2ray
假设你已经使用root用户登录成功了。下面开始安装:
1.安装wget
在登录完成的窗口输入下面命令并回车进行wget安装:
yum -y install wget
2.下载脚本
安装完wget之后就可以进行下载安装v2ray的脚本了,输入如下命令并回车:
wget https://install.direct/go.sh
3.安装unzip
因为centos不支持apt-get,我们需要安装unzip,详见官方说明:
yum install -y zip unzip
4.执行安装
输入命令bash go.sh
并回车执行安装:
[[email protected] v2ray]$ bash go.sh
Installing V2Ray v3.14 on x86_64
Downloading V2Ray.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 608 0 608 0 0 2229 0 --:--:-- --:--:-- --:--:-- 2235
100 8482k 100 8482k 0 0 2501k 0 0:00:03 0:00:03 --:--:-- 2813k
Extracting V2Ray package to /tmp/v2ray.
Archive: /tmp/v2ray/v2ray.zip
creating: /tmp/v2ray/v2ray-v3.14-linux-64/
inflating: /tmp/v2ray/v2ray-v3.14-linux-64/geoip.dat
inflating: /tmp/v2ray/v2ray-v3.14-linux-64/geosite.dat
inflating: /tmp/v2ray/v2ray-v3.14-linux-64/readme.md
creating: /tmp/v2ray/v2ray-v3.14-linux-64/systemd/
inflating: /tmp/v2ray/v2ray-v3.14-linux-64/systemd/v2ray.service
creating: /tmp/v2ray/v2ray-v3.14-linux-64/systemv/
inflating: /tmp/v2ray/v2ray-v3.14-linux-64/systemv/v2ray
inflating: /tmp/v2ray/v2ray-v3.14-linux-64/v2ctl
extracting: /tmp/v2ray/v2ray-v3.14-linux-64/v2ctl.sig
inflating: /tmp/v2ray/v2ray-v3.14-linux-64/v2ray
extracting: /tmp/v2ray/v2ray-v3.14-linux-64/v2ray.sig
inflating: /tmp/v2ray/v2ray-v3.14-linux-64/vpoint_socks_vmess.json
inflating: /tmp/v2ray/v2ray-v3.14-linux-64/vpoint_vmess_freedom.json
PORT:13437
UUID:f500ecf5-e135-49c6-9ce2-78eb490d0aa9
Created symlink from /etc/systemd/system/multi-user.target.wants/v2ray.service to /etc/systemd/system/v2ray.service.
V2Ray v3.14 is installed.
5.相关命令
在首次安装完成之后,V2Ray不会自动启动,需要手动运行上述启动命令。而在已经运行V2Ray的VPS上再次执行安装脚本,安装脚本会自动停止V2Ray 进程,升级V2Ray程序,然后自动运行V2Ray。在升级过程中,配置文件不会被修改。
## 启动
systemctl start v2ray
## 停止
systemctl stop v2ray
## 重启
systemctl restart v2ray
## 开机自启
systemctl enable v2ray
关于软件更新:更新 V2Ray 的方法是再次执行安装脚本!再次执行安装脚本!再次执行安装脚本!
6.配置
如果你按照上面的命令执行安装完成之后,服务端其实是不需要再进行任何配置的,配置文件位于/etc/v2ray/config.json
,使用cat /etc/v2ray/config.json
查看配置信息。接下来进行客户端配置就行了。
说明:
- 配置文件中的id、端口、alterId需要和客户端的配置保持一致;
- 服务端使用脚本安装成功之后默认就是vmess协议;
配置完成之后重启v2ray。
7.防火墙开放端口
有的vps端口默认不开放,可能导致连接不成功,如果有这种情况,详细配置,见CentOs开放端口的方法—二、firewalld。
## 查看已开放端口
firewall-cmd --zone=public --list-ports
## 添加开放端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
四、Windows 客户端
1.下载
这里使用的是Windows图形界面v2rayN,当前版本(2020年7月11日)是3.19版本,下载地址:
注: 下载v2ray-windows-64.zip和v2rayN.zip解压到同一文件夹。
然后运行V2RayN.exe
即可。
2.配置
运行V2RayN.exe
,然后进行配置,下图中的配置信息,需要和你VPS搭建的时候的配置信息对应,VPS的v2ray配置信息位于/etc/v2ray/config.json
文件里。
如果采用上面的默认方式安装,服务端配置是协议vmess,则配置如下:
五、测试
打开浏览器,访问www.google.com
,如下:
六、深入阅读
上面的过程是最基础的搭建,如果你对ws+tls
或mkcp
等方式搭建有兴趣,或者是想对VPS进行速度优化,请参考:
本系列文章: 科学上网汇总篇。
七、问题交流
在学习的过程中遇到任何问题都可以加入Telegram群组进行交流-> 加入群组。
卡在第4步了,请问怎么把打断命令粘贴进去
打断命令是什么
您好请问第四步到底应该输入什么啊,我把所有的东西都粘贴进去然后回车没反应。。不知道怎么搞
bash go.sh
感谢博主分享!一次就操作成功了
您好 想问下怎么配置多用户呢
请问一下 服务器的端口与v2ray配置文件得端口不是一个 设置端口应该用哪个
你是想问客户端的配置吗?客户端配置的是inbounds配置项有个port就是。
请问大神,unzip在哪里下载????我电脑没有,还不让选下载!!!
请问大神,unzip windows版在哪里下载????我电脑没有,还不让下载!!!
windows解压一般是7zip,winrar之类的吧
博主你好,,我刚使用yum install firewalld firewalld-config进行安装,然后执行了systemctl start firewalld 之后,就提示我could notconnect to我的IP了。能否帮忙解决下
能否ping通?是不是启用防火墙后端口未开放?
之前Netflix限制机房的ip,不知道现在能用么
很不错的文章,完全考虑到了新手。
我有一个疑问,更新脚本前,
v2ray/config.json的配置文件要不要删了
还是再安装一次它会自动覆盖v2ray/config.json文件?
博主想问一下
2020/05/25 21:45:43 tcp:127.0.0.1:4***5 accepted tcp:www.google.com.hk:80 [proxy]
这种是显示连接正确了吗?为什么我还是连不上Google…不知道什么原因
Using the webroot path /var/www/certbot for all unmatched domains.
Waiting for verification…
Challenge failed for domain xxxx.tk
http-01 challenge for xxxx.tk
Cleaning up challenges
Some challenges have failed.
IMPORTANT NOTES:
– The following errors were reported by the server:
Domain: xxxx.tk
Type: connection
Detail: Fetching
http://xxxx.tk/.well-known/acme-challenge/stiC6bFjWuRkZff_99Q5xcadE-SO7rr9_ef2e4XAP_M:
Connection reset by peer
To fix these errors, please make sure that your domain name was
entered correctly and the DNS A/AAAA record(s) for that domain
contain(s) the right IP address. Additionally, please check that
your computer has a publicly routable IP address and that no
firewalls are preventing the server from communicating with the
client. If you’re using the webroot plugin, you should also verify
that you are serving files from the webroot path you provided.
– Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
v2ray 安装脚本安装不了了
老哥 有没有window server的教程