-
Notifications
You must be signed in to change notification settings - Fork 433
/
tcp-wss.sh
256 lines (232 loc) · 6.64 KB
/
tcp-wss.sh
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
##!/bin/sh
# forum: https://1024.day
if [[ $EUID -ne 0 ]]; then
clear
echo "Error: This script must be run as root!" 1>&2
exit 1
fi
timedatectl set-timezone Asia/Shanghai
v2path=$(cat /dev/urandom | head -1 | md5sum | head -c 6)
v2uuid=$(cat /proc/sys/kernel/random/uuid)
ssport=$(shuf -i 2000-65000 -n 1)
getIP(){
local serverIP=
serverIP=$(curl -s -4 http://www.cloudflare.com/cdn-cgi/trace | grep "ip" | awk -F "[=]" '{print $2}')
if [[ -z "${serverIP}" ]]; then
serverIP=$(curl -s -6 http://www.cloudflare.com/cdn-cgi/trace | grep "ip" | awk -F "[=]" '{print $2}')
fi
echo "${serverIP}"
}
install_precheck(){
echo "====输入已经DNS解析好的域名===="
read domain
read -t 15 -p "回车或等待15秒为默认端口443,或者自定义端口请输入(1-65535):" getPort
if [ -z $getPort ];then
getPort=443
fi
if [ -f "/usr/bin/apt-get" ]; then
apt-get update -y && apt-get upgrade -y
apt-get install -y net-tools curl
else
yum update -y && yum upgrade -y
yum install -y epel-release
yum install -y net-tools curl
fi
sleep 3
isPort=`netstat -ntlp| grep -E ':80 |:443 '`
if [ "$isPort" != "" ];then
clear
echo " ================================================== "
echo " 80或443端口被占用,请先释放端口再运行此脚本"
echo
echo " 端口占用信息如下:"
echo $isPort
echo " ================================================== "
exit 1
fi
}
install_nginx(){
if [ -f "/usr/bin/apt-get" ];then
apt-get install -y nginx cron socat
else
yum install -y nginx cronie socat
fi
cat >/etc/nginx/nginx.conf<<EOF
pid /var/run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 51200;
events {
worker_connections 1024;
multi_accept on;
use epoll;
}
http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 120s;
keepalive_requests 10000;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
access_log off;
error_log /dev/null;
server {
listen 80;
listen [::]:80;
server_name $domain;
location / {
return 301 https://\$server_name\$request_uri;
}
}
server {
listen $getPort ssl http2;
listen [::]:$getPort ssl http2;
server_name $domain;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_certificate /etc/letsencrypt/live/$domain/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$domain/privkey.pem;
location / {
default_type text/plain;
return 200 "Hello World !";
}
location /$v2path {
proxy_redirect off;
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$http_host;
}
}
}
EOF
}
acme_ssl(){
curl https://get.acme.sh | sh -s email=my@example.com
mkdir -p /etc/letsencrypt/live/$domain
~/.acme.sh/acme.sh --issue -d $domain --standalone --keylength ec-256 --pre-hook "systemctl stop nginx" --post-hook "~/.acme.sh/acme.sh --installcert -d $domain --ecc --fullchain-file /etc/letsencrypt/live/$domain/fullchain.pem --key-file /etc/letsencrypt/live/$domain/privkey.pem --reloadcmd \"systemctl start nginx\""
}
install_v2ray(){
bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)
cat >/usr/local/etc/v2ray/config.json<<EOF
{
"inbounds": [
{
"port": 8080,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "$v2uuid"
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/$v2path"
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
}
]
}
EOF
systemctl enable v2ray.service && systemctl restart v2ray.service && systemctl restart nginx.service
rm -f tcp-wss.sh install-release.sh
cat >/usr/local/etc/v2ray/client.json<<EOF
{
===========配置参数=============
协议:VMess
地址:${domain}
端口:${getPort}
UUID:${v2uuid}
加密方式:aes-128-gcm
传输协议:ws
路径:/${v2path}
底层传输:tls
注意:8080是免流端口不需要打开tls
}
EOF
clear
}
install_ssrust(){
wget https://raw.githubusercontent.com/yeahwu/v2ray-wss/main/ss-rust.sh && bash ss-rust.sh
}
install_reality(){
wget https://raw.githubusercontent.com/yeahwu/v2ray-wss/main/reality.sh && bash reality.sh
}
install_hy2(){
wget https://raw.githubusercontent.com/yeahwu/v2ray-wss/main/hy2.sh && bash hy2.sh
}
client_v2ray(){
wslink=$(echo -n "{\"port\":${getPort},\"ps\":\"1024-wss\",\"tls\":\"tls\",\"id\":\"${v2uuid}\",\"aid\":0,\"v\":2,\"host\":\"${domain}\",\"type\":\"none\",\"path\":\"/${v2path}\",\"net\":\"ws\",\"add\":\"${domain}\",\"allowInsecure\":0,\"method\":\"none\",\"peer\":\"${domain}\",\"sni\":\"${domain}\"}" | base64 -w 0)
echo
echo "安装已经完成"
echo
echo "===========v2ray配置参数============"
echo "协议:VMess"
echo "地址:${domain}"
echo "端口:${getPort}"
echo "UUID:${v2uuid}"
echo "加密方式:aes-128-gcm"
echo "传输协议:ws"
echo "路径:/${v2path}"
echo "底层传输:tls"
echo "注意:8080是免流端口不需要打开tls"
echo "===================================="
echo "vmess://${wslink}"
echo
}
start_menu(){
clear
echo " ================================================== "
echo " 论坛:https://1024.day "
echo " 介绍:一键安装SS-Rust,v2ray+wss,Reality或Hysteria2 "
echo " 系统:Ubuntu、Debian、CentOS "
echo " ================================================== "
echo
echo " 1. 安装 Shadowsocks-rust"
echo " 2. 安装 v2ray+ws+tls"
echo " 3. 安装 Reality"
echo " 4. 安装 Hysteria2"
echo " 0. 退出脚本"
echo
read -p "请输入数字:" num
case "$num" in
1)
install_ssrust
;;
2)
install_precheck
install_nginx
acme_ssl
install_v2ray
client_v2ray
;;
3)
install_reality
;;
4)
install_hy2
;;
0)
exit 1
;;
*)
clear
echo "请输入正确数字"
sleep 2s
start_menu
;;
esac
}
start_menu