Skip to content

Instantly share code, notes, and snippets.

@caobug
Created June 10, 2019 21:56
Show Gist options
  • Save caobug/86eb3e281f64e5d00f4949a0c0251fa7 to your computer and use it in GitHub Desktop.
Save caobug/86eb3e281f64e5d00f4949a0c0251fa7 to your computer and use it in GitHub Desktop.
ss-libe + v2ray-plugin + tls + CentOS-7

v2ray-plugin CentOS-7

购买一个域名 / 或申请一个免费域名(推荐)

配置域名解析

比如 cloudflare,

  1. cloudflare DNS-> 添加一条 A 记录;name=域名,value=vpsIP,ttl=automatic,status=onlyDns
  2. cloudflare Crypto -> SSL = Flexible; 总是开启 HTTPS

安装 Golang

root 下安装

先点击下面连接查看 Go 的最新版本,我当前最新为1.12.5

https://golang.org/dl/

  • 下载安装
cd ~ && curl -O https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz
  • 解压
tar -C /usr/local -xzf go1.11.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 build
cp v2ray-plugin /usr/bin/v2ray-plugin

方式2

github release 页面直接下载对应 v2ray-plugin 执行文件,然后把该文件移动到 /usr/bin/ 目录下(只要不是root目录下即可)

cp v2ray-plugin /usr/bin/v2ray-plugin

https ( websocket + tls )

配置 ss-libev

修改 ss 配置文件

nameserver = dns 地址,也可以使用 1.1.1.1 ;加密方式也可以修改.

{
  "server": "0.0.0.0",
  "nameserver": "8.8.8.8",
  "password": "password",
  "method": "xchacha20-ietf-poly1305",
  "timeout": 60,
  "fast_open": true,
  "reuse_port": true,
  "no_delay": true,
  "mode": "tcp_and_udp"
}

修改自启配置文件

vim /etc/systemd/system/ss.service

写入:

[Unit]
Description=Shadowsocks Server
After=network.target
[Service]
ExecStart=/usr/local/bin/ss-server -c /etc/shadowsocks-libev/config.json -p 443 --plugin /usr/bin/v2ray-plugin --plugin-opts "server;tls;fast-open;host=你的域名;cert=/etc/shadowsocks-libev/你的域名/fullchain.cer;key=/etc/shadowsocks-libev/你的域名/你的域名.key;loglevel=none"
Restart=on-abort
[Install]
WantedBy=multi-user.target

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

  1. v2ray-plugin 文件的路径要正确
  2. 开放 443 端口
  3. host=你的域名(不包含 https 或 http)
  4. TLS证书 Cer 文件引用 cert=你证书存放的位置+证书名+.cer
  5. TLS证书 Key 文件引用 ket=你证书存放的位置+证书名+.key

前面三点很简单,关键后面两点的证书怎么获得呢? 其实官方 Github 页面的最后已经说明怎么申请免费证书(一般免费的使用期限是一年)

免费证书申请

和官方文档一样使用 acme 脚本自动申请免费证书

在申请之前必须先到 cloudflare 页面,点击右上角的头像,然后点击 My Profile ,在个人信息页面下拉到最后有个 API KEYs -> Global API KEY,在这里复制你的 API KEY,同时记得你 CloundFlare 的登陆邮箱,稍后用到这两个东西.

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 等文件。

其实 v2ray-plugin 会自动识别并且配置 acme 证书文件,你也可以不需要在自启配置文件中指定,比如像下面一样

ExecStart=/usr/local/bin/ss-server -c /etc/shadowsocks-libev/config.json -p 443 --plugin /usr/bin/v2ray-plugin --plugin-opts "server;tls;fast-open;host=你的域名;loglevel=none"

检查

systemctl daemon-reload
systemctl restart ss
systemctl status ss
  • 检查是否有错误。如果出现权限错误,请把 证书文件放到非 root 目录中,像上面一样,我是把所有的证书目录都放到了 /etc/shadowsocks-libev/ 中

  • cloudflare 的小云朵确保是灰色的,onlyDns

  • 在本地电脑上 ping 你的域名,确认对应的 ip 地址是否正确

客户端

PC

请先把 v2ray-plugin-win 文件下载到本地 SS 目录下 服务器地址=你的域名 端口=443 密码和加密看自己的配置文件,必须要写对 插件程序:v2ray-plugin 插件选项: host=你的域名;tls

Android

和 PC 差不多,也要先安装 v2ray-plugin-android, Trasport mode 选择 websocket-tls;后面默认即可。

( quic + tls )

在上面 https 的基础上,只需再修改两个地方即可,一个配置文件,一个自启服务文件。

  • ss 配置文件关闭 udp
{
  "mode": "tcp"
}
  • ss.service 文件, 修改 mode 为 quic(官方文档最后面很详细, 不声明,默认 mode = websocket)
ExecStart=/usr/local/bin/ss-server -c /etc/shadowsocks-libev/config.json -p 443 --plugin /usr/bin/v2ray-plugin --plugin-opts "server;mode=quic;tls;fast-open;host=你的域名;loglevel=none"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment