-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathdeploy_ss_to_vps
executable file
·84 lines (63 loc) · 2.48 KB
/
deploy_ss_to_vps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
self="$(curl https://raw.githubusercontent.com/zw963/deployment_bash/v0.4.6/deploy_start.sh)" && eval "$self"
export target=$1
copy ss-server/config.json /etc/shadowsocks/config.json
deploy_start
# Following code is execute on remote VPS
if which ss-server &>/dev/null; then
echo 'ss-server is exist, skip deploy.'
exit
fi
# replace `你的密码' to yours REALLY PASSWORD before deploy.
replace_string 'mypassword' "你的密码" /etc/shadowsocks/config.json
if grep -qs -e '你的密码' /etc/shadowsocks/config.json; then
echo 'You must specify shadowsocks server password!'
exit
fi
cat <<'HEREDOC' > /etc/sysctl.d/98-shadowsocks.conf
fs.file-max=51200
net.core.rmem_max=67108864
net.core.wmem_max=67108864
net.core.netdev_max_backlog=250000
net.core.somaxconn=4096
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_tw_recycle=0
net.ipv4.tcp_fin_timeout=30
net.ipv4.tcp_keepalive_time=1200
net.ipv4.ip_local_port_range=10000 65000
net.ipv4.tcp_max_syn_backlog=8192
net.ipv4.tcp_max_tw_buckets=5000
net.ipv4.tcp_mem=25600 51200 102400
net.ipv4.tcp_rmem=4096 87380 67108864
net.ipv4.tcp_wmem=4096 65536 67108864
net.ipv4.tcp_mtu_probing=1
net.ipv4.tcp_congestion_control=hybla
# 开启内核 fastopen, Linux 3.7 以上支持, 3.13 才默认开启.
# 等价于 echo 3 > /proc/sys/net/ipv4/tcp_fastopen
net.ipv4.tcp_fastopen=3
HEREDOC
# stolen from https://raw.githubusercontent.com/teddysun/across/master/bbr.sh
version_ge(){
test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"
}
kernel_version=$(uname -r | cut -d- -f1)
# 如果内核大于 4.9, 开启 bbr
if version_ge ${kernel_version} 4.9; then
echo "net.core.default_qdisc = fq" >> /etc/sysctl.d/98-shadowsocks.conf
echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.d/98-shadowsocks.conf
fi
sysctl -p
version='3.2.0'
package compile-tools pcre-devel asciidoc xmlto mbedtls-devel \
udns-devel libev-devel libsodium-devel rng-tools c-ares-devel
systemctl start rngd
systemctl status rngd
[ -d shadowsocks-libev-${version} ] || download_and_extract https://github.com/shadowsocks/shadowsocks-libev/releases/download/v${version}/shadowsocks-libev-${version}.tar.gz
cd shadowsocks-libev-${version}/ &&
configure shadowsocks &&
make &&
make install-strip &&
daemon shadowsocks '/usr/bin/ss-server -u --fast-open --no-delay -c /etc/shadowsocks/config.json -vvv'
server_port=$(cat /etc/shadowsocks/config.json |grep 'server_port"' |grep -o '[0-9]*')
expose_port $server_port