Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
vps安装shadowsocks

安装python和ss

yum install python-setuptools && easy_install pip
pip install shadowsocks

配置 Shadowsocks 配置文件

vi /etc/shadowsocks.json
{
    "server": "my_server_ip", // 这里输入本机的 IP 地址
    "server_port": 8388, // 为了安全,可修改为大于 1024 的数字
    "local_address": "127.0.0.1",
    "local_port": 1080, // 为了安全,可修改为大于 1024 的数字
    "password": "mypassword", // 设置一个密码
    "timeout": 300,
    "method": "aes-256-cfb",
    "fast_open": false
}

启动并永久运行 Shadowsocks 服务端功能

一句命令即可启动并永久运行:nohup ssserver -c /etc/shadowsocks.json -d start &

ssserverSS 的服务端命令。 -c 表示以配置文件的方式运行 SS/etc/shadowsocks.json 则是配置文件的路径。 -d 表示在后台运行,这样允许用户进行其他操作。start 就是启动。nohup 以及最后的 & 是让 SS 服务端一直运行,并把运行日志输出到当前用户主目录下的 nohup.out 文件中。

停止 SS 服务端

ssserver -c /etc/shadowsocks.json -d stop

无需 nohup&,把 start 换成 stop

优化 Shadowsocks 性能

按照 SS 官方 Wiki,有如下优化策略:

  • 创建 local.conf 配置文件:vim /etc/sysctl.d/local.conf
  • 按键盘 i,输入以下内容
# 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

# for high-latency network
net.ipv4.tcp_congestion_control = hybla

# for low-latency network, use cubic instead
# net.ipv4.tcp_congestion_control = cubic

退出并保存配置文件:按键盘 Esc 退出编辑,英文输入法状态下,输入 :wq

使配置生效:sysctl --system

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.