-
Notifications
You must be signed in to change notification settings - Fork 0
/
socks proxy server with shadowsocks on centos
117 lines (102 loc) · 3.25 KB
/
socks proxy server with shadowsocks on centos
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"copied from https://www.linode.com/docs/networking/vpn/create-a-socks5-proxy-server-with-shadowsocks-on-ubuntu-and-centos7/"
centos7
#update
yum update && yum upgrade -y
yum install epel-release -y
yum install -y gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto udns-devel \
libev-devel libsodium-devel mbedtls-devel git m2crypto c-ares-devel
cd /opt
git clone https://github.com/shadowsocks/shadowsocks-libev.git
cd shadowsocks-libev
git submodule update --init --recursive
./autogen.sh
./configure
make && make install
adduser --system --no-create-home -s /bin/false shadowsocks
mkdir -m 755 /etc/shadowsocks
sudo vi /etc/shadowsocks/shadowsocks.json
contents are:
#########################
{
"server":"server_ip",
"server_port":server_port,
"password":"server password",
"timeout":300,
"method":"aes-256-gcm",
"fast_open": true
}
############################
#optimize shadowsocks
sudo vi /etc/sysctl.d/local.conf
contents are:
############################################
# 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
###################################################
#apply optimizations
sysctl --system
#create a shadowsocks systemd service
sudo vi /etc/systemd/system/shadowsocks.service
contents are:
###########################################
[Unit]
Description=Shadowsocks proxy server
[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/bin/ss-server -c /etc/shadowsocks/shadowsocks.json -a shadowsocks -v start
ExecStop=/usr/local/bin/ss-server -c /etc/shadowsocks/shadowsocks.json -a shadowsocks -v stop
[Install]
WantedBy=multi-user.target
#############################################
#enable and start shadowsocks.service
systemctl daemon-reload
systemctl enable shadowsocks
systemctl start shadowsocks
#open firewall port for shadowsocks client
ufw allow proto tcp to 0.0.0.0/0 port 8388 comment "Shadowsocks server listen port"
firewall-cmd --permanent --zone=public --add-rich-rule='
rule family="ipv4"
port protocol="tcp" port="8388" accept'
firewall-cmd --reload