-
Notifications
You must be signed in to change notification settings - Fork 85
/
一键所有VPS部署New Bing AI.py
180 lines (132 loc) · 6.57 KB
/
一键所有VPS部署New Bing AI.py
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
import paramiko
servers = [
{"name": "美国", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"},
{"name": "不丹", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"},
{"name": "毛里求斯", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"},
# 添加更多服务器
]
# 定义更新操作
def update_server(name, hostname, port, username, password, domain):
try:
# 连接服务器
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname, port=port, username=username, password=password)
print(f" {name} 更新")
stdin, stdout, stderr = client.exec_command("apt update -y && apt install -y curl wget sudo socat")
print(f"正在更新:")
while not stdout.channel.exit_status_ready():
if stdout.channel.recv_ready():
print(stdout.channel.recv(1024).decode(), end="")
# 检查执行状态
if stderr.channel.recv_exit_status() == 0:
print(f"更新成功")
else:
print(f"更新失败")
print()
print(f"{name} 安装 Docker")
stdin, stdout, stderr = client.exec_command("curl -fsSL https://get.docker.com | sh")
while not stdout.channel.exit_status_ready():
if stdout.channel.recv_ready():
print(stdout.channel.recv(1024).decode(), end="")
# 检查执行状态
if stderr.channel.recv_exit_status() == 0:
print(f"安装 Docker 成功")
else:
print(f"安装 Docker 失败")
print()
print(f"{name} 安装 New Bing AI")
stdin, stdout, stderr = client.exec_command("docker run -d -p 3080:8080 --name go-proxy-bingai --restart=unless-stopped adams549659584/go-proxy-bingai")
while not stdout.channel.exit_status_ready():
if stdout.channel.recv_ready():
print(stdout.channel.recv(1024).decode(), end="")
# 检查执行状态
if stderr.channel.recv_exit_status() == 0:
print(f"安装成功")
else:
print(f"安装失败")
print()
print(f"{name} 创建nginx目录")
stdin, stdout, stderr = client.exec_command("mkdir -p /home/nginx\ntouch /home/nginx/nginx.conf &&\
mkdir -p /home/nginx/certs")
while not stdout.channel.exit_status_ready():
if stdout.channel.recv_ready():
print(stdout.channel.recv(1024).decode(), end="")
# 检查执行状态
if stderr.channel.recv_exit_status() == 0:
print(f"创建目录成功")
else:
print(f"创建目录失败")
print()
print(f"{name} 申请证书")
stdin, stdout, stderr = client.exec_command("curl https://get.acme.sh | sh &&\
~/.acme.sh/acme.sh --register-account -m xxxx@gmail.com &&\
~/.acme.sh/acme.sh --issue -d {} --standalone".format(domain))
print(f"正在申请中:")
while not stdout.channel.exit_status_ready():
if stdout.channel.recv_ready():
print(stdout.channel.recv(1024).decode(), end="")
# 检查执行状态
if stderr.channel.recv_exit_status() == 0:
print(f"申请成功")
else:
print(f"申请失败")
print()
print(f"{name} 下载证书")
stdin, stdout, stderr = client.exec_command("~/.acme.sh/acme.sh --installcert -d {} --key-file /home/nginx/certs/key.pem --fullchain-file /home/nginx/certs/cert.pem".format(domain))
while not stdout.channel.exit_status_ready():
if stdout.channel.recv_ready():
print(stdout.channel.recv(1024).decode(), end="")
# 检查执行状态
if stderr.channel.recv_exit_status() == 0:
print(f"下载证书成功")
else:
print(f"下载证书失败")
print()
print(f"{name} 配置nginx")
# 重定向到那个网站
redirect = f"{hostname}:3080"
stdin, stdout, stderr = client.exec_command('wget -O /home/nginx/nginx.conf https://raw.githubusercontent.com/kejilion/nginx/main/nginx3.conf && sed -i "s/yuming.com/' + domain + '/g" /home/nginx/nginx.conf && sed -i "s/0.0.0.0:0000/' + redirect + '/g" /home/nginx/nginx.conf')
while not stdout.channel.exit_status_ready():
if stdout.channel.recv_ready():
print(stdout.channel.recv(1024).decode(), end="")
# 检查执行状态
if stderr.channel.recv_exit_status() == 0:
print(f"配置成功")
else:
print(f"配置失败")
print()
print(f"{name} 安装nginx")
stdin, stdout, stderr = client.exec_command('docker run -d --name nginx --restart=always -p 80:80 -p 443:443 -v /home/nginx/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/certs:/etc/nginx/certs -v /home/nginx/html:/usr/share/nginx/html nginx:latest')
while not stdout.channel.exit_status_ready():
if stdout.channel.recv_ready():
print(stdout.channel.recv(1024).decode(), end="")
# 检查执行状态
if stderr.channel.recv_exit_status() == 0:
print(f"安装成功")
else:
print(f"安装失败")
print()
print(f"{name} nginx启动状态")
stdin, stdout, stderr = client.exec_command('docker ps -a')
while not stdout.channel.exit_status_ready():
if stdout.channel.recv_ready():
print(stdout.channel.recv(1024).decode(), end="")
print(f"搭建完成\nhttps://{domain}")
print()
print()
# 关闭 SSH 连接
client.close()
except Exception as e:
print(f"连接 {name} 失败")
# 遍历服务器列表,逐一更新
for server in servers:
name = server["name"]
hostname = server["hostname"]
port = server["port"]
username = server["username"]
password = server["password"]
domain = server["domain"]
update_server(name, hostname, port, username, password, domain)
# 等待用户按下任意键后关闭窗口
input("按任意键关闭窗口...")