-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_xray_warp.sh
222 lines (203 loc) · 5.17 KB
/
install_xray_warp.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
#!/bin/bash
# 安全提示
function confirm_action {
echo -e "注意: 此脚本将修改系统配置并安装多个服务,可能带来潜在的安全风险!"
read -p "是否继续执行? (y/n): " CONFIRM
if [[ "$CONFIRM" != "y" ]]; then
echo "操作已取消。"
exit 0
fi
}
# 权限检查
function check_root {
if [ "$(id -u)" -ne 0 ]; then
echo -e "请以 root 用户运行此脚本!"
exit 1
fi
}
# 检测系统包管理器
function get_os {
if [ -f /etc/os-release ]; then
. /etc/os-release
OS_NAME=$ID
else
OS_NAME=$(uname -s)
fi
}
# 安装必要工具
function install_dependencies {
case $OS_NAME in
ubuntu | debian)
apt update && apt install curl wget unzip openssl gnupg -y
;;
centos | rhel | fedora)
yum update && yum install curl wget unzip openssl epel-release -y
;;
esac
}
# 安装 Cloudflare WARP
function install_warp {
case $OS_NAME in
ubuntu)
curl -fsSL https://pkg.cloudflareclient.com/pubkey.gpg | sudo gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflare-client.list
apt update && apt install cloudflare-warp -y
;;
debian)
curl -fsSL https://pkg.cloudflareclient.com/pubkey.gpg | sudo gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflare-client.list
apt update && apt install cloudflare-warp -y
;;
centos | rhel | fedora)
curl -fsSl https://pkg.cloudflareclient.com/cloudflare-warp-ascii.repo | sudo tee /etc/yum.repos.d/cloudflare-warp.repo
yum update && yum install cloudflare-warp -y
;;
esac
}
# 配置 Cloudflare WARP
function setup_warp {
warp-cli mode proxy
warp-cli proxy port 2333
warp-cli registration new
warp-cli connect
systemctl enable warp-svc
}
# uuid生成
UUID=$(cat /proc/sys/kernel/random/uuid)
# 配置 Xray
function setup_xray {
DOMAIN=${1:-"example.com"}
DAYS_VALID=365
# 创建证书目录
mkdir -p /usr/local/etc/xray
# 使用 openssl 生成 PEM 和 KEY 文件
openssl req -x509 -nodes -days $DAYS_VALID -newkey rsa:2048 \
-keyout /usr/local/etc/xray/${DOMAIN}.key \
-out /usr/local/etc/xray/${DOMAIN}.pem \
-subj "/CN=${DOMAIN}"
chmod 644 /usr/local/etc/xray/${DOMAIN}.pem
chmod 644 /usr/local/etc/xray/${DOMAIN}.key
chown root:root /usr/local/etc/xray/${DOMAIN}.pem
chown root:root /usr/local/etc/xray/${DOMAIN}.key
# 安装 Xray
curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh | bash
# 创建 Xray 配置文件
cat >/usr/local/etc/xray/config.json <<EOF
{
"inbounds": [
{
"tag": "direct",
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "${UUID}"
}
],
"decryption": "none",
"fallbacks": []
},
"streamSettings": {
"network": "tcp",
"security": "tls",
"tlsSettings": {
"serverNames": [
""
],
"alpn": [
"h2",
"http/1.1"
],
"certificates": [
{
"certificateFile": "/usr/local/etc/xray/${DOMAIN}.pem",
"keyFile": "/usr/local/etc/xray/${DOMAIN}.key"
}
]
}
},
"sniffing": {
"enabled": true,
"destOverride": [
"http",
"tls",
"quic"
],
"routeOnly": true
}
}
],
"outbounds": [
{
"tag": "direct",
"protocol": "freedom"
},
{
"tag": "warp",
"protocol": "socks",
"settings": {
"servers": [
{
"address": "127.0.0.1",
"port": 2333
}
]
}
}
],
"routing": {
"rules": [
{
"type": "field",
"outboundTag": "warp",
"domain": [
"domain:openai.com",
"domain:chatgpt.com",
"domain:ai.com",
"domain:chat.com",
"domain:youtube.com",
"domain:netflix.com",
"domain:deepseek.com",
"domain:tiktok.com"
]
}
]
}
}
EOF
# 启动 Xray 服务
systemctl enable xray
systemctl restart xray
}
# 获取公网 IP 地址
function get_public_ip {
IPV4=$(curl 4.ipw.cn)
IPV6=$(curl 6.ipw.cn)
# 设置全局变量,供后续展示
PUBLIC_IPV4=${IPV4:-"未检测到"}
PUBLIC_IPV6=${IPV6:-"未检测到"}
}
# 主函数
function main {
confirm_action
check_root
get_os
install_dependencies
get_public_ip
install_warp
setup_warp
setup_xray
ufw allow 22
ufw allow 80
ufw allow 443
ufw allow 2333
ufw enable
echo -e "\n配置完成!"
echo "Xray使用的UUID: ${UUID}"
echo -e "公网 IPv4 地址: $PUBLIC_IPV4"
echo -e "公网 IPv6 地址: $PUBLIC_IPV6"
echo "Xray配置文件路径: /usr/local/etc/xray/config.json"
}
# 执行主函数
main "$@"