Ubuntu16.04 Shadowsocks

安装

sudo apt-get install -y python3-pip build-essential python3-dev python3-setuptools python3-wheel

sudo pip3 install https://github.com/shadowsocks/shadowsocks/archive/master.zip

配置

sudo mkdir /etc/shadowsocks
sudo nano /etc/shadowsocks/config.json

输入以下内容:

{
    “server”:”::”,
    “server_port”:8888,
    “local_address”: “127.0.0.1”,
    “local_port”:1080,
    “password”:”password”,
    “timeout”:300,
    “method”:”aes-256-cfb”,
    “fast_open”: true
}

添加systemd服务

sudo nano /etc/systemd/system/shadowsocks-server.service

输入以下内容:

[Unit]
Description=Shadowsocks Server
After=network.target

[Service]
ExecStartPre=/bin/sh -c ‘ulimit -n 51200’
ExecStart=/usr/local/bin/ssserver -c /etc/shadowsocks/config.json
Restart=on-abort

[Install]
WantedBy=multi-user.target

优化

sudo apt-get update
sudo apt-cache showpkg linux-image | grep generic

找到内核版本大于4.9的目标内核,例如:linux-image-4.15.0-38-generic,安装新内核

sudo apt-get install -y linux-image-4.15.0-38-generic

安装完成后重启,进入系统后删除就内核

sudo reboot

sudo purge-old-kernels

开启BBR

modprobe tcp_bbr
echo “tcp_bbr” >> /etc/modules-load.d/modules.conf

echo “net.core.default_qdisc=fq” >> /etc/sysctl.conf
echo “net.ipv4.tcp_congestion_control=bbr” >> /etc/sysctl.conf

sysctl -p

检查是否开启成功,若以下两个命令返回值中有bbr则代表成功

sysctl net.ipv4.tcp_available_congestion_control
sysctl net.ipv4.tcp_congestion_control

优化吞吐量

sudo nano /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

net.ipv4.tcp_congestion_control = bbr

sysctl –system

启动服务并设置开机启动

sudo systemctl enable shadowsocks-server
sudo systemctl start shadowsocks-server

留下评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据