Skip to content

Instantly share code, notes, and snippets.

@jshensh
Created June 27, 2020 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jshensh/bc2f76b20c4e6876ec6d667e707ec29d to your computer and use it in GitHub Desktop.
Save jshensh/bc2f76b20c4e6876ec6d667e707ec29d to your computer and use it in GitHub Desktop.
ss-libev + v2ray-plugin + tls + CentOS-7

v2ray-plugin CentOS-7

ss v2ray-plugin centos-7

购买域名 / 或申请免费域名

配置 cloudflare

  1. cloudflare DNS-> 添加一条 A 记录;name=域名,value=vpsIP, ttl=automatic, status=onlyDns
  2. cloudflare Crypto -> SSL = Flexible (如果有 Web 页面 可以设置 Full 或者 Full-strict ); 总是开启 HTTPS
  3. 如果使用 quic ,则还需在 cloudflare Network 打开 Http/3 (with quit)

安装 golang

查看 Go 的最新版本 ,我当前最新为1.12.5

  • 下载安装 root 下安装
cd ~ && curl -O https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz
  • 解压
tar -C /usr/local -xzf go1.12.5.linux-amd64.tar.gz
  • 添加到环境变量
vim ~/.bash_profile
  • 添加以下两行内容到文末:
export GOPATH=$HOME/work
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
  • 使环境变量生效
source ~/.bash_profile
  • 检查版本
go version

安装 v2ray-plugin

  • 方式1
git clone https://github.com/shadowsocks/v2ray-plugin.git
cd v2ray-plugin
go mod download
go build
cp v2ray-plugin /usr/bin/v2ray-plugin
  • 方式2 到 github release 页面直接下载对应 v2ray-plugin 执行文件,然后把该文件移动到 /usr/bin/ 目录下
cp v2ray-plugin /usr/bin/v2ray-plugin

https ( websocket + tls )

申请免费证书

和官方文档一样使用 acme 脚本自动申请免费证书 (免费证书有效期一般是 3 个月,

脚本会每隔 60 天自动更新一次证书有效期)

在申请证书之前必须先到 cloudflare 页面,点击右上角的头像,然后点击 My Profile ,在个人信息页面下拉到最后有个 API KEYs -> Global API KEY, 复制你的 API KEY, 同时复制你的 CloundFlare 的登陆邮箱 , key 和 email 用于申请证书

  • 申请证书 (申请证书之前确保你的域名已经解析到你的服务器地址)
export CF_Email="CloundFlare邮箱"
export CF_Key="API KEY"
curl https://get.acme.sh | sh
~/.acme.sh/acme.sh --issue --dns dns_cf -d 你的域名

执行完上面命令,acme 脚本就会自动帮你申请好了证书,证书存放的目录在 root/.acme.sh/你的域名/ 。里面包含了 ca.cer 、fullchain.cer | .key 等文件。

  • 申请完证书后也可以把证书链接放到 /etc/shadowsocks-libev/ 目录下使用
ln -s ~/.acme.sh/xxxx.com /etc/shadowsocks-libev/xxxx.com

其实 v2ray-plugin 会自动识别并且引用你的 acme 证书文件,也可以不用在配置文件中指定 (我更推荐使用明确指定路径的方式)

配置 ss-libev

  • 修改 ss 配置文件
{
  "server": "0.0.0.0",
  "nameserver": "8.8.8.8",
  "password": "password",
  "method": "chacha20-ietf-poly1305",
  "timeout": 600,
  "fast_open": true,
  "no_delay": true,
  "mode": "tcp_and_udp"
}

