背景
最近收到腾讯云的邮寄,说我的香港主机违规。
违规内容:存在通过技术手段使其成为跨境访问节点等行为。
主机直接不给我访问了,哎,GG。
尝试使用我以前的用了好几年的服务商Linode主机。
1.购买Linode主机
linode现在提供了每个月只要5刀的Nanode 节点,感觉自己也已经够用了。我帮linode所有的美国节点进行了一下测速,跑了几天发现Fremont的节点延迟和稳定性都蛮好(我是电信宽带),于是决定购买Fremont区域的机器。
2.系统安装
机器我开始选择的是centos7版本,因为用的习惯了。我后来调试的过程中发现网络不理想,于是想上bbr加速,发现centos7的内核版本不够,又要重新捣鼓内核,最后我还是把弄好的系统铲了重新装的centos9.
所以建议这波直接上centos9,非常好用,直接是最新内核支持bbr。
3.安装v2ray
官网(https://www.v2ray.com/chapter_00/start.html)提供的安装代码是:
curl -Ls https://install.direct/go.sh | sudo bash
输入代码它提示我这个安装脚本已经过时了,最新的安装脚本(https://github.com/v2fly/fhs-install-v2ray)是:
bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)
一键安装,不需要操作,就自动安装好了,界面信息会提示你各种配置文件的位置。
设置启动和开机时自动启动v2ray:
systemctl enable v2ray systemctl start v2ray
顺手配置下v2ray的配置文件/usr/local/etc/v2ray/config.json
:
{ "log": { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log", "loglevel": "warning" }, "inbounds": [{ "port": 2088, "listen": "127.0.0.1", "protocol": "vmess", "settings": { "clients": [ { "id": "b0c21cb8-c45a-44dd-a0e0-d8a13a3bcb89", "level": 1, "alterId": 0 } ] }, "streamSettings": { "network": "ws", "wsSettings": { "path": "/v2" } } }], "outbounds": [{ "protocol": "freedom", "settings": {} },{ "protocol": "blackhole", "settings": {}, "tag": "blocked" }], "routing": { "rules": [ { "type": "field", "ip": ["geoip:private"], "outboundTag": "blocked" } ] } }
上面的随机id可以使用下面命令生成:
cat /proc/sys/kernel/random/uuid
别的配置尽量按照配置里面的来不要随便改动,如果你不知道配置的意思的话,因为后面NGINX配置里面要映射这里的配置。
4.安装配置NGINX
yum install epel-release yum install nginx -y
增加NGINX配置到 /etc/nginx/conf.d/v2ray.conf 这个位置,配置内容如下。
server { listen 443 ssl; ssl on; ssl_certificate /opt/your_domain_bundle.crt; ssl_certificate_key /opt/your_domain.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; server_name your_domain; location /v2 { proxy_redirect off; proxy_pass http://127.0.0.1:2088; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $http_host; # Show realip in v2ray access.log proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
这个配置有2个地方需要改成你实际的配置:
- ssl证书的位置和证书需要你自己去申请
- 域名需要你配置成你实际的域名
配置NGINX的开机启动和安全连接配置和防火墙。
systemctl enable nginx systemctl start nginx setsebool -P httpd_can_network_connect 1 firewall-cmd --add-port=80/tcp --zone=public --permanent firewall-cmd --add-port=443/tcp --zone=public --permanent firewall-cmd --reload
5.启动bbr加速
修改sysctl
配置
echo 'net.core.default_qdisc=fq' | sudo tee -a /etc/sysctl.conf echo 'net.ipv4.tcp_congestion_control=bbr' | sudo tee -a /etc/sysctl.conf sudo sysctl -p
可以通过下面命令确认bbr已经启动
sudo sysctl net.ipv4.tcp_available_congestion_control
你应该可以看到下面的输出
net.ipv4.tcp_available_congestion_control = bbr cubic reno
再用下面的命令校验
sudo sysctl -n net.ipv4.tcp_congestion_control
你应该可以看到
bbr
最后校验下内核模块是否已经加载
lsmod | grep bbr
你应该可以看到类似
tcp_bbr 16384 0
至此你的服务端应该已经完美安装了。
6.客户端配置
这里简单提供个客户端clash的配置
proxies: - name: "vmess" type: vmess server: your_domain port: 443 uuid: b0c21cb8-c45a-44dd-a0e0-d8a13a3bcb89 alterId: 0 cipher: auto tls: true skip-cert-verify: true servername: your_domain network: ws ws-opts: path: /v2 headers: Host: your_domain
大概配置是这样,注意和前面服务器端的配置需要一致。
经过测试启动bbr加速后效果还不错。
参考资料:
https://github.com/v2fly/fhs-install-v2ray
https://www.vultr.com/docs/how-to-deploy-google-bbr-on-centos-7/
https://stackoverflow.com/questions/23948527/13-permission-denied-while-connecting-to-upstreamnginx