Gimhoy's Blog

Ubuntu 18.04 安装shadowsocks-libev, v2ray-plugin, 使用443端口, 并优化加速

安装前准备

sudo apt update
sudo apt upgrade

安装shadowsocks-libev

shadowsocks二进制版,比python版效率高

sudo apt install shadowsocks-libev

安装v2ray-plugin

可访问https://github.com/shadowsocks/v2ray-plugin/releases获得下载地址

wget https://github.com/shadowsocks/v2ray-plugin/releases/download/v1.3.1/v2ray-plugin-linux-amd64-v1.3.1.tar.gz
tar zxf v2ray-plugin-linux-amd64-v1.3.1.tar.gz
sudo mv v2ray-plugin_linux_amd64 /usr/bin/v2ray-plugin

安装acme.sh

curl https://get.acme.sh | sh

申请证书

root用户

直接使用standalone模式申请证书。acme.sh脚本会自动开启一个临时web服务器,用于验证域名的所有权。

acme.sh --issue -d mydomain.me --standalone
mkdir /root/certs //创建本地证书目录
acme.sh --install-cert -d mydomain.me --key-file /root/certs/mydomain.me.key --fullchain-file /root/certs/mydomain.me.cer --reloadcmd "sudo systemctl restart shadowsocks-libev"

非root用户

没有权限启动80端口的web服务器了,所以用nginx来处理web请求。

sudo apt install nginx
sudo chown ubuntu:ubuntu /var/www/html
acme.sh --issue -d mydomain.me --webroot /var/www/html


sudo mkdir /home/gimhoy
sudo mkdir /home/gimhoy/certs/ //创建本地证书目录
sudo chown ubuntu:ubuntu /home/gimhoy
sudo chmod -R 777 /home/gimhoy
chmod u+x /home/ubuntu/.acme.sh
acme.sh --install-cert -d mydomain.me --key-file /home/gimhoy/certs/mydomain.me.key --cert-file /home/gimhoy/certs/mydomain.me.cer --reloadcmd "sudo systemctl restart shadowsocks-libev"

配置shadowsocks+v2ray

sudo vi /etc/shadowsocks-libev/config.json
{
        "server":"::",
        "server_port": 443,
        "password": "mypwd",
        "timeout":60,
        "method":"chacha20-ietf-poly1305",
        "mode":"tcp_and_udp",
        "fast_open":true,
        "plugin":"v2ray-plugin",
        "plugin_opts":"server;tls;fast-open;host=mydomain.me;cert=/home/gimhoy/certs/mydomain.me.cer;key=/home/gimhoy/certs/mydomain.me.key;loglevel=none"
}

配置shadowsocks-libev.service

sudo vi /etc/systemd/system/shadowsocks-libev.service
[Unit]
Description=Shadowsocks-libev Server
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/ss-server -c /etc/shadowsocks-libev/config.json -u
Restart=on-abort

[Install]
WantedBy=multi-user.target
sudo systemctl start shadowsocks-libev
sudo systemctl enable shadowsocks-libev

开启TCP BBR加速

需Linux kernel 4.9 及以上

modprobe tcp_bbr
sudo sh -c "echo 'tcp_bbr' >> /etc/modules-load.d/modules.conf"
sudo sh -c  "echo 'net.core.default_qdisc=fq' >> /etc/sysctl.conf"
sudo sh -c  "echo 'net.ipv4.tcp_congestion_control=bbr' >> /etc/sysctl.conf"

//重启
sudo sysctl -p

//查看是否生效,若均有bbr,则开启BBR成功。
sysctl net.ipv4.tcp_available_congestion_control
sysctl net.ipv4.tcp_congestion_control

优化吞吐量

sudo vi /etc/sysctl.d/local.conf
# max open files
fs.file-max = 51200
# max read buffer
net.core.rmem_max = 67108864
# max write buffer
net.core.wmem_max = 67108864
# default read buffer
net.core.rmem_default = 65536
# default write buffer
net.core.wmem_default = 65536
# max processor input queue
net.core.netdev_max_backlog = 4096
# max backlog
net.core.somaxconn = 4096
# resist SYN flood attacks
net.ipv4.tcp_syncookies = 1
# reuse timewait sockets when safe
net.ipv4.tcp_tw_reuse = 1
# turn off fast timewait sockets recycling
net.ipv4.tcp_tw_recycle = 0
# short FIN timeout
net.ipv4.tcp_fin_timeout = 30
# short keepalive time
net.ipv4.tcp_keepalive_time = 1200
# outbound port range
net.ipv4.ip_local_port_range = 10000 65000
# max SYN backlog
net.ipv4.tcp_max_syn_backlog = 4096
# max timewait sockets held by system simultaneously
net.ipv4.tcp_max_tw_buckets = 5000
# turn on TCP Fast Open on both client and server side
net.ipv4.tcp_fastopen = 3
# TCP receive buffer
net.ipv4.tcp_rmem = 4096 87380 67108864
# TCP write buffer
net.ipv4.tcp_wmem = 4096 65536 67108864
# turn on path MTU discovery
net.ipv4.tcp_mtu_probing = 1
sudo sysctl --system  //使配置生效

ulimit优化

sudo vi /etc/rc.local
ulimit -n 51200
  //加在启动shadowsocks前
sudo sysctl --system  //使配置生效

客户端配置

以Windows官方客户端(https://github.com/shadowsocks/shadowsocks-windows/releases)为例,在https://github.com/shadowsocks/v2ray-plugin/releases下载最新的windows-amd64版v2ray-plugin,解压,将里面的.exe文件改名为v2ray-plugin.exe,放置在shadowsocks的运行目录下,配置如图。

其他系统大同小异。



免费获得每月10G空间+10G免费流量