ss 配置和 v2ray 插件配置整合

  • ss 配置 vim /etc/shadowsocks-libev/config.json
{
  "server": "0.0.0.0",
  "nameserver": "8.8.8.8",
  "server_port": 443,
  "password": "你的密码",
  "method": "chacha20-ietf-poly1305",
  "timeout": 600,
  "no_delay": true,
  "mode": "tcp_and_udp",
  "plugin": "v2ray-plugin",
  "plugin_opts": "server;tls;fast-open;host=xxxxxxxxx.com;cert=/证书目录/fullchain.cer;key=/证书目录/xxxxxxxxx.com.key;loglevel=none"
}
  • service 配置 vim /etc/systemd/system/ss.service
[Unit]
Description=Shadowsocks Server
After=network.target
[Service]
ExecStart=/usr/bin/ss-server -c /etc/shadowsocks-libev/config.json
Restart=on-abort
[Install]
WantedBy=multi-user.target

ss 配置和 v2ray 插件配置分离 (和官方例子一样的)

  • ss 配置 vim /etc/shadowsocks-libev/config.json
{
  "server": "0.0.0.0",
  "nameserver": "8.8.8.8",
  "password": "你的密码",
  "method": "chacha20-ietf-poly1305",
  "timeout": 600,
  "no_delay": true,
  "mode": "tcp_and_udp"
}
  • service 配置 vim /etc/systemd/system/ss.service
[Unit]
Description=Shadowsocks Server
After=network.target
[Service]
ExecStart=/usr/bin/ss-server -c /etc/shadowsocks-libev/config.json -p 443 --plugin /usr/bin/v2ray-plugin --plugin-opts "server;tls;fast-open;host=xxxxxxxxx.com;cert=/证书目录/fullchain.cer;key=/证书目录/xxxxxxxxx.key;loglevel=none"
Restart=on-abort
[Install]
WantedBy=multi-user.target

上面的配置需要注意 5 点:

  1. v2ray-plugin 和 ss-server 文件的路径要正确
  2. 开放 443 端口
  3. host=你的域名(不包含 https 或 http)
  4. cert=证书存放的位置/证书名/fullchain.cer
  5. ket=证书存放的位置/证书名/xxxxxx.com.key
  • 检查
systemctl daemon-reload
systemctl restart ss
systemctl status ss -l
  • cloudflare 的小云朵确保是灰色的,onlyDns
  • 在本地电脑上 ping 域名,确认对应的 ip 地址是否正确
  • 在浏览器上访问域名

quic ( quic + tls )

Quic 协议是基于 http2 的基础上( 所以必须要有证书 ),v2ray-plugin 中的 quic 内部默认启用 tls

quic 核心是 UDP,有些地区运营商对 UDP 的支持不太好, UDP 丢包严重,特别是局域网较深的地方。所以在某些地区不用 quic 反而更好。

  • 开启 quic 需要关闭 ss 的 udp
{
  "mode": "tcp_only"
}
  • ss.service 文件, 修改 mode 为 quic(没有指定 mode 的话,mode 默认为 websocket; 该插件的 quic 内部默认启用了 tls, 这里就不需要再添加 tls 选项了)
ExecStart=/usr/bin/ss-server -c /etc/shadowsocks-libev/config.json -p 443 --plugin /usr/bin/v2ray-plugin --plugin-opts "server;mode=quic;host=你的域名;cert=/证书目录/fullchain.cer;key=/证书目录/你的域名.key;loglevel=none"

如果不想使用 CDN,直接将客户端的地址栏改为服务器 IP 地址即可。

客户端

PC

  • 请先把 v2ray-plugin-win.exe 文件下载到本地 SS 目录下
  • 服务器地址: xxxxxxx.com
  • 端口: 443
  • 密码和加密方式看自己的配置文件
  • 插件程序:v2ray-plugin-win
  • 插件选项: tls;host=xxxxxx.com

Android

  • 和 PC 差不多,从 github 或 谷歌应用市场下载安装 v2ray-plugin-android.apk,
  • Trasport mode 选择: websocket-tls
  • Hostname:xxxxxxxx.com
  • 剩下默认即可

最后能成功连上的话,记得把 cloudflare 的 dnsonly 改为 proxied

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment