Skip to content

Commit c376197

Browse files
authoredJun 9, 2023
Add files via upload
1 parent 5dd7951 commit c376197

3 files changed

+285
-0
lines changed
 

‎一键所有VPS升级Debian12.py

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
2+
3+
import paramiko
4+
5+
# 定义服务器列表,包括服务器名称、IP地址、端口号、用户名和密码
6+
servers = [
7+
{"name": "美国", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"},
8+
{"name": "不丹", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"},
9+
{"name": "毛里求斯", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"},
10+
# 添加更多服务器
11+
]
12+
13+
14+
15+
# 定义更新操作
16+
def update_server(name, hostname, port, username, password):
17+
try:
18+
# 连接服务器
19+
client = paramiko.SSHClient()
20+
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
21+
client.connect(hostname, port=port, username=username, password=password)
22+
23+
stdin, stdout, stderr = client.exec_command("DEBIAN_FRONTEND=noninteractive apt update -y && DEBIAN_FRONTEND=noninteractive apt full-upgrade -y")
24+
stdin.write('Y\n') # 将默认响应设置为 Y(安装软件包维护者的版本)
25+
stdin.flush() # 刷新输入流
26+
27+
print(f"{name} 开始更新")
28+
while not stdout.channel.exit_status_ready():
29+
if stdout.channel.recv_ready():
30+
print(stdout.channel.recv(1024).decode(), end="")
31+
32+
# 检查更新状态
33+
if stderr.channel.recv_exit_status() == 0:
34+
print(f"更新成功")
35+
else:
36+
print(f"更新失败")
37+
38+
print()
39+
40+
stdin, stdout, stderr = client.exec_command("cat > /etc/apt/sources.list << EOF\ndeb http://deb.debian.org/debian testing main\ndeb-src http://deb.debian.org/debian testing main\n\ndeb http://deb.debian.org/debian-security/ testing-security main\ndeb-src http://deb.debian.org/debian-security/ testing-security main\n\ndeb http://deb.debian.org/debian testing-updates main\ndeb-src http://deb.debian.org/debian testing-updates main\nEOF")
41+
42+
print(f"{name} 导出官方更新源")
43+
while not stdout.channel.exit_status_ready():
44+
if stdout.channel.recv_ready():
45+
print(stdout.channel.recv(1024).decode(), end="")
46+
47+
# 检查更新状态
48+
if stderr.channel.recv_exit_status() == 0:
49+
print(f"导入成功")
50+
else:
51+
print(f"导入失败")
52+
53+
print()
54+
55+
stdin, stdout, stderr = client.exec_command("DEBIAN_FRONTEND=noninteractive apt update -y && DEBIAN_FRONTEND=noninteractive apt full-upgrade -y && apt install -y curl wget sudo socat htop")
56+
stdin.write('Y\n') # 将默认响应设置为 Y(安装软件包维护者的版本)
57+
stdin.flush() # 刷新输入流
58+
59+
print(f"{name} 开始升级")
60+
while not stdout.channel.exit_status_ready():
61+
if stdout.channel.recv_ready():
62+
print(stdout.channel.recv(1024).decode(), end="")
63+
64+
# 检查更新状态
65+
if stderr.channel.recv_exit_status() == 0:
66+
print(f"升级成功")
67+
else:
68+
print(f"升级失败")
69+
70+
print()
71+
72+
stdin, stdout, stderr = client.exec_command("apt autoremove --purge -y && apt clean -y && apt autoclean -y && apt remove --purge $(dpkg -l | awk '/^rc/ {print $2}') -y && journalctl --rotate && journalctl --vacuum-time=1s && journalctl --vacuum-size=50M && apt remove --purge $(dpkg -l | awk '/^ii linux-(image|headers)-[^ ]+/{print $2}' | grep -v $(uname -r | sed 's/-.*//') | xargs) -y")
73+
74+
print(f"{name} 开始清理")
75+
while not stdout.channel.exit_status_ready():
76+
if stdout.channel.recv_ready():
77+
print(stdout.channel.recv(1024).decode(), end="")
78+
79+
# 检查更新状态
80+
if stderr.channel.recv_exit_status() == 0:
81+
print(f"清理成功")
82+
else:
83+
print(f"清理失败")
84+
85+
print()
86+
87+
# 检查更新状态
88+
stdin, stdout, stderr = client.exec_command("reboot")
89+
print(f"{name} 重启服务器")
90+
print()
91+
print()
92+
93+
# 关闭 SSH 连接
94+
client.close()
95+
96+
97+
except Exception as e:
98+
print(f"连接 {name} 失败")
99+
100+
print()
101+
print()
102+
103+
# 遍历服务器列表,逐一更新
104+
for server in servers:
105+
name = server["name"]
106+
hostname = server["hostname"]
107+
port = server["port"]
108+
username = server["username"]
109+
password = server["password"]
110+
update_server(name, hostname, port, username, password)
111+
112+
# 等待用户按下任意键后关闭窗口
113+
input("按任意键关闭窗口...")

‎一键所有VPS更新docker镜像.py

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
2+
import time
3+
import paramiko
4+
5+
# 定义服务器列表,包括服务器名称、IP地址、端口号、用户名和密码
6+
servers = [
7+
{"name": "美国", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"},
8+
{"name": "不丹", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"},
9+
{"name": "毛里求斯", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"},
10+
# 添加更多服务器
11+
]
12+
13+
14+
15+
# 定义更新操作
16+
def update_server(name, hostname, port, username, password):
17+
try:
18+
19+
# 连接服务器
20+
client = paramiko.SSHClient()
21+
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
22+
client.connect(hostname, port=port, username=username, password=password)
23+
24+
25+
# 设置 DEBIAN_FRONTEND 环境变量
26+
stdin, stdout, stderr = client.exec_command("DEBIAN_FRONTEND=noninteractive apt update -y && DEBIAN_FRONTEND=noninteractive apt full-upgrade -y")
27+
print(f"{name} 开始更新")
28+
while not stdout.channel.exit_status_ready():
29+
if stdout.channel.recv_ready():
30+
print(stdout.channel.recv(1024).decode(), end="")
31+
32+
# 检查更新状态
33+
if stderr.channel.recv_exit_status() == 0:
34+
print(f"更新成功")
35+
else:
36+
print(f"更新失败")
37+
38+
print()
39+
40+
stdin, stdout, stderr = client.exec_command("docker images | awk '{print $1\":\"$2}' | grep -v REPOSITORY:TAG | xargs -L1 docker pull")
41+
print(f"{name} 开始更新docker镜像")
42+
while not stdout.channel.exit_status_ready():
43+
if stdout.channel.recv_ready():
44+
print(stdout.channel.recv(1024).decode(), end="")
45+
46+
# 检查更新状态
47+
if stderr.channel.recv_exit_status() == 0:
48+
print(f"更新成功")
49+
else:
50+
print(f"更新成功")
51+
52+
53+
print()
54+
55+
56+
stdin, stdout, stderr = client.exec_command("docker system prune -af --volumes")
57+
print(f"{name} 清理docker镜像")
58+
while not stdout.channel.exit_status_ready():
59+
if stdout.channel.recv_ready():
60+
print(stdout.channel.recv(1024).decode(), end="")
61+
62+
# 检查更新状态
63+
if stderr.channel.recv_exit_status() == 0:
64+
print(f"清理成功")
65+
else:
66+
print(f"清理失败")
67+
68+
69+
time.sleep(5)
70+
print()
71+
72+
# 检查更新状态
73+
print(f"{name} 重启服务器")
74+
stdin, stdout, stderr = client.exec_command("reboot")
75+
print()
76+
print()
77+
78+
79+
# 关闭 SSH 连接
80+
client.close()
81+
82+
83+
except Exception as e:
84+
print(f"连接 {name} 失败 \n")
85+
86+
# 遍历服务器列表,逐一更新
87+
for server in servers:
88+
name = server["name"]
89+
hostname = server["hostname"]
90+
port = server["port"]
91+
username = server["username"]
92+
password = server["password"]
93+
update_server(name, hostname, port, username, password)
94+
95+
# 等待用户按下任意键后关闭窗口
96+
input("按任意键关闭窗口...")

‎一键所有VPS重装Debian系统.py

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import paramiko
2+
3+
# 定义服务器列表,包括服务器名称、IP地址、端口号、用户名和密码
4+
servers = [
5+
{"name": "美国", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"},
6+
{"name": "不丹", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"},
7+
{"name": "毛里求斯", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"},
8+
# 添加更多服务器
9+
]
10+
11+
12+
13+
# 定义更新操作
14+
def update_server(name, hostname, port, username, password, domain):
15+
try:
16+
17+
# 连接服务器
18+
client = paramiko.SSHClient()
19+
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
20+
client.connect(hostname, port=port, username=username, password=password)
21+
22+
23+
print(f" {name} 更新")
24+
stdin, stdout, stderr = client.exec_command("apt update -y && apt install -y curl wget sudo socat")
25+
26+
print(f"正在更新:")
27+
while not stdout.channel.exit_status_ready():
28+
if stdout.channel.recv_ready():
29+
print(stdout.channel.recv(1024).decode(), end="")
30+
31+
# 检查执行状态
32+
if stderr.channel.recv_exit_status() == 0:
33+
print(f"更新成功")
34+
else:
35+
print(f"更新失败")
36+
37+
print()
38+
39+
40+
print(f"{name} 重装")
41+
stdin, stdout, stderr = client.exec_command("bash <(wget --no-check-certificate -qO- 'https://raw.githubusercontent.com/MoeClub/Note/master/InstallNET.sh') -d 11 -v 64 -p 123456 -port 22")
42+
print(f"正在续签中:")
43+
while not stdout.channel.exit_status_ready():
44+
if stdout.channel.recv_ready():
45+
print(stdout.channel.recv(1024).decode(), end="")
46+
47+
48+
print(f"重装成功")
49+
50+
51+
52+
print()
53+
print()
54+
55+
# 关闭 SSH 连接
56+
client.close()
57+
58+
59+
except Exception as e:
60+
print(f"连接 {name} 失败")
61+
62+
63+
# 遍历服务器列表,逐一更新
64+
for server in servers:
65+
name = server["name"]
66+
hostname = server["hostname"]
67+
port = server["port"]
68+
username = server["username"]
69+
password = server["password"]
70+
domain = server["domain"]
71+
update_server(name, hostname, port, username, password, domain)
72+
73+
# 等待用户按下任意键后关闭窗口
74+
input("按任意键关闭窗口...")
75+
76+

0 commit comments

Comments
 (0)
Please sign in to comment.