feeday commited on
Commit
c58acab
·
verified ·
1 Parent(s): ab52a53

Upload centos_install_ssr.sh

Browse files
Files changed (1) hide show
  1. sh/centos_install_ssr.sh +484 -0
sh/centos_install_ssr.sh ADDED
@@ -0,0 +1,484 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # shadowsocksR/SSR CentOS 7/8一键安装教程
3
+ # Author: hijk<https://hijk.art>
4
+
5
+
6
+ RED="\033[31m" # Error message
7
+ GREEN="\033[32m" # Success message
8
+ YELLOW="\033[33m" # Warning message
9
+ BLUE="\033[36m" # Info message
10
+ PLAIN='\033[0m'
11
+
12
+ V6_PROXY=""
13
+ IP=`curl -sL -4 ip.sb`
14
+ if [[ "$?" != "0" ]]; then
15
+ IP=`curl -sL -6 ip.sb`
16
+ V6_PROXY="https://gh.hijk.art/"
17
+ fi
18
+
19
+ FILENAME="ShadowsocksR-v3.2.2"
20
+ URL="${V6_PROXY}https://github.com/shadowsocksrr/shadowsocksr/archive/3.2.2.tar.gz"
21
+ BASE=`pwd`
22
+
23
+ OS=`hostnamectl | grep -i system | cut -d: -f2`
24
+
25
+ CONFIG_FILE="/etc/shadowsocksR.json"
26
+
27
+ colorEcho() {
28
+ echo -e "${1}${@:2}${PLAIN}"
29
+ }
30
+
31
+
32
+ checkSystem() {
33
+ result=$(id | awk '{print $1}')
34
+ if [ $result != "uid=0(root)" ]; then
35
+ colorEcho $RED " 请以root身份执行该脚本"
36
+ exit 1
37
+ fi
38
+
39
+ if [ ! -f /etc/centos-release ];then
40
+ res=`which yum`
41
+ if [ "$?" != "0" ]; then
42
+ colorEcho $RED " 系统不是CentOS"
43
+ exit 1
44
+ fi
45
+ else
46
+ result=`cat /etc/centos-release|grep -oE "[0-9.]+"`
47
+ main=${result%%.*}
48
+ if [ $main -lt 7 ]; then
49
+ colorEcho $RED " 不受支持的CentOS版本"
50
+ exit 1
51
+ fi
52
+ fi
53
+ }
54
+
55
+ slogon() {
56
+ clear
57
+ echo "#############################################################"
58
+ echo -e "# ${RED}CentOS 7/8 ShadowsocksR/SSR 一键安装脚本${PLAIN} #"
59
+ echo -e "# ${GREEN}作者${PLAIN}: 网络跳越(hijk) #"
60
+ echo -e "# ${GREEN}网址${PLAIN}: https://hijk.art #"
61
+ echo -e "# ${GREEN}论坛${PLAIN}: https://hijk.club #"
62
+ echo -e "# ${GREEN}TG群${PLAIN}: https://t.me/hijkclub #"
63
+ echo -e "# ${GREEN}Youtube频道${PLAIN}: https://youtube.com/channel/UCYTB--VsObzepVJtc9yvUxQ #"
64
+ echo "#############################################################"
65
+ echo ""
66
+ }
67
+
68
+ getData() {
69
+ read -p " 请设置SSR的密码(不输入则随机生成):" PASSWORD
70
+ [ -z "$PASSWORD" ] && PASSWORD=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1`
71
+ echo ""
72
+ colorEcho $BLUE " 密码: $PASSWORD"
73
+ echo ""
74
+
75
+ while true
76
+ do
77
+ read -p " 请设置SSR的端口号[1-65535]:" PORT
78
+ [ -z "$PORT" ] && PORT="12345"
79
+ if [ "${PORT:0:1}" = "0" ]; then
80
+ echo -e " ${RED}端口不能以0开头${PLAIN}"
81
+ exit 1
82
+ fi
83
+ expr $PORT + 0 &>/dev/null
84
+ if [ $? -eq 0 ]; then
85
+ if [ $PORT -ge 1 ] && [ $PORT -le 65535 ]; then
86
+ echo ""
87
+ colorEcho $BLUE " 端口号: $PORT"
88
+ echo ""
89
+ break
90
+ else
91
+ colorEcho $RED " 输入错误,端口号为1-65535的数字"
92
+ fi
93
+ else
94
+ colorEcho $RED " 输入错误,端口号为1-65535的数字"
95
+ fi
96
+ done
97
+
98
+
99
+ colorEcho $BLUE " 请选择SSR的加密方式:"
100
+ echo " 1)aes-256-cfb"
101
+ echo " 2)aes-192-cfb"
102
+ echo " 3)aes-128-cfb"
103
+ echo " 4)aes-256-ctr"
104
+ echo " 5)aes-192-ctr"
105
+ echo " 6)aes-128-ctr"
106
+ echo " 7)aes-256-cfb8"
107
+ echo " 8)aes-192-cfb8"
108
+ echo " 9)aes-128-cfb8"
109
+ echo " 10)camellia-128-cfb"
110
+ echo " 11)camellia-192-cfb"
111
+ echo " 12)camellia-256-cfb"
112
+ echo " 13)chacha20-ietf"
113
+ read -p " 请选择加密方式(默认aes-256-cfb)" answer
114
+ if [ -z "$answer" ]; then
115
+ METHOD="aes-256-cfb"
116
+ else
117
+ case $answer in
118
+ 1)
119
+ METHOD="aes-256-cfb"
120
+ ;;
121
+ 2)
122
+ METHOD="aes-192-cfb"
123
+ ;;
124
+ 3)
125
+ METHOD="aes-128-cfb"
126
+ ;;
127
+ 4)
128
+ METHOD="aes-256-ctr"
129
+ ;;
130
+ 5)
131
+ METHOD="aes-192-ctr"
132
+ ;;
133
+ 6)
134
+ METHOD="aes-128-ctr"
135
+ ;;
136
+ 7)
137
+ METHOD="aes-256-cfb8"
138
+ ;;
139
+ 8)
140
+ METHOD="aes-192-cfb8"
141
+ ;;
142
+ 9)
143
+ METHOD="aes-128-cfb8"
144
+ ;;
145
+ 10)
146
+ METHOD="camellia-128-cfb"
147
+ ;;
148
+ 11)
149
+ METHOD="camellia-192-cfb"
150
+ ;;
151
+ 12)
152
+ METHOD="camellia-256-cfb"
153
+ ;;
154
+ 13)
155
+ METHOD="chacha20-ietf"
156
+ ;;
157
+ *)
158
+ colorEcho $RED " 无效的选择,使用默认加密方式"
159
+ METHOD="aes-256-cfb"
160
+ esac
161
+ fi
162
+ echo ""
163
+ colorEcho $BLUE " 加密方式: $METHOD"
164
+ echo ""
165
+
166
+ colorEcho $BLUE " 请选择SSR协议:"
167
+ echo " 1)origin"
168
+ echo " 2)verify_deflate"
169
+ echo " 3)auth_sha1_v4"
170
+ echo " 4)auth_aes128_md5"
171
+ echo " 5)auth_aes128_sha1"
172
+ echo " 6)auth_chain_a"
173
+ echo " 7)auth_chain_b"
174
+ echo " 8)auth_chain_c"
175
+ echo " 9)auth_chain_d"
176
+ echo " 10)auth_chain_e"
177
+ echo " 11)auth_chain_f"
178
+ read -p " 请选择SSR协议(默认origin)" answer
179
+ if [ -z "$answer" ]; then
180
+ PROTOCOL="origin"
181
+ else
182
+ case $answer in
183
+ 1)
184
+ PROTOCOL="origin"
185
+ ;;
186
+ 2)
187
+ PROTOCOL="verify_deflate"
188
+ ;;
189
+ 3)
190
+ PROTOCOL="auth_sha1_v4"
191
+ ;;
192
+ 4)
193
+ PROTOCOL="auth_aes128_md5"
194
+ ;;
195
+ 5)
196
+ PROTOCOL="auth_aes128_sha1"
197
+ ;;
198
+ 6)
199
+ PROTOCOL="auth_chain_a"
200
+ ;;
201
+ 7)
202
+ PROTOCOL="auth_chain_b"
203
+ ;;
204
+ 8)
205
+ PROTOCOL="auth_chain_c"
206
+ ;;
207
+ 9)
208
+ PROTOCOL="auth_chain_d"
209
+ ;;
210
+ 10)
211
+ PROTOCOL="auth_chain_e"
212
+ ;;
213
+ 11)
214
+ PROTOCOL="auth_chain_f"
215
+ ;;
216
+ *)
217
+ colorEcho $RED " 无效的选择,使用默认协议"
218
+ PROTOCOL="origin"
219
+ esac
220
+ fi
221
+ echo ""
222
+ colorEcho $BLUE " SSR协议: $PROTOCOL"
223
+ echo ""
224
+
225
+
226
+ colorEcho $BLUE " 请选择SSR混淆模式:"
227
+ echo " 1)plain"
228
+ echo " 2)http_simple"
229
+ echo " 3)http_post"
230
+ echo " 4)tls1.2_ticket_auth"
231
+ echo " 5)tls1.2_ticket_fastauth"
232
+ read -p " 请选择混淆模式(默认plain)" answer
233
+ if [ -z "$answer" ]; then
234
+ OBFS="plain"
235
+ else
236
+ case $answer in
237
+ 1)
238
+ OBFS="plain"
239
+ ;;
240
+ 2)
241
+ OBFS="http_simple"
242
+ ;;
243
+ 3)
244
+ OBFS="http_post"
245
+ ;;
246
+ 4)
247
+ OBFS="tls1.2_ticket_auth"
248
+ ;;
249
+ 5)
250
+ OBFS="tls1.2_ticket_fastauth"
251
+ ;;
252
+ *)
253
+ colorEcho $RED " 无效的选择,使用默认混淆模式"
254
+ OBFS="plain"
255
+ esac
256
+ fi
257
+ echo ""
258
+ colorEcho $BLUE " 混淆模式: $OBFS"
259
+ echo ""
260
+ }
261
+
262
+ preinstall() {
263
+ colorEcho $BLUE " 更新系统..."
264
+ yum clean all
265
+ #yum update -y
266
+ colorEcho $BLUE " 安装必要软件"
267
+ yum install -y epel-release telnet curl wget vim net-tools libsodium openssl unzip tar qrencode
268
+ res=`which wget`
269
+ [ "$?" != "0" ] && yum install -y wget
270
+ res=`which netstat`
271
+ [ "$?" != "0" ] && yum install -y net-tools
272
+ if [ $main -eq 8 ]; then
273
+ ln -s /usr/bin/python3 /usr/bin/python
274
+ fi
275
+
276
+ if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
277
+ sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
278
+ setenforce 0
279
+ fi
280
+ }
281
+
282
+ installSSR() {
283
+ if [ ! -d /usr/local/shadowsocks ]; then
284
+ echo 下载安装文件
285
+ if ! wget --no-check-certificate -O ${FILENAME}.tar.gz ${URL}; then
286
+ echo -e " [${RED}Error${PLAIN}] 下载文件失败!"
287
+ exit 1
288
+ fi
289
+
290
+ tar -zxf ${FILENAME}.tar.gz
291
+ mv shadowsocksr-3.2.2/shadowsocks /usr/local
292
+ if [ ! -f /usr/local/shadowsocks/server.py ]; then
293
+ colorEcho $RED " $OS 安装失败,请到 https://hijk.art 网站反馈"
294
+ cd ${BASE} && rm -rf shadowsocksr-3.2.2 ${FILENAME}.tar.gz
295
+ exit 1
296
+ fi
297
+ cd ${BASE} && rm -rf shadowsocksr-3.2.2 ${FILENAME}.tar.gz
298
+ fi
299
+
300
+ cat > $CONFIG_FILE<<-EOF
301
+ {
302
+ "server":"0.0.0.0",
303
+ "server_ipv6":"::",
304
+ "server_port":${PORT},
305
+ "local_port":1080,
306
+ "password":"${PASSWORD}",
307
+ "timeout":600,
308
+ "method":"${METHOD}",
309
+ "protocol":"${PROTOCOL}",
310
+ "protocol_param":"",
311
+ "obfs":"${OBFS}",
312
+ "obfs_param":"",
313
+ "redirect":"",
314
+ "dns_ipv6":false,
315
+ "fast_open":false,
316
+ "workers":1
317
+ }
318
+ EOF
319
+
320
+ cat > /usr/lib/systemd/system/shadowsocksR.service <<-EOF
321
+ [Unit]
322
+ Description=shadowsocksR
323
+ Documentation=https://hijk.art/
324
+ After=network-online.target
325
+ Wants=network-online.target
326
+
327
+ [Service]
328
+ Type=forking
329
+ LimitNOFILE=32768
330
+ ExecStart=/usr/local/shadowsocks/server.py -c $CONFIG_FILE -d start
331
+ ExecReload=/bin/kill -s HUP \$MAINPID
332
+ ExecStop=/bin/kill -s TERM \$MAINPID
333
+
334
+ [Install]
335
+ WantedBy=multi-user.target
336
+ EOF
337
+
338
+ systemctl daemon-reload
339
+ systemctl enable shadowsocksR && systemctl restart shadowsocksR
340
+ sleep 3
341
+ res=`netstat -nltp | grep ${PORT} | grep python`
342
+ if [ "${res}" = "" ]; then
343
+ colorEcho $RED " ssr启动失败,请检查端口是否被占用!"
344
+ exit 1
345
+ fi
346
+ }
347
+
348
+ setFirewall() {
349
+ systemctl status firewalld > /dev/null 2>&1
350
+ if [[ $? -eq 0 ]];then
351
+ firewall-cmd --permanent --add-service=http
352
+ firewall-cmd --permanent --add-port=${PORT}/tcp
353
+ firewall-cmd --permanent --add-port=${PORT}/udp
354
+ firewall-cmd --reload
355
+ else
356
+ nl=`iptables -nL | nl | grep FORWARD | awk '{print $1}'`
357
+ if [[ "$nl" != "3" ]]; then
358
+ iptables -I INPUT -p tcp --dport 80 -j ACCEPT
359
+ iptables -I INPUT -p tcp --dport ${PORT} -j ACCEPT
360
+ iptables -I INPUT -p udp --dport ${PORT} -j ACCEPT
361
+ fi
362
+ fi
363
+ }
364
+
365
+ installBBR() {
366
+ result=$(lsmod | grep bbr)
367
+ if [ "$result" != "" ]; then
368
+ colorEcho $GREEN " BBR模块已安装"
369
+ INSTALL_BBR=false
370
+ return
371
+ fi
372
+ res=`hostnamectl | grep -i openvz`
373
+ if [ "$res" != "" ]; then
374
+ colorEcho $YELLOW " openvz机器,跳过安装"
375
+ INSTALL_BBR=false
376
+ return
377
+ fi
378
+
379
+ echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
380
+ echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
381
+ sysctl -p
382
+ result=$(lsmod | grep bbr)
383
+ if [[ "$result" != "" ]]; then
384
+ colorEcho $GREEN " BBR模块已启用"
385
+ INSTALL_BBR=false
386
+ return
387
+ fi
388
+
389
+ colorEcho $BLUE " 安装BBR模块..."
390
+ rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
391
+ rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm
392
+ yum --enablerepo=elrepo-kernel install kernel-ml -y
393
+ yum remove kernel-3.* -y
394
+ grub2-set-default 0
395
+ echo "tcp_bbr" >> /etc/modules-load.d/modules.conf
396
+ INSTALL_BBR=true
397
+ }
398
+
399
+ info() {
400
+ port=`grep server_port $CONFIG_FILE| cut -d: -f2 | tr -d \",' '`
401
+ res=`netstat -nltp | grep ${port} | grep python`
402
+ [ -z "$res" ] && status="${RED}已停止${PLAIN}" || status="${GREEN}正在运行${PLAIN}"
403
+ password=`grep password $CONFIG_FILE| cut -d: -f2 | tr -d \",' '`
404
+ method=`grep method $CONFIG_FILE| cut -d: -f2 | tr -d \",' '`
405
+ protocol=`grep protocol $CONFIG_FILE| cut -d: -f2 | tr -d \",' '`
406
+ obfs=`grep obfs $CONFIG_FILE| cut -d: -f2 | tr -d \",' '`
407
+
408
+ p1=`echo -n ${password} | base64 -w 0`
409
+ p1=`echo -n ${p1} | tr -d =`
410
+ res=`echo -n "${IP}:${port}:${protocol}:${method}:${obfs}:${p1}/?remarks=&protoparam=&obfsparam=" | base64 -w 0`
411
+ res=`echo -n ${res} | tr -d =`
412
+ link="ssr://${res}"
413
+
414
+ echo ""
415
+ echo ============================================
416
+ echo -e " ${BLUE}ssr运行状态:${PLAIN}${status}"
417
+ echo -e " ${BLUE}ssr配置文件:${PLAIN}${RED}$CONFIG_FILE${PLAIN}"
418
+ echo ""
419
+ echo -e " ${RED}ssr配置信息:${PLAIN}"
420
+ echo -e " ${BLUE}IP(address):${PLAIN} ${RED}${IP}${PLAIN}"
421
+ echo -e " ${BLUE}端口(port):${PLAIN}${RED}${port}${PLAIN}"
422
+ echo -e " ${BLUE}密码(password):${PLAIN}${RED}${password}${PLAIN}"
423
+ echo -e " ${BLUE}加密方式(method):${PLAIN} ${RED}${method}${PLAIN}"
424
+ echo -e " ${BLUE}协议(protocol):${PLAIN} ${RED}${protocol}${PLAIN}"
425
+ echo -e " ${BLUE}混淆(obfuscation):${PLAIN} ${RED}${obfs}${PLAIN}"
426
+ echo
427
+ echo -e " ${BLUE}ssr链接:${PLAIN} $link"
428
+ qrencode -o - -t utf8 $link
429
+ }
430
+
431
+ bbrReboot() {
432
+ if [ "${INSTALL_BBR}" == "true" ]; then
433
+ echo
434
+ echo 为使BBR模块生效,系统将在30秒后重启
435
+ echo
436
+ echo -e " 您可以按 ctrl + c 取消重启,稍后输入 ${RED}reboot${PLAIN} 重启系统"
437
+ sleep 30
438
+ reboot
439
+ fi
440
+ }
441
+
442
+
443
+ install() {
444
+ echo -n "系统版本: "
445
+ cat /etc/centos-release
446
+ checkSystem
447
+ getData
448
+ preinstall
449
+ installBBR
450
+ installSSR
451
+ setFirewall
452
+
453
+ info
454
+
455
+ bbrReboot
456
+ }
457
+
458
+ uninstall() {
459
+ echo ""
460
+ read -p " 确定卸载SSR吗?(y/n)" answer
461
+ [ -z ${answer} ] && answer="n"
462
+
463
+ if [ "${answer}" == "y" ] || [ "${answer}" == "Y" ]; then
464
+ rm -f $CONFIG_FILE
465
+ rm -f /var/log/shadowsocks.log
466
+ rm -rf /usr/local/shadowsocks
467
+ systemctl disable shadowsocksR && systemctl stop shadowsocksR && rm -rf /usr/lib/systemd/system/shadowsocksR.service
468
+ fi
469
+ echo -e " ${RED}卸载成功${PLAIN}"
470
+ }
471
+
472
+ slogon
473
+
474
+ action=$1
475
+ [ -z $1 ] && action=install
476
+ case "$action" in
477
+ install|uninstall|info)
478
+ ${action}
479
+ ;;
480
+ *)
481
+ echo " 参数错误"
482
+ echo " 用法: `basename $0` [install|uninstall]"
483
+ ;;
484
+ esac