10
10
# 添加更多服务器
11
11
]
12
12
13
+
13
14
# 定义更新操作
14
15
def update_server (name , hostname , port , username , password ):
15
16
try :
16
17
17
18
18
- print (f"在服务器 { name } 上安装流量出售工具" )
19
19
client = paramiko .SSHClient ()
20
20
client .set_missing_host_key_policy (paramiko .AutoAddPolicy ())
21
21
client .connect (hostname , port = port , username = username , password = password )
22
22
23
23
24
+ # 执行步骤1: 更新操作
25
+ print (f" { name } 更新" )
26
+ stdin , stdout , stderr = client .exec_command ("apt update -y && apt install -y curl wget sudo socat htop" )
27
+
28
+ print (f"正在更新:" )
29
+ while not stdout .channel .exit_status_ready ():
30
+ if stdout .channel .recv_ready ():
31
+ print (stdout .channel .recv (1024 ).decode (), end = "" )
32
+
33
+ # 检查执行状态
34
+ if stderr .channel .recv_exit_status () == 0 :
35
+ print (f"更新成功" )
36
+ else :
37
+ print (f"更新失败" )
38
+
39
+ print ()
40
+
41
+
42
+ print (f"{ name } 安装 Docker" )
43
+ stdin , stdout , stderr = client .exec_command ("wget -qO- https://get.docker.com/ | sh" )
44
+
45
+ print (f"正在安装 Docker:" )
46
+ while not stdout .channel .exit_status_ready ():
47
+ if stdout .channel .recv_ready ():
48
+ print (stdout .channel .recv (1024 ).decode (), end = "" )
49
+
50
+ # 检查执行状态
51
+ if stderr .channel .recv_exit_status () == 0 :
52
+ print (f"安装 Docker 成功" )
53
+ else :
54
+ print (f"安装 Docker 失败" )
55
+
56
+ print ()
57
+
58
+
59
+ print (f"在服务器 { name } 上安装流量出售工具" )
24
60
stdin , stdout , stderr = client .exec_command ("docker run -d --name tmd --restart=always traffmonetizer/cli start accept --token VM+OdtNp5mupfl8I2w0EZswkOJ8WSuTuMe/kDV02gS8=" )
25
61
26
62
while not stdout .channel .exit_status_ready ():
@@ -33,14 +69,6 @@ def update_server(name, hostname, port, username, password):
33
69
else :
34
70
print (f"安装失败" )
35
71
36
- # 关闭 SSH 连接
37
- client .close ()
38
-
39
-
40
- # 执行步骤2: 安装 Docker
41
- client = paramiko .SSHClient ()
42
- client .set_missing_host_key_policy (paramiko .AutoAddPolicy ())
43
- client .connect (hostname , port = port , username = username , password = password )
44
72
45
73
stdin , stdout , stderr = client .exec_command ("docker ps -a" )
46
74
0 commit comments