├── LDNMP ├── 1.部署LNMP环境.py ├── 2.部署WordPress.py ├── 3.部署苹果CMS.py └── 4.部署discuz论坛.py ├── README.md ├── cluster ├── clean.py ├── custom_tasks.py ├── firewall_close.py ├── install_bbr3.py ├── install_docker.py ├── install_kejilion.py ├── swap1024.py ├── time_shanghai.py └── update.py ├── 一键上传目录及文件到所有VPS.py ├── 一键所有VPS升级Debian最新稳定版.py ├── 一键所有VPS升级内核.py ├── 一键所有VPS启动BBR加速.py ├── 一键所有VPS垃圾清理.py ├── 一键所有VPS安装docker.py ├── 一键所有VPS安装流量出售工具.py ├── 一键所有VPS更新docker镜像.py ├── 一键所有VPS更新系统.py ├── 一键所有VPS测速.py ├── 一键所有VPS解锁ChatGPT.py ├── 一键所有VPS部署NGINX反代.py ├── 一键所有VPS部署NGINX重定向.py ├── 一键所有VPS部署New Bing AI.py ├── 一键所有VPS部署WordPress.py ├── 一键所有VPS部署发卡网站.py ├── 一键所有VPS部署苹果CMS.py ├── 一键所有VPS重装Debian系统.py └── 一键查看所有VPS资源占用.py /LDNMP/1.部署LNMP环境.py: -------------------------------------------------------------------------------- 1 | import paramiko 2 | 3 | servers = [ 4 | 5 | {"name": "吉隆坡", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "dbrootpasswd": "webroot", "dbuse": "one", "dbusepasswd": "yyds", "domain": "a1.yuming.com", "dbname": "db1"}, 6 | 7 | ] 8 | 9 | 10 | # 定义更新操作 11 | def update_server(name, hostname, port, username, password, domain, dbrootpasswd, dbuse, dbusepasswd): 12 | try: 13 | 14 | # 连接服务器 15 | client = paramiko.SSHClient() 16 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 17 | client.connect(hostname, port=port, username=username, password=password) 18 | 19 | 20 | print(f"{name} 更新系统") 21 | 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 unzip tar htop") 22 | 23 | stdout.channel.recv_exit_status() # 等待命令执行完成 24 | 25 | # 检查执行状态 26 | if stderr.channel.recv_exit_status() == 0: 27 | print("完成") 28 | else: 29 | print("失败") 30 | 31 | 32 | print() 33 | 34 | 35 | print(f"{name} 安装 Docker") 36 | stdin, stdout, stderr = client.exec_command("curl -fsSL https://get.docker.com | sh") 37 | 38 | stdout.channel.recv_exit_status() # 等待命令执行完成 39 | 40 | 41 | stdin, stdout, stderr = client.exec_command('curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose') 42 | 43 | stdout.channel.recv_exit_status() # 等待命令执行完成 44 | 45 | # 检查执行状态 46 | if stderr.channel.recv_exit_status() == 0: 47 | print("完成") 48 | else: 49 | print("失败") 50 | 51 | print() 52 | 53 | stdin, stdout, stderr = client.exec_command("cd /home && mkdir -p web/html web/mysql web/certs web/conf.d web/redis && touch web/docker-compose.yml") 54 | 55 | stdout.channel.recv_exit_status() # 等待命令执行完成 56 | 57 | 58 | command = '''wget -O /home/web/docker-compose.yml https://raw.githubusercontent.com/kejilion/docker/main/LNMP-docker-compose-4.yml && \ 59 | sed -i "s/webroot/{}/g" /home/web/docker-compose.yml && \ 60 | sed -i "s/kejilionYYDS/{}/g" /home/web/docker-compose.yml && \ 61 | sed -i "s/kejilion/{}/g" /home/web/docker-compose.yml'''.format(dbrootpasswd, dbusepasswd, dbuse) 62 | 63 | stdin, stdout, stderr = client.exec_command(command) 64 | 65 | stdout.channel.recv_exit_status() # 等待命令执行完成 66 | 67 | stdin, stdout, stderr = client.exec_command('iptables -P INPUT ACCEPT && \ 68 | iptables -P FORWARD ACCEPT && \ 69 | iptables -P OUTPUT ACCEPT && \ 70 | iptables -F') 71 | 72 | stdout.channel.recv_exit_status() # 等待命令执行完成 73 | 74 | 75 | 76 | 77 | print(f"{name} 启动环境") 78 | stdin, stdout, stderr = client.exec_command('cd /home/web && docker-compose up -d') 79 | 80 | stdout.channel.recv_exit_status() # 等待命令执行完成 81 | 82 | # 检查执行状态 83 | if stderr.channel.recv_exit_status() == 0: 84 | print("完成") 85 | else: 86 | print("失败") 87 | 88 | print() 89 | 90 | 91 | 92 | print(f"{name} PHP最新版配置") 93 | command = ( 94 | "docker exec php apt update && " 95 | "docker exec php apt install -y libmariadb-dev-compat libmariadb-dev libzip-dev libmagickwand-dev imagemagick && " 96 | "docker exec php docker-php-ext-install mysqli pdo_mysql zip exif gd intl bcmath opcache && " 97 | "docker exec php pecl install imagick && " 98 | "docker exec php sh -c 'echo \"extension=imagick.so\" > /usr/local/etc/php/conf.d/imagick.ini' && " 99 | "docker exec php pecl install redis && " 100 | "docker exec php sh -c 'echo \"extension=redis.so\" > /usr/local/etc/php/conf.d/docker-php-ext-redis.ini' && " 101 | "docker exec php sh -c 'echo \"upload_max_filesize=50M \n post_max_size=50M\" > /usr/local/etc/php/conf.d/uploads.ini' && " 102 | "docker exec php sh -c 'echo \"memory_limit=256M\" > /usr/local/etc/php/conf.d/memory.ini'" 103 | 104 | ) 105 | 106 | stdin, stdout, stderr = client.exec_command(command) 107 | 108 | stdout.channel.recv_exit_status() # 等待命令执行完成 109 | 110 | # 检查执行状态 111 | if stderr.channel.recv_exit_status() == 0: 112 | print("完成") 113 | else: 114 | print("失败") 115 | 116 | print() 117 | 118 | print(f"{name} PHP7.4配置") 119 | 120 | command = ( 121 | "docker exec php74 apt update && " 122 | "docker exec php74 apt install -y libmariadb-dev-compat libmariadb-dev libzip-dev libmagickwand-dev imagemagick && " 123 | "docker exec php74 docker-php-ext-install mysqli pdo_mysql zip gd intl bcmath opcache && " 124 | "docker exec php74 pecl install imagick && " 125 | "docker exec php74 sh -c 'echo \"extension=imagick.so\" > /usr/local/etc/php/conf.d/imagick.ini' && " 126 | "docker exec php74 pecl install redis && " 127 | "docker exec php74 sh -c 'echo \"extension=redis.so\" > /usr/local/etc/php/conf.d/docker-php-ext-redis.ini'" 128 | "docker exec php74 sh -c 'echo \"upload_max_filesize=50M \n post_max_size=50M\" > /usr/local/etc/php/conf.d/uploads.ini' && " 129 | "docker exec php74 sh -c 'echo \"memory_limit=256M\" > /usr/local/etc/php/conf.d/memory.ini'" 130 | 131 | ) 132 | 133 | stdin, stdout, stderr = client.exec_command(command) 134 | 135 | stdout.channel.recv_exit_status() # 等待命令执行完成 136 | 137 | # 检查执行状态 138 | if stderr.channel.recv_exit_status() == 0: 139 | print("完成") 140 | else: 141 | print("失败") 142 | 143 | print() 144 | print() 145 | 146 | 147 | stdin, stdout, stderr = client.exec_command('docker restart php && docker restart php74') 148 | 149 | stdout.channel.recv_exit_status() # 等待命令执行完成 150 | 151 | 152 | stdin, stdout, stderr = client.exec_command('rm /home/web/docker-compose.yml') 153 | 154 | stdout.channel.recv_exit_status() # 等待命令执行完成 155 | 156 | # 检查执行状态 157 | if stderr.channel.recv_exit_status() == 0: 158 | print(f"搭建完成") 159 | else: 160 | print(f"搭建失败") 161 | 162 | print() 163 | print() 164 | 165 | # 关闭 SSH 连接 166 | client.close() 167 | 168 | 169 | except Exception as e: 170 | print(f"连接 {name} 失败") 171 | 172 | 173 | # 遍历服务器列表,逐一更新 174 | for server in servers: 175 | name = server["name"] 176 | hostname = server["hostname"] 177 | port = server["port"] 178 | username = server["username"] 179 | password = server["password"] 180 | domain = server["domain"] 181 | dbrootpasswd = server["dbrootpasswd"] 182 | dbuse = server["dbuse"] 183 | dbusepasswd = server["dbusepasswd"] 184 | update_server(name, hostname, port, username, password, domain, dbrootpasswd, dbuse, dbusepasswd) 185 | 186 | # 等待用户按下任意键后关闭窗口 187 | input("按任意键关闭窗口...") 188 | 189 | 190 | -------------------------------------------------------------------------------- /LDNMP/2.部署WordPress.py: -------------------------------------------------------------------------------- 1 | import paramiko 2 | 3 | servers = [ 4 | 5 | {"name": "吉隆坡", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "dbrootpasswd": "webroot", "dbuse": "one", "dbusepasswd": "yyds", "domain": "a1.yuming.com", "dbname": "db1"}, 6 | 7 | ] 8 | 9 | 10 | # 定义更新操作 11 | def update_server(name, hostname, port, username, password, domain, dbrootpasswd, dbuse, dbname ): 12 | try: 13 | 14 | # 连接服务器 15 | client = paramiko.SSHClient() 16 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 17 | client.connect(hostname, port=port, username=username, password=password) 18 | 19 | 20 | stdin, stdout, stderr = client.exec_command("docker stop nginx") 21 | stdout.channel.recv_exit_status() # 等待命令执行完成 22 | 23 | 24 | cert_command = ( 25 | "curl https://get.acme.sh | sh && " 26 | "~/.acme.sh/acme.sh --register-account -m xxxx@gmail.com --issue -d {} " 27 | "--standalone --key-file /home/web/certs/{}_key.pem --cert-file /home/web/certs/{}_cert.pem --force" 28 | ).format(domain, domain, domain) 29 | 30 | # 使用 client.exec_command 执行命令,并将标准输出和标准错误重定向到 /dev/null 31 | stdin, stdout, stderr = client.exec_command(f"{cert_command} > /dev/null 2>&1") 32 | 33 | # 等待命令执行完成 34 | stdout.channel.recv_exit_status() 35 | 36 | 37 | stdin, stdout, stderr = client.exec_command("docker start nginx") 38 | stdout.channel.recv_exit_status() # 等待命令执行完成 39 | 40 | 41 | 42 | stdin, stdout, stderr = client.exec_command('wget -O /home/web/conf.d/' + domain + '.conf https://raw.githubusercontent.com/kejilion/nginx/main/wordpress.com.conf && \ 43 | sed -i "s/yuming.com/' + domain + '/g" /home/web/conf.d/' + domain + '.conf') 44 | 45 | stdout.channel.recv_exit_status() # 等待命令执行完成 46 | 47 | 48 | # 使用字符串拼接来组织命令,增加可读性 49 | command = ( 50 | 'cd /home/web/html/ && ' 51 | 'mkdir {} && ' 52 | 'cd {} && ' 53 | 'wget https://cn.wordpress.org/wordpress-6.2.2-zh_CN.zip && ' 54 | 'unzip wordpress-6.2.2-zh_CN.zip && ' 55 | 'rm wordpress-6.2.2-zh_CN.zip' 56 | ).format(domain, domain) 57 | 58 | command = f"{command} > /dev/null 2>&1" 59 | 60 | stdin, stdout, stderr = client.exec_command(command) 61 | 62 | stdout.channel.recv_exit_status() 63 | 64 | 65 | stdin, stdout, stderr = client.exec_command("echo \"define('FS_METHOD', 'direct'); define('WP_REDIS_HOST', 'redis'); define('WP_REDIS_PORT', '6379');\" >> /home/web/html/{}/wordpress/wp-config-sample.php".format(domain)) 66 | stdout.channel.recv_exit_status() # 等待命令执行完成 67 | 68 | 69 | stdin, stdout, stderr = client.exec_command('docker exec nginx chmod -R 777 /var/www/html && docker exec php chmod -R 777 /var/www/html && docker exec php74 chmod -R 777 /var/www/html') 70 | stdout.channel.recv_exit_status() # 等待命令执行完成 71 | 72 | 73 | command = "docker exec mysql mysql -u root -p'{}' -e 'CREATE DATABASE {}; GRANT ALL PRIVILEGES ON {}.* TO \"{}\"@\"%\";'".format(dbrootpasswd,dbname,dbname,dbuse) 74 | stdin, stdout, stderr = client.exec_command(command) 75 | stdout.channel.recv_exit_status() # 等待命令执行完成 76 | 77 | 78 | stdin, stdout, stderr = client.exec_command("docker restart php && docker restart php74 && docker restart nginx ") 79 | stdout.channel.recv_exit_status() # 等待命令执行完成 80 | 81 | 82 | print(f"您的WordPress网站搭建好啦!\nhttps://{domain}") 83 | print() 84 | 85 | # 关闭 SSH 连接 86 | client.close() 87 | 88 | 89 | except Exception as e: 90 | print(f"连接 {name} 失败") 91 | 92 | 93 | # 遍历服务器列表,逐一更新 94 | for server in servers: 95 | name = server["name"] 96 | hostname = server["hostname"] 97 | port = server["port"] 98 | username = server["username"] 99 | password = server["password"] 100 | domain = server["domain"] 101 | dbname = server["dbname"] 102 | dbrootpasswd = server["dbrootpasswd"] 103 | dbuse = server["dbuse"] 104 | update_server(name, hostname, port, username, password, domain, dbrootpasswd, dbuse, dbname ) 105 | 106 | # 等待用户按下任意键后关闭窗口 107 | input("按任意键关闭窗口...") 108 | 109 | 110 | -------------------------------------------------------------------------------- /LDNMP/3.部署苹果CMS.py: -------------------------------------------------------------------------------- 1 | import paramiko 2 | 3 | servers = [ 4 | 5 | {"name": "吉隆坡", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "dbrootpasswd": "webroot", "dbuse": "one", "dbusepasswd": "yyds", "domain": "a1.yuming.com", "dbname": "db1"}, 6 | 7 | 8 | 9 | ] 10 | 11 | 12 | # 定义更新操作 13 | def update_server(name, hostname, port, username, password, domain, dbrootpasswd, dbuse, dbname ): 14 | try: 15 | 16 | # 连接服务器 17 | client = paramiko.SSHClient() 18 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 19 | client.connect(hostname, port=port, username=username, password=password) 20 | 21 | 22 | stdin, stdout, stderr = client.exec_command("docker stop nginx") 23 | stdout.channel.recv_exit_status() # 等待命令执行完成 24 | 25 | 26 | cert_command = ( 27 | "curl https://get.acme.sh | sh && " 28 | "~/.acme.sh/acme.sh --register-account -m xxxx@gmail.com --issue -d {} " 29 | "--standalone --key-file /home/web/certs/{}_key.pem --cert-file /home/web/certs/{}_cert.pem --force" 30 | ).format(domain, domain, domain) 31 | 32 | # 使用 client.exec_command 执行命令,并将标准输出和标准错误重定向到 /dev/null 33 | stdin, stdout, stderr = client.exec_command(f"{cert_command} > /dev/null 2>&1") 34 | 35 | # 等待命令执行完成 36 | stdout.channel.recv_exit_status() 37 | 38 | 39 | stdin, stdout, stderr = client.exec_command("docker start nginx") 40 | stdout.channel.recv_exit_status() # 等待命令执行完成 41 | 42 | 43 | 44 | stdin, stdout, stderr = client.exec_command('wget -O /home/web/conf.d/' + domain + '.conf https://raw.githubusercontent.com/kejilion/nginx/main/maccms.com.conf && \ 45 | sed -i "s/yuming.com/' + domain + '/g" /home/web/conf.d/' + domain + '.conf') 46 | 47 | stdout.channel.recv_exit_status() # 等待命令执行完成 48 | 49 | 50 | # 使用字符串拼接来组织命令,增加可读性 51 | command = ( 52 | 'cd /home/web/html/ && ' 53 | 'mkdir {} && ' 54 | 'cd {} && ' 55 | 'wget https://github.com/magicblack/maccms_down/raw/master/maccms10.zip && unzip maccms10.zip && rm maccms10.zip &&' 56 | 'cd /home/web/html/{}/maccms10-master/template/ && wget https://github.com/kejilion/Website_source_code/raw/main/DYXS2.zip && unzip DYXS2.zip && rm /home/web/html/{}/maccms10-master/template/DYXS2.zip && ' 57 | 'cp /home/web/html/{}/maccms10-master/template/DYXS2/asset/admin/Dyxs2.php /home/web/html/{}/maccms10-master/application/admin/controller &&' 58 | 'cp /home/web/html/{}/maccms10-master/template/DYXS2/asset/admin/dycms.html /home/web/html/{}/maccms10-master/application/admin/view/system &&' 59 | 'mv /home/web/html/{}/maccms10-master/admin.php /home/web/html/{}/maccms10-master/vip.php && wget -O /home/web/html/{}/maccms10-master/application/extra/maccms.php https://raw.githubusercontent.com/kejilion/Website_source_code/main/maccms.php' 60 | 61 | ).format(domain, domain, domain, domain, domain, domain, domain, domain, domain, domain, domain) 62 | 63 | command = f"{command} > /dev/null 2>&1" 64 | 65 | stdin, stdout, stderr = client.exec_command(command) 66 | 67 | stdout.channel.recv_exit_status() 68 | 69 | 70 | stdin, stdout, stderr = client.exec_command("echo \"define('FS_METHOD', 'direct'); define('WP_REDIS_HOST', 'redis'); define('WP_REDIS_PORT', '6379');\" >> /home/web/html/{}/wordpress/wp-config-sample.php".format(domain)) 71 | stdout.channel.recv_exit_status() # 等待命令执行完成 72 | 73 | 74 | stdin, stdout, stderr = client.exec_command('docker exec nginx chmod -R 777 /var/www/html && docker exec php chmod -R 777 /var/www/html && docker exec php74 chmod -R 777 /var/www/html') 75 | stdout.channel.recv_exit_status() # 等待命令执行完成 76 | 77 | 78 | command = "docker exec mysql mysql -u root -p'{}' -e 'CREATE DATABASE {}; GRANT ALL PRIVILEGES ON {}.* TO \"{}\"@\"%\";'".format(dbrootpasswd,dbname,dbname,dbuse) 79 | stdin, stdout, stderr = client.exec_command(command) 80 | stdout.channel.recv_exit_status() # 等待命令执行完成 81 | 82 | 83 | stdin, stdout, stderr = client.exec_command("docker restart php && docker restart php74 && docker restart nginx ") 84 | stdout.channel.recv_exit_status() # 等待命令执行完成 85 | 86 | 87 | print(f"您的苹果CMS网站搭建好啦!\nhttps://{domain}") 88 | print() 89 | 90 | # 关闭 SSH 连接 91 | client.close() 92 | 93 | 94 | except Exception as e: 95 | print(f"连接 {name} 失败") 96 | 97 | 98 | # 遍历服务器列表,逐一更新 99 | for server in servers: 100 | name = server["name"] 101 | hostname = server["hostname"] 102 | port = server["port"] 103 | username = server["username"] 104 | password = server["password"] 105 | domain = server["domain"] 106 | dbname = server["dbname"] 107 | dbrootpasswd = server["dbrootpasswd"] 108 | dbuse = server["dbuse"] 109 | update_server(name, hostname, port, username, password, domain, dbrootpasswd, dbuse, dbname ) 110 | 111 | # 等待用户按下任意键后关闭窗口 112 | input("按任意键关闭窗口...") 113 | 114 | 115 | -------------------------------------------------------------------------------- /LDNMP/4.部署discuz论坛.py: -------------------------------------------------------------------------------- 1 | import paramiko 2 | 3 | servers = [ 4 | 5 | {"name": "吉隆坡", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "dbrootpasswd": "webroot", "dbuse": "one", "dbusepasswd": "yyds", "domain": "a1.yuming.com", "dbname": "db1"}, 6 | 7 | ] 8 | 9 | 10 | # 定义更新操作 11 | def update_server(name, hostname, port, username, password, domain, dbrootpasswd, dbuse, dbname ): 12 | try: 13 | 14 | # 连接服务器 15 | client = paramiko.SSHClient() 16 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 17 | client.connect(hostname, port=port, username=username, password=password) 18 | 19 | 20 | stdin, stdout, stderr = client.exec_command("docker stop nginx") 21 | stdout.channel.recv_exit_status() # 等待命令执行完成 22 | 23 | 24 | cert_command = ( 25 | "curl https://get.acme.sh | sh && " 26 | "~/.acme.sh/acme.sh --register-account -m xxxx@gmail.com --issue -d {} " 27 | "--standalone --key-file /home/web/certs/{}_key.pem --cert-file /home/web/certs/{}_cert.pem --force" 28 | ).format(domain, domain, domain) 29 | 30 | # 使用 client.exec_command 执行命令,并将标准输出和标准错误重定向到 /dev/null 31 | stdin, stdout, stderr = client.exec_command(f"{cert_command} > /dev/null 2>&1") 32 | 33 | # 等待命令执行完成 34 | stdout.channel.recv_exit_status() 35 | 36 | 37 | stdin, stdout, stderr = client.exec_command("docker start nginx") 38 | stdout.channel.recv_exit_status() # 等待命令执行完成 39 | 40 | 41 | 42 | stdin, stdout, stderr = client.exec_command('wget -O /home/web/conf.d/' + domain + '.conf https://raw.githubusercontent.com/kejilion/nginx/main/discuz.com.conf && \ 43 | sed -i "s/yuming.com/' + domain + '/g" /home/web/conf.d/' + domain + '.conf') 44 | 45 | stdout.channel.recv_exit_status() # 等待命令执行完成 46 | 47 | 48 | # 使用字符串拼接来组织命令,增加可读性 49 | command = ( 50 | 'cd /home/web/html/ && ' 51 | 'mkdir {} && ' 52 | 'cd {} && ' 53 | 'wget https://github.com/kejilion/Website_source_code/raw/main/Discuz_X3.5_SC_UTF8_20230520.zip && ' 54 | 'unzip Discuz_X3.5_SC_UTF8_20230520.zip && ' 55 | 'rm Discuz_X3.5_SC_UTF8_20230520.zip' 56 | ).format(domain, domain) 57 | 58 | command = f"{command} > /dev/null 2>&1" 59 | 60 | stdin, stdout, stderr = client.exec_command(command) 61 | 62 | stdout.channel.recv_exit_status() 63 | 64 | stdin, stdout, stderr = client.exec_command('docker exec nginx chmod -R 777 /var/www/html && docker exec php chmod -R 777 /var/www/html && docker exec php74 chmod -R 777 /var/www/html') 65 | stdout.channel.recv_exit_status() # 等待命令执行完成 66 | 67 | 68 | command = "docker exec mysql mysql -u root -p'{}' -e 'CREATE DATABASE {}; GRANT ALL PRIVILEGES ON {}.* TO \"{}\"@\"%\";'".format(dbrootpasswd,dbname,dbname,dbuse) 69 | stdin, stdout, stderr = client.exec_command(command) 70 | stdout.channel.recv_exit_status() # 等待命令执行完成 71 | 72 | 73 | stdin, stdout, stderr = client.exec_command("docker restart php && docker restart php74 && docker restart nginx ") 74 | stdout.channel.recv_exit_status() # 等待命令执行完成 75 | 76 | 77 | print(f"您的discuz论坛搭建好啦!\nhttps://{domain}") 78 | print() 79 | 80 | # 关闭 SSH 连接 81 | client.close() 82 | 83 | 84 | except Exception as e: 85 | print(f"连接 {name} 失败") 86 | 87 | 88 | # 遍历服务器列表,逐一更新 89 | for server in servers: 90 | name = server["name"] 91 | hostname = server["hostname"] 92 | port = server["port"] 93 | username = server["username"] 94 | password = server["password"] 95 | domain = server["domain"] 96 | dbname = server["dbname"] 97 | dbrootpasswd = server["dbrootpasswd"] 98 | dbuse = server["dbuse"] 99 | update_server(name, hostname, port, username, password, domain, dbrootpasswd, dbuse, dbname ) 100 | 101 | # 等待用户按下任意键后关闭窗口 102 | input("按任意键关闭窗口...") 103 | 104 | 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # python-for-vps 2 | 管理所有VPS一键搞定! 3 | 4 | 这里提供的python脚本都是在自己的电脑上运行的,需要先在本机安装python环境安装paramiko,speedtest-cli库。 5 | 就可以用现实电脑操作控制所有VPS了,包括批量更新,查看所有VPS情况,批量安装docker,批量上传文件,批量测速,批量部署NGINX,批量启动BBR加速等操作! 6 | 7 | 目前仅适配Debian10+ Ubuntu20.04+ 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /cluster/clean.py: -------------------------------------------------------------------------------- 1 | import time 2 | import paramiko 3 | from servers import servers 4 | 5 | # 定义更新操作 6 | def update_server(name, hostname, port, username, password): 7 | try: 8 | # 连接服务器 9 | client = paramiko.SSHClient() 10 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 11 | client.connect(hostname, port=port, username=username, password=password) 12 | print(f"{name} 已连接") 13 | 14 | # 设置 DEBIAN_FRONTEND 环境变量 15 | stdin, stdout, stderr = client.exec_command("k") 16 | 17 | # 暂停一段时间以等待安装程序接受输入 18 | time.sleep(1) 19 | 20 | # 中文 21 | stdin.write('3\n') 22 | stdin.flush() 23 | 24 | while not stdout.channel.exit_status_ready(): 25 | if stdout.channel.recv_ready(): 26 | output = stdout.channel.recv(8192).decode() 27 | print(output, end="") 28 | 29 | # 检查是否包含特定消息 30 | if "操作完成" in output: 31 | client.close() 32 | 33 | 34 | except Exception as e: 35 | print(f"连接 {name} 失败\n") 36 | 37 | # 遍历服务器列表,逐一更新 38 | for server in servers: 39 | name = server["name"] 40 | hostname = server["hostname"] 41 | port = server["port"] 42 | username = server["username"] 43 | password = server["password"] 44 | update_server(name, hostname, port, username, password) 45 | 46 | print("") 47 | input("任务执行已全部结束") 48 | -------------------------------------------------------------------------------- /cluster/custom_tasks.py: -------------------------------------------------------------------------------- 1 | import time 2 | import paramiko 3 | from servers import servers 4 | 5 | # 定义更新操作 6 | def update_server(name, hostname, port, username, password): 7 | try: 8 | # 连接服务器 9 | client = paramiko.SSHClient() 10 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 11 | client.connect(hostname, port=port, username=username, password=password) 12 | print("") 13 | print(f"{name} 已连接") 14 | 15 | stdin, stdout, stderr = client.exec_command("Customtasks") 16 | 17 | # 读取输出 18 | output = stdout.read().decode() 19 | error = stderr.read().decode() 20 | 21 | # 检查命令执行状态 22 | exit_status = stdout.channel.recv_exit_status() 23 | if exit_status == 0: 24 | print(output) 25 | print(f"\033[92m{name} 成功\033[0m") # 绿色文本 26 | else: 27 | print(error) 28 | print(f"\033[91m{name} 失败\033[0m") # 红色文本 29 | 30 | print("") 31 | print("") 32 | 33 | 34 | # 关闭 SSH 连接 35 | client.close() 36 | 37 | except Exception as e: 38 | print(f"连接 {name} 失败\n") 39 | 40 | # 遍历服务器列表,逐一更新 41 | for server in servers: 42 | name = server["name"] 43 | hostname = server["hostname"] 44 | port = server["port"] 45 | username = server["username"] 46 | password = server["password"] 47 | update_server(name, hostname, port, username, password) 48 | 49 | print("") 50 | input("任务执行已全部结束") 51 | -------------------------------------------------------------------------------- /cluster/firewall_close.py: -------------------------------------------------------------------------------- 1 | import time 2 | import paramiko 3 | from servers import servers 4 | 5 | # 定义更新操作 6 | def update_server(name, hostname, port, username, password): 7 | try: 8 | # 连接服务器 9 | client = paramiko.SSHClient() 10 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 11 | client.connect(hostname, port=port, username=username, password=password) 12 | print(f"{name} 已连接") 13 | 14 | # 设置 DEBIAN_FRONTEND 环境变量 15 | stdin, stdout, stderr = client.exec_command("k") 16 | 17 | # 暂停一段时间以等待安装程序接受输入 18 | time.sleep(1) 19 | 20 | # 中文 21 | stdin.write('13\n') 22 | stdin.flush() 23 | 24 | time.sleep(1) 25 | 26 | stdin.write('5\n') 27 | stdin.flush() 28 | 29 | while not stdout.channel.exit_status_ready(): 30 | if stdout.channel.recv_ready(): 31 | output = stdout.channel.recv(8192).decode() 32 | print(output, end="") 33 | 34 | # 检查是否包含特定消息 35 | if "操作完成" in output: 36 | client.close() 37 | 38 | 39 | except Exception as e: 40 | print(f"连接 {name} 失败\n") 41 | 42 | # 遍历服务器列表,逐一更新 43 | for server in servers: 44 | name = server["name"] 45 | hostname = server["hostname"] 46 | port = server["port"] 47 | username = server["username"] 48 | password = server["password"] 49 | update_server(name, hostname, port, username, password) 50 | 51 | print("") 52 | input("任务执行已全部结束") 53 | -------------------------------------------------------------------------------- /cluster/install_bbr3.py: -------------------------------------------------------------------------------- 1 | import time 2 | import paramiko 3 | from servers import servers 4 | 5 | # 定义更新操作 6 | def update_server(name, hostname, port, username, password): 7 | try: 8 | # 连接服务器 9 | client = paramiko.SSHClient() 10 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 11 | client.connect(hostname, port=port, username=username, password=password) 12 | print(f"{name} 已连接") 13 | 14 | # 设置 DEBIAN_FRONTEND 环境变量 15 | stdin, stdout, stderr = client.exec_command("k") 16 | 17 | # 暂停一段时间以等待安装程序接受输入 18 | time.sleep(1) 19 | 20 | # 中文 21 | stdin.write('13\n') 22 | stdin.flush() 23 | 24 | time.sleep(1) 25 | 26 | stdin.write('16\n') 27 | stdin.flush() 28 | 29 | time.sleep(1) 30 | 31 | stdin.write('y\n') 32 | stdin.flush() 33 | 34 | while not stdout.channel.exit_status_ready(): 35 | if stdout.channel.recv_ready(): 36 | output = stdout.channel.recv(8192).decode() 37 | print(output, end="") 38 | 39 | # 检查是否包含特定消息 40 | if "操作完成" in output: 41 | client.close() 42 | 43 | 44 | except Exception as e: 45 | print(f"连接 {name} 失败\n") 46 | 47 | # 遍历服务器列表,逐一更新 48 | for server in servers: 49 | name = server["name"] 50 | hostname = server["hostname"] 51 | port = server["port"] 52 | username = server["username"] 53 | password = server["password"] 54 | update_server(name, hostname, port, username, password) 55 | 56 | print("") 57 | input("任务执行已全部结束") 58 | -------------------------------------------------------------------------------- /cluster/install_docker.py: -------------------------------------------------------------------------------- 1 | import time 2 | import paramiko 3 | from servers import servers 4 | 5 | # 定义更新操作 6 | def update_server(name, hostname, port, username, password): 7 | try: 8 | # 连接服务器 9 | client = paramiko.SSHClient() 10 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 11 | client.connect(hostname, port=port, username=username, password=password) 12 | print(f"{name} 已连接") 13 | 14 | # 设置 DEBIAN_FRONTEND 环境变量 15 | stdin, stdout, stderr = client.exec_command("k") 16 | 17 | # 暂停一段时间以等待安装程序接受输入 18 | time.sleep(1) 19 | 20 | # 中文 21 | stdin.write('6\n') 22 | stdin.flush() 23 | 24 | time.sleep(1) 25 | 26 | # 中文 27 | stdin.write('1\n') 28 | stdin.flush() 29 | 30 | while not stdout.channel.exit_status_ready(): 31 | if stdout.channel.recv_ready(): 32 | output = stdout.channel.recv(8192).decode() 33 | print(output, end="") 34 | 35 | # 检查是否包含特定消息 36 | if "操作完成" in output: 37 | client.close() 38 | 39 | 40 | except Exception as e: 41 | print(f"连接 {name} 失败\n") 42 | 43 | # 遍历服务器列表,逐一更新 44 | for server in servers: 45 | name = server["name"] 46 | hostname = server["hostname"] 47 | port = server["port"] 48 | username = server["username"] 49 | password = server["password"] 50 | update_server(name, hostname, port, username, password) 51 | 52 | print("") 53 | input("任务执行已全部结束") 54 | -------------------------------------------------------------------------------- /cluster/install_kejilion.py: -------------------------------------------------------------------------------- 1 | import time 2 | import paramiko 3 | from servers import servers 4 | 5 | # 定义更新操作 6 | def update_server(name, hostname, port, username, password): 7 | try: 8 | # 连接服务器 9 | client = paramiko.SSHClient() 10 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 11 | client.connect(hostname, port=port, username=username, password=password) 12 | print(f"{name} 已连接") 13 | 14 | # 设置 DEBIAN_FRONTEND 环境变量 15 | stdin, stdout, stderr = client.exec_command("curl -sS -O https://raw.githubusercontent.com/kejilion/sh/main/kejilion.sh && chmod +x kejilion.sh && ./kejilion.sh") 16 | stdin.flush() 17 | 18 | # 暂停一段时间以等待安装程序接受输入 19 | time.sleep(1) 20 | 21 | # 中文 22 | stdin.write('y\n') 23 | stdin.flush() 24 | 25 | # 暂停一段时间以等待安装程序接受输入 26 | time.sleep(1) 27 | 28 | # 中文 29 | stdin.write('0\n') 30 | stdin.flush() 31 | 32 | # 关闭 SSH 连接 33 | client.close() 34 | 35 | except Exception as e: 36 | print(f"连接 {name} 失败\n") 37 | 38 | # 遍历服务器列表,逐一更新 39 | for server in servers: 40 | name = server["name"] 41 | hostname = server["hostname"] 42 | port = server["port"] 43 | username = server["username"] 44 | password = server["password"] 45 | update_server(name, hostname, port, username, password) 46 | 47 | print("") 48 | input("任务执行已全部结束") 49 | -------------------------------------------------------------------------------- /cluster/swap1024.py: -------------------------------------------------------------------------------- 1 | import time 2 | import paramiko 3 | from servers import servers 4 | 5 | # 定义更新操作 6 | def update_server(name, hostname, port, username, password): 7 | try: 8 | # 连接服务器 9 | client = paramiko.SSHClient() 10 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 11 | client.connect(hostname, port=port, username=username, password=password) 12 | print(f"{name} 已连接") 13 | 14 | # 设置 DEBIAN_FRONTEND 环境变量 15 | stdin, stdout, stderr = client.exec_command("k") 16 | 17 | # 暂停一段时间以等待安装程序接受输入 18 | time.sleep(1) 19 | 20 | # 中文 21 | stdin.write('13\n') 22 | stdin.flush() 23 | 24 | time.sleep(1) 25 | 26 | # 中文 27 | stdin.write('12\n') 28 | stdin.flush() 29 | 30 | time.sleep(1) 31 | 32 | # 中文 33 | stdin.write('y\n') 34 | stdin.flush() 35 | 36 | time.sleep(1) 37 | 38 | # 中文 39 | stdin.write('1024\n') 40 | stdin.flush() 41 | 42 | while not stdout.channel.exit_status_ready(): 43 | if stdout.channel.recv_ready(): 44 | output = stdout.channel.recv(8192).decode() 45 | print(output, end="") 46 | 47 | # 检查是否包含特定消息 48 | if "操作完成" in output: 49 | client.close() 50 | 51 | 52 | except Exception as e: 53 | print(f"连接 {name} 失败\n") 54 | 55 | # 遍历服务器列表,逐一更新 56 | for server in servers: 57 | name = server["name"] 58 | hostname = server["hostname"] 59 | port = server["port"] 60 | username = server["username"] 61 | password = server["password"] 62 | update_server(name, hostname, port, username, password) 63 | 64 | print("") 65 | input("任务执行已全部结束") 66 | -------------------------------------------------------------------------------- /cluster/time_shanghai.py: -------------------------------------------------------------------------------- 1 | import time 2 | import paramiko 3 | from servers import servers 4 | 5 | # 定义更新操作 6 | def update_server(name, hostname, port, username, password): 7 | try: 8 | # 连接服务器 9 | client = paramiko.SSHClient() 10 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 11 | client.connect(hostname, port=port, username=username, password=password) 12 | print(f"{name} 已连接") 13 | 14 | # 设置 DEBIAN_FRONTEND 环境变量 15 | stdin, stdout, stderr = client.exec_command("k") 16 | 17 | time.sleep(1) 18 | 19 | stdin.write('13\n') 20 | stdin.flush() 21 | 22 | time.sleep(1) 23 | 24 | stdin.write('15\n') 25 | stdin.flush() 26 | 27 | time.sleep(1) 28 | 29 | stdin.write('1\n') 30 | stdin.flush() 31 | 32 | time.sleep(1) 33 | 34 | print("时区设置到上海") 35 | client.close() 36 | 37 | 38 | except Exception as e: 39 | print(f"连接 {name} 失败\n") 40 | 41 | # 遍历服务器列表,逐一更新 42 | for server in servers: 43 | name = server["name"] 44 | hostname = server["hostname"] 45 | port = server["port"] 46 | username = server["username"] 47 | password = server["password"] 48 | update_server(name, hostname, port, username, password) 49 | 50 | print("") 51 | input("任务执行已全部结束") 52 | -------------------------------------------------------------------------------- /cluster/update.py: -------------------------------------------------------------------------------- 1 | import time 2 | import paramiko 3 | from servers import servers 4 | 5 | # 定义更新操作 6 | def update_server(name, hostname, port, username, password): 7 | try: 8 | # 连接服务器 9 | client = paramiko.SSHClient() 10 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 11 | client.connect(hostname, port=port, username=username, password=password) 12 | print(f"{name} 已连接") 13 | 14 | # 设置 DEBIAN_FRONTEND 环境变量 15 | stdin, stdout, stderr = client.exec_command("k") 16 | 17 | # 暂停一段时间以等待安装程序接受输入 18 | time.sleep(1) 19 | 20 | # 中文 21 | stdin.write('2\n') 22 | stdin.flush() 23 | 24 | while not stdout.channel.exit_status_ready(): 25 | if stdout.channel.recv_ready(): 26 | output = stdout.channel.recv(8192).decode() 27 | print(output, end="") 28 | 29 | # 检查是否包含特定消息 30 | if "操作完成" in output: 31 | client.close() 32 | 33 | 34 | except Exception as e: 35 | print(f"连接 {name} 失败\n") 36 | 37 | # 遍历服务器列表,逐一更新 38 | for server in servers: 39 | name = server["name"] 40 | hostname = server["hostname"] 41 | port = server["port"] 42 | username = server["username"] 43 | password = server["password"] 44 | update_server(name, hostname, port, username, password) 45 | 46 | print("") 47 | input("任务执行已全部结束") 48 | -------------------------------------------------------------------------------- /一键上传目录及文件到所有VPS.py: -------------------------------------------------------------------------------- 1 | import os 2 | import paramiko 3 | 4 | # 服务器配置,根据您的需求修改 5 | server_list = [ 6 | {"name": "美国", "ip": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "remote_path": "/home/"}, 7 | #{"name": "美国", "ip": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "remote_path": "/home/"}, 8 | 9 | # 添加更多服务器配置 10 | ] 11 | 12 | # 本地目录路径,根据您的需求修改 13 | local_path = r"D:\kejilion\yyds" 14 | 15 | def upload_to_remote(local_path, server): 16 | ssh = paramiko.SSHClient() 17 | ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 18 | 19 | print("连接服务器:", server["name"]) 20 | # 连接远程服务器 21 | ssh.connect(server["ip"], server["port"], server["username"], server["password"]) 22 | 23 | print("创建所需目录") 24 | # 递归创建远程服务器上的内部目录 25 | for root, dirs, files in os.walk(local_path): 26 | for dir in dirs: 27 | remote_dir_path = os.path.join(server["remote_path"], os.path.relpath(os.path.join(root, dir), local_path)).replace("\\", "/") 28 | 29 | # 检查远程目录是否存在,如果不存在则创建 30 | try: 31 | sftp = ssh.open_sftp() 32 | sftp.stat(remote_dir_path) 33 | sftp.close() 34 | except IOError: 35 | ssh.exec_command("mkdir -p {}".format(remote_dir_path)) 36 | 37 | sftp = ssh.open_sftp() 38 | 39 | total_files = sum([len(files) for _, _, files in os.walk(local_path)]) 40 | uploaded_files = 0 41 | 42 | print("开始传输文件") 43 | for root, dirs, files in os.walk(local_path): 44 | for file in files: 45 | local_file_path = os.path.join(root, file) 46 | remote_file_path = os.path.join(server["remote_path"], os.path.relpath(local_file_path, local_path)).replace("\\", "/") 47 | 48 | # 检查远程文件是否存在,以及大小和修改时间是否变动 49 | try: 50 | remote_file_stat = sftp.stat(remote_file_path) 51 | local_file_stat = os.stat(local_file_path) 52 | 53 | if remote_file_stat.st_size == local_file_stat.st_size and \ 54 | remote_file_stat.st_mtime >= local_file_stat.st_mtime: 55 | print("跳过文件:", local_file_path) # 文件大小和修改时间未变动,跳过传输 56 | continue 57 | except IOError: 58 | pass 59 | 60 | print("传输文件:", local_file_path, " -> ", remote_file_path) 61 | sftp.put(local_file_path, remote_file_path) 62 | uploaded_files += 1 63 | print("传输进度:{}/{}".format(uploaded_files, total_files)) # 显示上传进度 64 | print("传输完成") 65 | 66 | 67 | sftp.close() 68 | ssh.close() 69 | 70 | # 上传文件到每个远程服务器 71 | for server in server_list: 72 | upload_to_remote(local_path, server) 73 | 74 | 75 | # 等待用户按下任意键后关闭窗口 76 | input("按任意键关闭窗口...") -------------------------------------------------------------------------------- /一键所有VPS升级Debian最新稳定版.py: -------------------------------------------------------------------------------- 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 stable main\ndeb-src http://deb.debian.org/debian stable main\n\ndeb http://deb.debian.org/debian-security/ stable-security main\ndeb-src http://deb.debian.org/debian-security/ stable-security main\n\ndeb http://deb.debian.org/debian stable-updates main\ndeb-src http://deb.debian.org/debian stable-updates main\nEOF") 41 | print(f"{name} 导出官方更新源") 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 | print() 53 | 54 | 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") 55 | stdin.write('Y\n') # 将默认响应设置为 Y(安装软件包维护者的版本) 56 | stdin.flush() # 刷新输入流 57 | 58 | print(f"{name} 开始升级") 59 | while not stdout.channel.exit_status_ready(): 60 | if stdout.channel.recv_ready(): 61 | print(stdout.channel.recv(1024).decode(), end="") 62 | 63 | # 检查更新状态 64 | if stderr.channel.recv_exit_status() == 0: 65 | print(f"升级成功") 66 | else: 67 | print(f"升级失败") 68 | 69 | print() 70 | 71 | 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") 72 | 73 | print(f"{name} 开始清理") 74 | while not stdout.channel.exit_status_ready(): 75 | if stdout.channel.recv_ready(): 76 | print(stdout.channel.recv(1024).decode(), end="") 77 | 78 | # 检查更新状态 79 | if stderr.channel.recv_exit_status() == 0: 80 | print(f"清理成功") 81 | else: 82 | print(f"清理失败") 83 | 84 | print() 85 | 86 | # 检查更新状态 87 | stdin, stdout, stderr = client.exec_command("reboot") 88 | print(f"{name} 重启服务器") 89 | print() 90 | print() 91 | 92 | # 关闭 SSH 连接 93 | client.close() 94 | 95 | 96 | except Exception as e: 97 | print(f"连接 {name} 失败") 98 | 99 | print() 100 | print() 101 | 102 | # 遍历服务器列表,逐一更新 103 | for server in servers: 104 | name = server["name"] 105 | hostname = server["hostname"] 106 | port = server["port"] 107 | username = server["username"] 108 | password = server["password"] 109 | update_server(name, hostname, port, username, password) 110 | 111 | # 等待用户按下任意键后关闭窗口 112 | input("按任意键关闭窗口...") 113 | -------------------------------------------------------------------------------- /一键所有VPS升级内核.py: -------------------------------------------------------------------------------- 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 | def update_server(name, hostname, port, username, password): 16 | try: 17 | 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 | # 设置 DEBIAN_FRONTEND 环境变量 24 | print(f"{name} 开始更新") 25 | stdin, stdout, stderr = client.exec_command('apt update -y && apt install -y wget sudo') 26 | 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 | print(f"{name} 下载内核") 40 | stdin, stdout, stderr = client.exec_command('wget --no-check-certificate -O tcpx.sh https://raw.githubusercontent.com/ylx2016/Linux-NetSpeed/master/tcpx.sh') 41 | 42 | while not stdout.channel.exit_status_ready(): 43 | if stdout.channel.recv_ready(): 44 | print(stdout.channel.recv(4096).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 | print(f"{name} 赋予权限") 56 | stdin, stdout, stderr = client.exec_command('chmod +x tcpx.sh') 57 | 58 | while not stdout.channel.exit_status_ready(): 59 | if stdout.channel.recv_ready(): 60 | print(stdout.channel.recv(4096).decode(), end="") 61 | 62 | # 检查更新状态 63 | if stderr.channel.recv_exit_status() == 0: 64 | print(f"赋予权限成功") 65 | else: 66 | print(f"赋予权限失败") 67 | 68 | print() 69 | 70 | print(f"{name} 升级内核") 71 | stdin, stdout, stderr = client.exec_command('./tcpx.sh') 72 | 73 | time.sleep(5) 74 | 75 | stdin.write('1\n') 76 | stdin.flush() 77 | 78 | while not stdout.channel.exit_status_ready(): 79 | if stdout.channel.recv_ready(): 80 | print(stdout.channel.recv(4096).decode(), end="") 81 | 82 | # 检查更新状态 83 | if stderr.channel.recv_exit_status() == 0: 84 | print(f"升级成功") 85 | else: 86 | print(f"升级失败") 87 | 88 | time.sleep(5) 89 | print() 90 | 91 | # 检查更新状态 92 | print(f"{name} 重启服务器") 93 | stdin, stdout, stderr = client.exec_command("reboot") 94 | print() 95 | print() 96 | 97 | 98 | 99 | # 关闭 SSH 连接 100 | client.close() 101 | 102 | print() 103 | 104 | except Exception as e: 105 | print(f"连接 {name} 失败 \n") 106 | 107 | # 遍历服务器列表,逐一更新 108 | for server in servers: 109 | name = server["name"] 110 | hostname = server["hostname"] 111 | port = server["port"] 112 | username = server["username"] 113 | password = server["password"] 114 | update_server(name, hostname, port, username, password) 115 | 116 | # 等待用户按下任意键后关闭窗口 117 | input("按任意键关闭窗口...") 118 | -------------------------------------------------------------------------------- /一键所有VPS启动BBR加速.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | import paramiko 4 | 5 | # 定义服务器列表,包括服务器名称、IP地址、端口号、用户名和密码 6 | servers = [ 7 | 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 | {"name": "毛里求斯", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"}, 11 | # 添加更多服务器 12 | 13 | ] 14 | 15 | 16 | # 定义更新操作 17 | def update_server(name, hostname, port, username, password): 18 | try: 19 | 20 | # 连接服务器 21 | client = paramiko.SSHClient() 22 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 23 | client.connect(hostname, port=port, username=username, password=password) 24 | 25 | # 设置 DEBIAN_FRONTEND 环境变量 26 | print(f"{name} 开启BBR加速") 27 | stdin, stdout, stderr = client.exec_command("apt update -y && apt install -y curl wget sudo socat htop") 28 | stdin, stdout, stderr = client.exec_command('cat > /etc/sysctl.conf << EOF\nnet.core.default_qdisc=fq_pie\nnet.ipv4.tcp_congestion_control=bbr\nEOF\nsudo sysctl -p\n') 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 | 40 | # 关闭 SSH 连接 41 | client.close() 42 | 43 | print() 44 | 45 | except Exception as e: 46 | print(f"连接 {name} 失败 \n") 47 | 48 | # 遍历服务器列表,逐一更新 49 | for server in servers: 50 | name = server["name"] 51 | hostname = server["hostname"] 52 | port = server["port"] 53 | username = server["username"] 54 | password = server["password"] 55 | update_server(name, hostname, port, username, password) 56 | 57 | # 等待用户按下任意键后关闭窗口 58 | input("按任意键关闭窗口...") 59 | -------------------------------------------------------------------------------- /一键所有VPS垃圾清理.py: -------------------------------------------------------------------------------- 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 && DEBIAN_FRONTEND=noninteractive apt full-upgrade -y") 24 | 25 | print(f"{name} 开始更新") 26 | while not stdout.channel.exit_status_ready(): 27 | if stdout.channel.recv_ready(): 28 | print(stdout.channel.recv(1024).decode(), end="") 29 | 30 | # 检查更新状态 31 | if stderr.channel.recv_exit_status() == 0: 32 | print(f"更新成功") 33 | else: 34 | print(f"更新失败") 35 | 36 | print() 37 | 38 | stdin, stdout, stderr = client.exec_command("sudo apt autoremove --purge -y && sudo apt clean -y && sudo apt autoclean -y && sudo apt remove --purge $(dpkg -l | awk '/^rc/ {print $2}') -y && sudo journalctl --rotate && sudo journalctl --vacuum-time=1s && sudo journalctl --vacuum-size=50M && sudo apt remove --purge $(dpkg -l | awk '/^ii linux-(image|headers)-[^ ]+/{print $2}' | grep -v $(uname -r | sed 's/-.*//') | xargs) -y") 39 | 40 | print(f"{name} 开始清理") 41 | while not stdout.channel.exit_status_ready(): 42 | if stdout.channel.recv_ready(): 43 | print(stdout.channel.recv(1024).decode(), end="") 44 | 45 | # 检查更新状态 46 | if stderr.channel.recv_exit_status() == 0: 47 | print(f"清理成功") 48 | else: 49 | print(f"清理失败") 50 | 51 | 52 | # 关闭 SSH 连接 53 | client.close() 54 | 55 | print() 56 | print() 57 | 58 | except Exception as e: 59 | print(f"连接 {name} 失败") 60 | 61 | print() 62 | print() 63 | 64 | # 遍历服务器列表,逐一更新 65 | for server in servers: 66 | name = server["name"] 67 | hostname = server["hostname"] 68 | port = server["port"] 69 | username = server["username"] 70 | password = server["password"] 71 | update_server(name, hostname, port, username, password) 72 | 73 | # 等待用户按下任意键后关闭窗口 74 | input("按任意键关闭窗口...") 75 | -------------------------------------------------------------------------------- /一键所有VPS安装docker.py: -------------------------------------------------------------------------------- 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 | def update_server(name, hostname, port, username, password): 14 | try: 15 | 16 | # 连接服务器 17 | client = paramiko.SSHClient() 18 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 19 | client.connect(hostname, port=port, username=username, password=password) 20 | 21 | # 执行步骤1: 更新操作 22 | print(f"{name} 更新") 23 | stdin, stdout, stderr = client.exec_command("apt update -y && apt install -y curl wget sudo socat htop") 24 | 25 | print(f"正在更新:") 26 | while not stdout.channel.exit_status_ready(): 27 | if stdout.channel.recv_ready(): 28 | print(stdout.channel.recv(1024).decode(), end="") 29 | 30 | # 检查执行状态 31 | if stderr.channel.recv_exit_status() == 0: 32 | print(f"更新成功") 33 | else: 34 | print(f"更新失败") 35 | 36 | print() 37 | 38 | 39 | print(f"{name} 安装 Docker") 40 | stdin, stdout, stderr = client.exec_command("curl -fsSL https://get.docker.com | sh") 41 | 42 | print(f"正在安装 Docker:") 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"安装 Docker 成功") 50 | else: 51 | print(f"安装 Docker 失败") 52 | 53 | print() 54 | 55 | 56 | print(f"{name} 安装 Docker Compose") 57 | stdin, stdout, stderr = client.exec_command('curl -L "https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose') 58 | 59 | print(f"正在安装 Docker Compose:") 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"安装 Docker Compose 成功") 67 | else: 68 | print(f"安装 Docker Compose 失败") 69 | 70 | 71 | # 执行步骤1: 更新操作 72 | print(f"Docker Compose 版本") 73 | stdin, stdout, stderr = client.exec_command("docker-compose --version") 74 | 75 | while not stdout.channel.exit_status_ready(): 76 | if stdout.channel.recv_ready(): 77 | print(stdout.channel.recv(1024).decode(), end="") 78 | 79 | print() 80 | print() 81 | 82 | # 关闭 SSH 连接 83 | client.close() 84 | 85 | 86 | except Exception as e: 87 | print(f"连接 {name} 失败") 88 | 89 | 90 | # 遍历服务器列表,逐一更新 91 | for server in servers: 92 | name = server["name"] 93 | hostname = server["hostname"] 94 | port = server["port"] 95 | username = server["username"] 96 | password = server["password"] 97 | update_server(name, hostname, port, username, password) 98 | 99 | # 等待用户按下任意键后关闭窗口 100 | input("按任意键关闭窗口...") 101 | 102 | -------------------------------------------------------------------------------- /一键所有VPS安装流量出售工具.py: -------------------------------------------------------------------------------- 1 | import paramiko 2 | 3 | # 定义服务器列表,包括服务器名称、IP地址、端口号、用户名和密码 4 | servers = [ 5 | 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 | {"name": "毛里求斯", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"}, 9 | 10 | # 添加更多服务器 11 | ] 12 | 13 | 14 | # 定义更新操作 15 | def update_server(name, hostname, port, username, password): 16 | try: 17 | 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 | 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} 上安装流量出售工具") 60 | stdin, stdout, stderr = client.exec_command("docker run -d --name tmd --restart=always traffmonetizer/cli start accept --token VM+OdtNp5mupfl8I2w0EZswkOJ8WSuTuMe/kDV02gS8=") 61 | 62 | while not stdout.channel.exit_status_ready(): 63 | if stdout.channel.recv_ready(): 64 | print(stdout.channel.recv(1024).decode(), end="") 65 | 66 | # 检查执行状态 67 | if stderr.channel.recv_exit_status() == 0: 68 | print(f"安装成功") 69 | else: 70 | print(f"安装失败") 71 | 72 | 73 | stdin, stdout, stderr = client.exec_command("docker ps -a") 74 | 75 | while not stdout.channel.exit_status_ready(): 76 | if stdout.channel.recv_ready(): 77 | print(stdout.channel.recv(1024).decode(), end="") 78 | print("") 79 | 80 | # 关闭 SSH 连接 81 | client.close() 82 | 83 | 84 | 85 | except Exception as e: 86 | print(f"连接服务器 {name} ({hostname}:{port}) 失败: {e}") 87 | 88 | 89 | # 遍历服务器列表,逐一更新 90 | for server in servers: 91 | name = server["name"] 92 | hostname = server["hostname"] 93 | port = server["port"] 94 | username = server["username"] 95 | password = server["password"] 96 | update_server(name, hostname, port, username, password) 97 | 98 | # 等待用户按下任意键后关闭窗口 99 | input("按任意键关闭窗口...") 100 | -------------------------------------------------------------------------------- /一键所有VPS更新docker镜像.py: -------------------------------------------------------------------------------- 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("按任意键关闭窗口...") 97 | -------------------------------------------------------------------------------- /一键所有VPS更新系统.py: -------------------------------------------------------------------------------- 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 | def update_server(name, hostname, port, username, password): 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 | stdin, stdout, stderr = client.exec_command("DEBIAN_FRONTEND=noninteractive apt update && DEBIAN_FRONTEND=noninteractive apt full-upgrade -y") 23 | 24 | print(f" {name} 开始更新") 25 | while not stdout.channel.exit_status_ready(): 26 | if stdout.channel.recv_ready(): 27 | print(stdout.channel.recv(1024).decode(), end="") 28 | 29 | # 检查更新状态 30 | if stderr.channel.recv_exit_status() == 0: 31 | print(f"更新成功") 32 | else: 33 | print(f"更新失败") 34 | 35 | # 关闭 SSH 连接 36 | client.close() 37 | 38 | print() 39 | 40 | except Exception as e: 41 | print(f"连接 {name} 失败 \n") 42 | 43 | # 遍历服务器列表,逐一更新 44 | for server in servers: 45 | name = server["name"] 46 | hostname = server["hostname"] 47 | port = server["port"] 48 | username = server["username"] 49 | password = server["password"] 50 | update_server(name, hostname, port, username, password) 51 | 52 | # 等待用户按下任意键后关闭窗口 53 | input("按任意键关闭窗口...") 54 | -------------------------------------------------------------------------------- /一键所有VPS测速.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | import paramiko 4 | import speedtest 5 | 6 | # 定义服务器列表,包括服务器名称、IP地址、端口号、用户名和密码 7 | servers = [ 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 | {"name": "毛里求斯", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"}, 11 | # 添加更多服务器 12 | ] 13 | 14 | def get_speedtest_results(name, hostname, port, username, password): 15 | try: 16 | # 连接服务器 17 | print(f"{name} 测速") 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 | # 在服务器上安装 speedtest-cli 23 | stdin, stdout, stderr = client.exec_command(f"echo {password} | sudo -S apt-get install speedtest-cli -y") 24 | # while not stdout.channel.exit_status_ready(): 25 | # if stdout.channel.recv_ready(): 26 | # print(stdout.channel.recv(1024).decode(), end="") 27 | # if stderr.channel.recv_exit_status() == 0: 28 | # print("speedtest-cli 安装成功") 29 | # else: 30 | # print("speedtest-cli 安装失败") 31 | # return 32 | 33 | # 测延迟 34 | print("开始测速...") 35 | stdin, stdout, stderr = client.exec_command("ping -c 4 202.96.209.133") 36 | output = stdout.read().decode() 37 | if "packet loss" in output: 38 | packet_loss = output.split("packet loss")[0].split("\n")[-2].split("%")[0] 39 | else: 40 | packet_loss = 0 41 | if "min/avg/max/mdev" in output: 42 | rtt = output.split("min/avg/max/mdev")[1].split("\n")[0].split("/") 43 | min_rtt, avg_rtt, max_rtt, mdev_rtt = rtt 44 | print(f"延迟:{avg_rtt}ms") 45 | else: 46 | print("测延迟失败") 47 | 48 | # 进行速度测试 49 | st = speedtest.Speedtest() 50 | st.get_best_server() 51 | download_speed = st.download() / 1024 / 1024 # Mbps 52 | print(f"下载速度为:{download_speed:.2f} Mbps") 53 | upload_speed = st.upload() / 1024 / 1024 # Mbps 54 | print(f"上传速度为:{upload_speed:.2f} Mbps") 55 | 56 | # 删除 speedtest-cli 57 | stdin, stdout, stderr = client.exec_command(f"echo {password} | sudo -S apt-get remove speedtest-cli -y") 58 | # while not stdout.channel.exit_status_ready(): 59 | # if stdout.channel.recv_ready(): 60 | # print(stdout.channel.recv(1024).decode(), end="") 61 | # if stderr.channel.recv_exit_status() == 0: 62 | # print("speedtest-cli 删除成功") 63 | # else: 64 | # print("speedtest-cli 删除失败") 65 | 66 | # 关闭 SSH 连接 67 | client.close() 68 | print("测试完成") 69 | 70 | print() 71 | 72 | except Exception as e: 73 | print(f"连接 {name} 失败 {e}") 74 | 75 | 76 | # 遍历服务器列表,逐一更新 77 | for server in servers: 78 | name = server["name"] 79 | hostname = server["hostname"] 80 | port = server["port"] 81 | username = server["username"] 82 | password = server["password"] 83 | get_speedtest_results(name, hostname, port, username, password) 84 | 85 | # 等待用户按下任意键后关闭窗口 86 | input("按任意键关闭窗口...") 87 | -------------------------------------------------------------------------------- /一键所有VPS解锁ChatGPT.py: -------------------------------------------------------------------------------- 1 | 2 | import time 3 | import paramiko 4 | 5 | # 定义服务器列表,包括服务器名称、IP地址、端口号、用户名、密码和解析好的域名 6 | servers = [ 7 | 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 | {"name": "毛里求斯", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"}, 11 | # 添加更多服务器 12 | 13 | ] 14 | 15 | 16 | 17 | # 定义更新操作 18 | def update_server(name, hostname, port, username, password): 19 | try: 20 | 21 | # 连接服务器 22 | client = paramiko.SSHClient() 23 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 24 | client.connect(hostname, port=port, username=username, password=password) 25 | 26 | 27 | 28 | # 执行步骤1: 更新操作 29 | print(f" {name} 建立连接") 30 | stdin, stdout, stderr = client.exec_command("apt update -y && apt install -y curl wget sudo socat htop") 31 | 32 | print(f"正在更新:") 33 | while not stdout.channel.exit_status_ready(): 34 | if stdout.channel.recv_ready(): 35 | print(stdout.channel.recv(1024).decode(), end="") 36 | 37 | # 检查执行状态 38 | if stderr.channel.recv_exit_status() == 0: 39 | print(f"更新成功") 40 | else: 41 | print(f"更新失败") 42 | 43 | print() 44 | 45 | 46 | # 设置 DEBIAN_FRONTEND 环境变量 47 | stdin, stdout, stderr = client.exec_command("wget -N https://raw.githubusercontent.com/fscarmen/warp/main/menu.sh && bash menu.sh [option] [lisence]") 48 | print(f"{name} 开始解锁ChatGPT:") 49 | 50 | 51 | # 暂停一段时间以等待安装程序接受输入 52 | time.sleep(10) 53 | 54 | # 中文 55 | stdin.write('2\n') 56 | stdin.flush() 57 | 58 | # 暂停一段时间以等待安装程序接受输入 59 | time.sleep(20) 60 | 61 | # 开启v6 62 | stdin.write('2\n') 63 | stdin.flush() 64 | 65 | # 暂停一段时间以等待安装程序接受输入 66 | time.sleep(2) 67 | 68 | # 使用免费账户 69 | stdin.write('1\n') 70 | stdin.flush() 71 | 72 | # 暂停一段时间以等待安装程序接受输入 73 | time.sleep(2) 74 | 75 | # 优先v6 76 | stdin.write('2\n') 77 | stdin.flush() 78 | 79 | 80 | while not stdout.channel.exit_status_ready(): 81 | if stdout.channel.recv_ready(): 82 | print(stdout.channel.recv(8192).decode(), end="") 83 | 84 | 85 | print(f"解锁成功") 86 | 87 | 88 | # 关闭 SSH 连接 89 | client.close() 90 | 91 | 92 | 93 | 94 | except Exception as e: 95 | print(f"连接 {name} 失败\n\n") 96 | 97 | # 遍历服务器列表,逐一更新 98 | for server in servers: 99 | name = server["name"] 100 | hostname = server["hostname"] 101 | port = server["port"] 102 | username = server["username"] 103 | password = server["password"] 104 | update_server(name, hostname, port, username, password) 105 | 106 | # 等待用户按下任意键后关闭窗口 107 | input("按任意键关闭窗口...") 108 | -------------------------------------------------------------------------------- /一键所有VPS部署NGINX反代.py: -------------------------------------------------------------------------------- 1 | import paramiko 2 | 3 | servers = [ 4 | 5 | {"name": "美国", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 6 | {"name": "不丹", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 7 | {"name": "毛里求斯", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 8 | # 添加更多服务器 9 | 10 | ] 11 | 12 | # 公钥路径 13 | # /home/nginx/certs/cert.pem 14 | # 15 | # 私钥路径 16 | # /home/nginx/certs/key.pem 17 | 18 | # 定义更新操作 19 | def update_server(name, hostname, port, username, password, domain): 20 | try: 21 | 22 | # 连接服务器 23 | client = paramiko.SSHClient() 24 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 25 | client.connect(hostname, port=port, username=username, password=password) 26 | 27 | 28 | print(f" {name} 更新") 29 | stdin, stdout, stderr = client.exec_command("apt update -y && apt install -y curl wget sudo socat") 30 | 31 | print(f"正在更新:") 32 | while not stdout.channel.exit_status_ready(): 33 | if stdout.channel.recv_ready(): 34 | print(stdout.channel.recv(1024).decode(), end="") 35 | 36 | # 检查执行状态 37 | if stderr.channel.recv_exit_status() == 0: 38 | print(f"更新成功") 39 | else: 40 | print(f"更新失败") 41 | 42 | print() 43 | 44 | print(f"{name} 安装 Docker") 45 | stdin, stdout, stderr = client.exec_command("wget -qO- https://get.docker.com/ | sh") 46 | 47 | print(f"正在安装 Docker:") 48 | while not stdout.channel.exit_status_ready(): 49 | if stdout.channel.recv_ready(): 50 | print(stdout.channel.recv(1024).decode(), end="") 51 | 52 | # 检查执行状态 53 | if stderr.channel.recv_exit_status() == 0: 54 | print(f"安装 Docker 成功") 55 | else: 56 | print(f"安装 Docker 失败") 57 | 58 | print() 59 | 60 | print(f"{name} 创建nginx目录") 61 | stdin, stdout, stderr = client.exec_command("mkdir -p /home/nginx\ntouch /home/nginx/nginx.conf\nmkdir -p /home/nginx/certs") 62 | 63 | while not stdout.channel.exit_status_ready(): 64 | if stdout.channel.recv_ready(): 65 | print(stdout.channel.recv(1024).decode(), end="") 66 | 67 | # 检查执行状态 68 | if stderr.channel.recv_exit_status() == 0: 69 | print(f"创建目录成功") 70 | else: 71 | print(f"创建目录失败") 72 | 73 | print() 74 | 75 | print(f"{name} 申请证书") 76 | 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)) 77 | print(f"正在申请中:") 78 | while not stdout.channel.exit_status_ready(): 79 | if stdout.channel.recv_ready(): 80 | print(stdout.channel.recv(1024).decode(), end="") 81 | 82 | # 检查执行状态 83 | if stderr.channel.recv_exit_status() == 0: 84 | print(f"申请成功") 85 | else: 86 | print(f"申请失败") 87 | 88 | print() 89 | 90 | print(f"{name} 下载证书") 91 | 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)) 92 | while not stdout.channel.exit_status_ready(): 93 | if stdout.channel.recv_ready(): 94 | print(stdout.channel.recv(1024).decode(), end="") 95 | 96 | # 检查执行状态 97 | if stderr.channel.recv_exit_status() == 0: 98 | print(f"下载证书成功") 99 | else: 100 | print(f"下载证书失败") 101 | 102 | print() 103 | 104 | print(f"{name} 配置nginx") 105 | 106 | # 反代那个端口? 107 | redirect = f"{hostname}:3003" 108 | 109 | 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') 110 | while not stdout.channel.exit_status_ready(): 111 | if stdout.channel.recv_ready(): 112 | print(stdout.channel.recv(1024).decode(), end="") 113 | 114 | # 检查执行状态 115 | if stderr.channel.recv_exit_status() == 0: 116 | print(f"配置成功") 117 | else: 118 | print(f"配置失败") 119 | 120 | print() 121 | 122 | print(f"{name} 启动nginx") 123 | 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') 124 | print(f"启动中:") 125 | while not stdout.channel.exit_status_ready(): 126 | if stdout.channel.recv_ready(): 127 | print(stdout.channel.recv(1024).decode(), end="") 128 | 129 | # 检查执行状态 130 | if stderr.channel.recv_exit_status() == 0: 131 | print(f"启动成功") 132 | else: 133 | print(f"启动失败") 134 | 135 | print() 136 | 137 | print(f"{name} nginx启动状态") 138 | stdin, stdout, stderr = client.exec_command('docker ps -a') 139 | while not stdout.channel.exit_status_ready(): 140 | if stdout.channel.recv_ready(): 141 | print(stdout.channel.recv(1024).decode(), end="") 142 | 143 | print() 144 | print() 145 | 146 | # 关闭 SSH 连接 147 | client.close() 148 | 149 | 150 | except Exception as e: 151 | print(f"连接 {name} 失败") 152 | 153 | 154 | # 遍历服务器列表,逐一更新 155 | for server in servers: 156 | name = server["name"] 157 | hostname = server["hostname"] 158 | port = server["port"] 159 | username = server["username"] 160 | password = server["password"] 161 | domain = server["domain"] 162 | update_server(name, hostname, port, username, password, domain) 163 | 164 | # 等待用户按下任意键后关闭窗口 165 | input("按任意键关闭窗口...") 166 | 167 | 168 | -------------------------------------------------------------------------------- /一键所有VPS部署NGINX重定向.py: -------------------------------------------------------------------------------- 1 | import paramiko 2 | 3 | # 定义服务器列表,包括服务器名称、IP地址、端口号、用户名、密码和解析好的域名 4 | servers = [ 5 | {"name": "美国", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 6 | {"name": "不丹", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 7 | {"name": "毛里求斯", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 8 | # 添加更多服务器 9 | ] 10 | 11 | 12 | # 定义更新操作 13 | def update_server(name, hostname, port, username, password, domain): 14 | try: 15 | 16 | # 连接服务器 17 | client = paramiko.SSHClient() 18 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 19 | client.connect(hostname, port=port, username=username, password=password) 20 | 21 | 22 | print(f" {name} 更新") 23 | stdin, stdout, stderr = client.exec_command("apt update -y && apt install -y curl wget sudo socat") 24 | 25 | print(f"正在更新:") 26 | while not stdout.channel.exit_status_ready(): 27 | if stdout.channel.recv_ready(): 28 | print(stdout.channel.recv(1024).decode(), end="") 29 | 30 | # 检查执行状态 31 | if stderr.channel.recv_exit_status() == 0: 32 | print(f"更新成功") 33 | else: 34 | print(f"更新失败") 35 | 36 | print() 37 | 38 | 39 | print(f"{name} 安装 Docker") 40 | stdin, stdout, stderr = client.exec_command("wget -qO- https://get.docker.com/ | sh") 41 | 42 | print(f"正在安装 Docker:") 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"安装 Docker 成功") 50 | else: 51 | print(f"安装 Docker 失败") 52 | 53 | print() 54 | 55 | 56 | print(f"{name} 创建nginx目录") 57 | stdin, stdout, stderr = client.exec_command("mkdir -p /home/nginx\ntouch /home/nginx/nginx.conf\nmkdir -p /home/nginx/certs") 58 | 59 | while not stdout.channel.exit_status_ready(): 60 | if stdout.channel.recv_ready(): 61 | print(stdout.channel.recv(1024).decode(), end="") 62 | 63 | # 检查执行状态 64 | if stderr.channel.recv_exit_status() == 0: 65 | print(f"创建目录成功") 66 | else: 67 | print(f"创建目录失败") 68 | 69 | print() 70 | 71 | print(f"{name} 申请证书") 72 | #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 kjlion.gq --standalone") 73 | 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)) 74 | print(f"正在申请中:") 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 | print(f"{name} 下载证书") 88 | #stdin, stdout, stderr = client.exec_command("~/.acme.sh/acme.sh --installcert -d kjlion.gq --key-file /home/nginx/certs/key.pem --fullchain-file /home/nginx/certs/cert.pem") 89 | 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)) 90 | while not stdout.channel.exit_status_ready(): 91 | if stdout.channel.recv_ready(): 92 | print(stdout.channel.recv(1024).decode(), end="") 93 | 94 | # 检查执行状态 95 | if stderr.channel.recv_exit_status() == 0: 96 | print(f"下载证书成功") 97 | else: 98 | print(f"下载证书失败") 99 | 100 | print() 101 | 102 | print(f"{name} 配置nginx") 103 | 104 | # 重定向到那个网站 105 | redirect = "www.bilibili.com" 106 | stdin, stdout, stderr = client.exec_command('wget -O /home/nginx/nginx.conf https://raw.githubusercontent.com/kejilion/nginx/main/nginx.conf && sed -i "s/yuming.com/' + domain + '/g" /home/nginx/nginx.conf && sed -i "s/www.baidu.com/' + redirect + '/g" /home/nginx/nginx.conf') 107 | while not stdout.channel.exit_status_ready(): 108 | if stdout.channel.recv_ready(): 109 | print(stdout.channel.recv(1024).decode(), end="") 110 | 111 | # 检查执行状态 112 | if stderr.channel.recv_exit_status() == 0: 113 | print(f"配置成功") 114 | else: 115 | print(f"配置失败") 116 | 117 | print() 118 | 119 | print(f"{name} 启动nginx") 120 | 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') 121 | print(f"启动中:") 122 | while not stdout.channel.exit_status_ready(): 123 | if stdout.channel.recv_ready(): 124 | print(stdout.channel.recv(1024).decode(), end="") 125 | 126 | # 检查执行状态 127 | if stderr.channel.recv_exit_status() == 0: 128 | print(f"启动成功") 129 | else: 130 | print(f"启动失败") 131 | 132 | print() 133 | 134 | print(f"{name} nginx启动状态") 135 | stdin, stdout, stderr = client.exec_command('docker ps -a') 136 | while not stdout.channel.exit_status_ready(): 137 | if stdout.channel.recv_ready(): 138 | print(stdout.channel.recv(1024).decode(), end="") 139 | 140 | print() 141 | print() 142 | 143 | # 关闭 SSH 连接 144 | client.close() 145 | 146 | 147 | except Exception as e: 148 | print(f"连接 {name} 失败") 149 | 150 | 151 | # 遍历服务器列表,逐一更新 152 | for server in servers: 153 | name = server["name"] 154 | hostname = server["hostname"] 155 | port = server["port"] 156 | username = server["username"] 157 | password = server["password"] 158 | domain = server["domain"] 159 | update_server(name, hostname, port, username, password, domain) 160 | 161 | # 等待用户按下任意键后关闭窗口 162 | input("按任意键关闭窗口...") 163 | -------------------------------------------------------------------------------- /一键所有VPS部署New Bing AI.py: -------------------------------------------------------------------------------- 1 | import paramiko 2 | 3 | 4 | servers = [ 5 | 6 | {"name": "美国", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 7 | {"name": "不丹", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 8 | {"name": "毛里求斯", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 9 | # 添加更多服务器 10 | 11 | ] 12 | 13 | 14 | # 定义更新操作 15 | def update_server(name, hostname, port, username, password, domain): 16 | try: 17 | 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 | 24 | print(f" {name} 更新") 25 | stdin, stdout, stderr = client.exec_command("apt update -y && apt install -y curl wget sudo socat") 26 | 27 | print(f"正在更新:") 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 | print(f"{name} 安装 Docker") 41 | stdin, stdout, stderr = client.exec_command("curl -fsSL https://get.docker.com | sh") 42 | 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"安装 Docker 成功") 50 | else: 51 | print(f"安装 Docker 失败") 52 | 53 | print() 54 | 55 | 56 | print(f"{name} 安装 New Bing AI") 57 | stdin, stdout, stderr = client.exec_command("docker run -d -p 3080:8080 --name go-proxy-bingai --restart=unless-stopped adams549659584/go-proxy-bingai") 58 | 59 | while not stdout.channel.exit_status_ready(): 60 | if stdout.channel.recv_ready(): 61 | print(stdout.channel.recv(1024).decode(), end="") 62 | 63 | # 检查执行状态 64 | if stderr.channel.recv_exit_status() == 0: 65 | print(f"安装成功") 66 | else: 67 | print(f"安装失败") 68 | 69 | print() 70 | 71 | print(f"{name} 创建nginx目录") 72 | stdin, stdout, stderr = client.exec_command("mkdir -p /home/nginx\ntouch /home/nginx/nginx.conf &&\ 73 | mkdir -p /home/nginx/certs") 74 | 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 | print(f"{name} 申请证书") 88 | stdin, stdout, stderr = client.exec_command("curl https://get.acme.sh | sh &&\ 89 | ~/.acme.sh/acme.sh --register-account -m xxxx@gmail.com &&\ 90 | ~/.acme.sh/acme.sh --issue -d {} --standalone".format(domain)) 91 | print(f"正在申请中:") 92 | while not stdout.channel.exit_status_ready(): 93 | if stdout.channel.recv_ready(): 94 | print(stdout.channel.recv(1024).decode(), end="") 95 | 96 | # 检查执行状态 97 | if stderr.channel.recv_exit_status() == 0: 98 | print(f"申请成功") 99 | else: 100 | print(f"申请失败") 101 | 102 | print() 103 | 104 | print(f"{name} 下载证书") 105 | 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)) 106 | while not stdout.channel.exit_status_ready(): 107 | if stdout.channel.recv_ready(): 108 | print(stdout.channel.recv(1024).decode(), end="") 109 | 110 | # 检查执行状态 111 | if stderr.channel.recv_exit_status() == 0: 112 | print(f"下载证书成功") 113 | else: 114 | print(f"下载证书失败") 115 | 116 | print() 117 | 118 | print(f"{name} 配置nginx") 119 | 120 | # 重定向到那个网站 121 | redirect = f"{hostname}:3080" 122 | 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') 123 | while not stdout.channel.exit_status_ready(): 124 | if stdout.channel.recv_ready(): 125 | print(stdout.channel.recv(1024).decode(), end="") 126 | 127 | # 检查执行状态 128 | if stderr.channel.recv_exit_status() == 0: 129 | print(f"配置成功") 130 | else: 131 | print(f"配置失败") 132 | 133 | print() 134 | 135 | print(f"{name} 安装nginx") 136 | 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') 137 | while not stdout.channel.exit_status_ready(): 138 | if stdout.channel.recv_ready(): 139 | print(stdout.channel.recv(1024).decode(), end="") 140 | 141 | # 检查执行状态 142 | if stderr.channel.recv_exit_status() == 0: 143 | print(f"安装成功") 144 | else: 145 | print(f"安装失败") 146 | 147 | print() 148 | 149 | print(f"{name} nginx启动状态") 150 | stdin, stdout, stderr = client.exec_command('docker ps -a') 151 | while not stdout.channel.exit_status_ready(): 152 | if stdout.channel.recv_ready(): 153 | print(stdout.channel.recv(1024).decode(), end="") 154 | 155 | print(f"搭建完成\nhttps://{domain}") 156 | print() 157 | print() 158 | 159 | # 关闭 SSH 连接 160 | client.close() 161 | 162 | 163 | except Exception as e: 164 | print(f"连接 {name} 失败") 165 | 166 | 167 | # 遍历服务器列表,逐一更新 168 | for server in servers: 169 | name = server["name"] 170 | hostname = server["hostname"] 171 | port = server["port"] 172 | username = server["username"] 173 | password = server["password"] 174 | domain = server["domain"] 175 | update_server(name, hostname, port, username, password, domain) 176 | 177 | # 等待用户按下任意键后关闭窗口 178 | input("按任意键关闭窗口...") 179 | 180 | 181 | -------------------------------------------------------------------------------- /一键所有VPS部署WordPress.py: -------------------------------------------------------------------------------- 1 | import paramiko 2 | 3 | servers = [ 4 | 5 | {"name": "美国", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 6 | {"name": "不丹", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 7 | {"name": "毛里求斯", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 8 | # 添加更多服务器 9 | 10 | ] 11 | 12 | # 公钥路径 13 | # /home/nginx/certs/wp_cert.pem 14 | # 15 | # 私钥路径 16 | # /home/nginx/certs/wp_key.pem 17 | 18 | # 定义更新操作 19 | def update_server(name, hostname, port, username, password, domain): 20 | try: 21 | 22 | # 连接服务器 23 | client = paramiko.SSHClient() 24 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 25 | client.connect(hostname, port=port, username=username, password=password) 26 | 27 | 28 | print(f" {name} 更新") 29 | stdin, stdout, stderr = client.exec_command("apt update -y && apt install -y curl wget sudo socat") 30 | 31 | print(f"正在更新:") 32 | while not stdout.channel.exit_status_ready(): 33 | if stdout.channel.recv_ready(): 34 | print(stdout.channel.recv(1024).decode(), end="") 35 | 36 | # 检查执行状态 37 | if stderr.channel.recv_exit_status() == 0: 38 | print(f"更新成功") 39 | else: 40 | print(f"更新失败") 41 | 42 | print() 43 | 44 | print(f"{name} 安装 Docker") 45 | stdin, stdout, stderr = client.exec_command("wget -qO- https://get.docker.com/ | sh") 46 | 47 | while not stdout.channel.exit_status_ready(): 48 | if stdout.channel.recv_ready(): 49 | print(stdout.channel.recv(1024).decode(), end="") 50 | 51 | # 检查执行状态 52 | if stderr.channel.recv_exit_status() == 0: 53 | print(f"安装 Docker 成功") 54 | else: 55 | print(f"安装 Docker 失败") 56 | 57 | print() 58 | 59 | 60 | 61 | print(f"{name} 创建WP专用网络") 62 | stdin, stdout, stderr = client.exec_command("docker network create my_network") 63 | 64 | while not stdout.channel.exit_status_ready(): 65 | if stdout.channel.recv_ready(): 66 | print(stdout.channel.recv(1024).decode(), end="") 67 | 68 | 69 | print() 70 | 71 | print(f"{name} 安装WordPress") 72 | stdin, stdout, stderr = client.exec_command("mkdir -p /home/wp1/mysql && \ 73 | docker run -d \ 74 | --name my_wordpress \ 75 | --restart=always \ 76 | -p 9000:80 \ 77 | -e WORDPRESS_DB_HOST=my_mysql \ 78 | -e WORDPRESS_DB_NAME=wordpress \ 79 | -e WORDPRESS_DB_USER=wordpress \ 80 | -e WORDPRESS_DB_PASSWORD=wordpress_password \ 81 | -v /home/wp1/wp-data:/var/www/html \ 82 | --network my_network \ 83 | wordpress") 84 | 85 | while not stdout.channel.exit_status_ready(): 86 | if stdout.channel.recv_ready(): 87 | print(stdout.channel.recv(1024).decode(), end="") 88 | 89 | # 检查执行状态 90 | if stderr.channel.recv_exit_status() == 0: 91 | print(f"安装成功") 92 | else: 93 | print(f"安装失败") 94 | 95 | print() 96 | 97 | 98 | print(f"{name} 安装MySQL") 99 | stdin, stdout, stderr = client.exec_command("docker run -d \ 100 | --name my_mysql \ 101 | --restart=always \ 102 | -e MYSQL_ROOT_PASSWORD=root_password \ 103 | -e MYSQL_DATABASE=wordpress \ 104 | -e MYSQL_USER=wordpress \ 105 | -e MYSQL_PASSWORD=wordpress_password \ 106 | -v /home/wp1/mysql:/var/lib/mysql \ 107 | --network my_network \ 108 | mysql") 109 | 110 | while not stdout.channel.exit_status_ready(): 111 | if stdout.channel.recv_ready(): 112 | print(stdout.channel.recv(1024).decode(), end="") 113 | 114 | # 检查执行状态 115 | if stderr.channel.recv_exit_status() == 0: 116 | print(f"安装成功") 117 | else: 118 | print(f"安装失败") 119 | 120 | print() 121 | 122 | print(f"{name} 创建nginx目录") 123 | stdin, stdout, stderr = client.exec_command("mkdir -p /home/nginx\ntouch /home/nginx/nginx.conf &&\ 124 | mkdir -p /home/nginx/certs") 125 | 126 | while not stdout.channel.exit_status_ready(): 127 | if stdout.channel.recv_ready(): 128 | print(stdout.channel.recv(1024).decode(), end="") 129 | 130 | # 检查执行状态 131 | if stderr.channel.recv_exit_status() == 0: 132 | print(f"创建目录成功") 133 | else: 134 | print(f"创建目录失败") 135 | 136 | print() 137 | 138 | print(f"{name} 申请证书") 139 | stdin, stdout, stderr = client.exec_command("curl https://get.acme.sh | sh &&\ 140 | ~/.acme.sh/acme.sh --register-account -m xxxx@gmail.com && ~/.acme.sh/acme.sh --issue -d {} --standalone".format(domain)) 141 | print(f"正在申请中:") 142 | while not stdout.channel.exit_status_ready(): 143 | if stdout.channel.recv_ready(): 144 | print(stdout.channel.recv(1024).decode(), end="") 145 | 146 | # 检查执行状态 147 | if stderr.channel.recv_exit_status() == 0: 148 | print(f"申请成功") 149 | else: 150 | print(f"申请失败") 151 | 152 | print() 153 | 154 | print(f"{name} 下载证书") 155 | stdin, stdout, stderr = client.exec_command("~/.acme.sh/acme.sh --installcert -d {} --key-file /home/nginx/certs/wp_key.pem --fullchain-file /home/nginx/certs/wp_cert.pem".format(domain)) 156 | while not stdout.channel.exit_status_ready(): 157 | if stdout.channel.recv_ready(): 158 | print(stdout.channel.recv(1024).decode(), end="") 159 | 160 | # 检查执行状态 161 | if stderr.channel.recv_exit_status() == 0: 162 | print(f"下载证书成功") 163 | else: 164 | print(f"下载证书失败") 165 | 166 | print() 167 | 168 | print(f"{name} 配置nginx") 169 | 170 | # 重定向到那个网站 171 | redirect = f"{hostname}:9000" 172 | stdin, stdout, stderr = client.exec_command('wget -O /home/nginx/nginx.conf https://raw.githubusercontent.com/kejilion/nginx/main/nginx_wp.conf && sed -i "s/wp.com/' + domain + '/g" /home/nginx/nginx.conf && sed -i "s/wp.wp.wp.wp:9000/' + redirect + '/g" /home/nginx/nginx.conf') 173 | while not stdout.channel.exit_status_ready(): 174 | if stdout.channel.recv_ready(): 175 | print(stdout.channel.recv(1024).decode(), end="") 176 | 177 | # 检查执行状态 178 | if stderr.channel.recv_exit_status() == 0: 179 | print(f"配置成功") 180 | else: 181 | print(f"配置失败") 182 | 183 | print() 184 | 185 | print(f"{name} 安装nginx") 186 | 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') 187 | while not stdout.channel.exit_status_ready(): 188 | if stdout.channel.recv_ready(): 189 | print(stdout.channel.recv(1024).decode(), end="") 190 | 191 | # 检查执行状态 192 | if stderr.channel.recv_exit_status() == 0: 193 | print(f"安装成功") 194 | else: 195 | print(f"安装失败") 196 | 197 | print() 198 | 199 | print(f"{name} nginx启动状态") 200 | stdin, stdout, stderr = client.exec_command('docker ps -a') 201 | while not stdout.channel.exit_status_ready(): 202 | if stdout.channel.recv_ready(): 203 | print(stdout.channel.recv(1024).decode(), end="") 204 | 205 | print(f"搭建完成\nhttps://{domain}") 206 | print() 207 | print() 208 | 209 | # 关闭 SSH 连接 210 | client.close() 211 | 212 | 213 | except Exception as e: 214 | print(f"连接 {name} 失败") 215 | 216 | 217 | # 遍历服务器列表,逐一更新 218 | for server in servers: 219 | name = server["name"] 220 | hostname = server["hostname"] 221 | port = server["port"] 222 | username = server["username"] 223 | password = server["password"] 224 | domain = server["domain"] 225 | update_server(name, hostname, port, username, password, domain) 226 | 227 | # 等待用户按下任意键后关闭窗口 228 | input("按任意键关闭窗口...") 229 | 230 | 231 | -------------------------------------------------------------------------------- /一键所有VPS部署发卡网站.py: -------------------------------------------------------------------------------- 1 | import paramiko 2 | 3 | servers = [ 4 | 5 | {"name": "美国", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 6 | {"name": "不丹", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 7 | {"name": "毛里求斯", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 8 | # 添加更多服务器 9 | 10 | ] 11 | 12 | # 定义更新操作 13 | def update_server(name, hostname, port, username, password, domain): 14 | try: 15 | 16 | # 连接服务器 17 | client = paramiko.SSHClient() 18 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 19 | client.connect(hostname, port=port, username=username, password=password) 20 | 21 | 22 | print(f" {name} 更新") 23 | stdin, stdout, stderr = client.exec_command("apt update -y && apt install -y curl wget sudo socat") 24 | 25 | print(f"正在更新:") 26 | while not stdout.channel.exit_status_ready(): 27 | if stdout.channel.recv_ready(): 28 | print(stdout.channel.recv(1024).decode(), end="") 29 | 30 | # 检查执行状态 31 | if stderr.channel.recv_exit_status() == 0: 32 | print(f"更新成功") 33 | else: 34 | print(f"更新失败") 35 | 36 | print() 37 | 38 | print(f"{name} 安装 Docker") 39 | stdin, stdout, stderr = client.exec_command("curl -fsSL https://get.docker.com | sh") 40 | 41 | print(f"正在安装 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"安装 Docker 成功") 49 | else: 50 | print(f"安装 Docker 失败") 51 | 52 | print() 53 | 54 | print(f"{name} 安装 Docker Compose") 55 | stdin, stdout, stderr = client.exec_command('curl -L "https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose') 56 | 57 | print(f"正在安装 Docker Compose:") 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"安装 Docker Compose 成功") 65 | else: 66 | print(f"安装 Docker Compose 失败") 67 | 68 | print() 69 | 70 | 71 | print(f"{name} 创建web目录") 72 | stdin, stdout, stderr = client.exec_command("cd /home && mkdir -p web/html web/mysql web/certs web/redis && touch web/nginx.conf web/docker-compose.yml") 73 | 74 | while not stdout.channel.exit_status_ready(): 75 | if stdout.channel.recv_ready(): 76 | print(stdout.channel.recv(1024).decode(), end="") 77 | 78 | # 检查执行状态 79 | if stderr.channel.recv_exit_status() == 0: 80 | print(f"创建目录成功") 81 | else: 82 | print(f"创建目录失败") 83 | 84 | print() 85 | 86 | print(f"{name} 申请证书") 87 | 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)) 88 | print(f"正在申请中:") 89 | while not stdout.channel.exit_status_ready(): 90 | if stdout.channel.recv_ready(): 91 | print(stdout.channel.recv(1024).decode(), end="") 92 | 93 | # 检查执行状态 94 | if stderr.channel.recv_exit_status() == 0: 95 | print(f"申请成功") 96 | else: 97 | print(f"申请失败") 98 | 99 | print() 100 | 101 | print(f"{name} 下载证书") 102 | stdin, stdout, stderr = client.exec_command("~/.acme.sh/acme.sh --installcert -d {} --key-file /home/web/certs/key.pem --fullchain-file /home/web/certs/cert.pem".format(domain)) 103 | while not stdout.channel.exit_status_ready(): 104 | if stdout.channel.recv_ready(): 105 | print(stdout.channel.recv(1024).decode(), end="") 106 | 107 | # 检查执行状态 108 | if stderr.channel.recv_exit_status() == 0: 109 | print(f"下载证书成功") 110 | else: 111 | print(f"下载证书失败") 112 | 113 | print() 114 | 115 | print(f"{name} 配置nginx") 116 | stdin, stdout, stderr = client.exec_command('wget -O /home/web/nginx.conf https://raw.githubusercontent.com/kejilion/nginx/main/nginx7.conf && sed -i "s/yuming.com/' + domain + '/g" /home/web/nginx.conf') 117 | while not stdout.channel.exit_status_ready(): 118 | if stdout.channel.recv_ready(): 119 | print(stdout.channel.recv(1024).decode(), end="") 120 | 121 | # 检查执行状态 122 | if stderr.channel.recv_exit_status() == 0: 123 | print(f"配置成功") 124 | else: 125 | print(f"配置失败") 126 | 127 | print() 128 | 129 | print(f"{name} 配置docker-compose.yml") 130 | stdin, stdout, stderr = client.exec_command('wget -O /home/web/docker-compose.yml https://raw.githubusercontent.com/kejilion/docker/main/LNMP-docker-compose-2.yml') 131 | while not stdout.channel.exit_status_ready(): 132 | if stdout.channel.recv_ready(): 133 | print(stdout.channel.recv(1024).decode(), end="") 134 | 135 | # 检查执行状态 136 | if stderr.channel.recv_exit_status() == 0: 137 | print(f"配置成功") 138 | else: 139 | print(f"配置失败") 140 | 141 | print() 142 | 143 | print(f"{name} 下载网站源码-发卡网站") 144 | stdin, stdout, stderr = client.exec_command('cd /home/web/html && wget https://github.com/assimon/dujiaoka/releases/download/2.0.6/2.0.6-antibody.tar.gz && apt install -y tar && tar -zxvf 2.0.6-antibody.tar.gz && rm 2.0.6-antibody.tar.gz') 145 | while not stdout.channel.exit_status_ready(): 146 | if stdout.channel.recv_ready(): 147 | print(stdout.channel.recv(1024).decode(), end="") 148 | 149 | # 检查执行状态 150 | if stderr.channel.recv_exit_status() == 0: 151 | print(f"配置成功") 152 | else: 153 | print(f"配置失败") 154 | 155 | 156 | print() 157 | 158 | print(f"{name} 启动环境") 159 | stdin, stdout, stderr = client.exec_command('cd /home/web && docker-compose up -d') 160 | print(f"启动中:") 161 | while not stdout.channel.exit_status_ready(): 162 | if stdout.channel.recv_ready(): 163 | print(stdout.channel.recv(1024).decode(), end="") 164 | 165 | # 检查执行状态 166 | if stderr.channel.recv_exit_status() == 0: 167 | print(f"启动成功") 168 | else: 169 | print(f"启动失败") 170 | 171 | print() 172 | 173 | 174 | print(f"{name} 赋予文件权限") 175 | stdin, stdout, stderr = client.exec_command('docker exec nginx chmod -R 777 /var/www/html && docker exec php chmod -R 777 /var/www/html') 176 | while not stdout.channel.exit_status_ready(): 177 | if stdout.channel.recv_ready(): 178 | print(stdout.channel.recv(1024).decode(), end="") 179 | 180 | # 检查执行状态 181 | if stderr.channel.recv_exit_status() == 0: 182 | print(f"赋予成功") 183 | else: 184 | print(f"赋予失败") 185 | 186 | print() 187 | 188 | print(f"{name} 安装PHP依赖") 189 | stdin, stdout, stderr = client.exec_command('docker exec php apt update && docker exec php apt install -y libmariadb-dev-compat libmariadb-dev libzip-dev') 190 | print(f"安装中:") 191 | while not stdout.channel.exit_status_ready(): 192 | if stdout.channel.recv_ready(): 193 | print(stdout.channel.recv(1024).decode(), end="") 194 | 195 | # 检查执行状态 196 | if stderr.channel.recv_exit_status() == 0: 197 | print(f"安装成功") 198 | else: 199 | print(f"安装失败") 200 | 201 | print() 202 | 203 | print(f"{name} 安装PHP扩展") 204 | stdin, stdout, stderr = client.exec_command('docker exec php docker-php-ext-install pdo_mysql zip bcmath && docker exec php pecl install redis && docker exec php sh -c \'echo "extension=redis.so" > /usr/local/etc/php/conf.d/docker-php-ext-redis.ini\' && docker restart php') 205 | print(f"安装中:") 206 | while not stdout.channel.exit_status_ready(): 207 | if stdout.channel.recv_ready(): 208 | print(stdout.channel.recv(1024).decode(), end="") 209 | 210 | # 检查执行状态 211 | if stderr.channel.recv_exit_status() == 0: 212 | print(f"安装成功") 213 | else: 214 | print(f"安装失败") 215 | 216 | print() 217 | 218 | 219 | 220 | 221 | print(f"搭建完成\nhttps://{domain}") 222 | print() 223 | print() 224 | 225 | 226 | print() 227 | print() 228 | 229 | # 关闭 SSH 连接 230 | client.close() 231 | 232 | 233 | except Exception as e: 234 | print(f"连接 {name} 失败") 235 | 236 | 237 | # 遍历服务器列表,逐一更新 238 | for server in servers: 239 | name = server["name"] 240 | hostname = server["hostname"] 241 | port = server["port"] 242 | username = server["username"] 243 | password = server["password"] 244 | domain = server["domain"] 245 | update_server(name, hostname, port, username, password, domain) 246 | 247 | # 等待用户按下任意键后关闭窗口 248 | input("按任意键关闭窗口...") 249 | 250 | 251 | -------------------------------------------------------------------------------- /一键所有VPS部署苹果CMS.py: -------------------------------------------------------------------------------- 1 | import paramiko 2 | 3 | servers = [ 4 | 5 | {"name": "美国", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 6 | {"name": "不丹", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 7 | {"name": "毛里求斯", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456", "domain": "yuming.com"}, 8 | # 添加更多服务器 9 | 10 | ] 11 | 12 | # 定义更新操作 13 | def update_server(name, hostname, port, username, password, domain): 14 | try: 15 | 16 | # 连接服务器 17 | client = paramiko.SSHClient() 18 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 19 | client.connect(hostname, port=port, username=username, password=password) 20 | 21 | 22 | print(f" {name} 更新") 23 | stdin, stdout, stderr = client.exec_command("apt update -y && apt install -y curl wget sudo socat") 24 | while not stdout.channel.exit_status_ready(): 25 | if stdout.channel.recv_ready(): 26 | print(stdout.channel.recv(1024).decode(), end="") 27 | 28 | # 检查执行状态 29 | if stderr.channel.recv_exit_status() == 0: 30 | print(f"更新成功") 31 | else: 32 | print(f"更新失败") 33 | 34 | print() 35 | 36 | print(f"{name} 安装 Docker") 37 | stdin, stdout, stderr = client.exec_command("curl -fsSL https://get.docker.com | sh") 38 | 39 | print(f"正在安装 Docker:") 40 | while not stdout.channel.exit_status_ready(): 41 | if stdout.channel.recv_ready(): 42 | print(stdout.channel.recv(1024).decode(), end="") 43 | 44 | # 检查执行状态 45 | if stderr.channel.recv_exit_status() == 0: 46 | print(f"安装 Docker 成功") 47 | else: 48 | print(f"安装 Docker 失败") 49 | 50 | print() 51 | 52 | print(f"{name} 安装 Docker Compose") 53 | stdin, stdout, stderr = client.exec_command('curl -L "https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose') 54 | 55 | print(f"正在安装 Docker Compose:") 56 | while not stdout.channel.exit_status_ready(): 57 | if stdout.channel.recv_ready(): 58 | print(stdout.channel.recv(1024).decode(), end="") 59 | 60 | # 检查执行状态 61 | if stderr.channel.recv_exit_status() == 0: 62 | print(f"安装 Docker Compose 成功") 63 | else: 64 | print(f"安装 Docker Compose 失败") 65 | 66 | print() 67 | 68 | 69 | print(f"{name} 创建web目录") 70 | stdin, stdout, stderr = client.exec_command("cd /home && mkdir -p web/html web/mysql web/certs && touch web/nginx.conf web/docker-compose.yml") 71 | while not stdout.channel.exit_status_ready(): 72 | if stdout.channel.recv_ready(): 73 | print(stdout.channel.recv(1024).decode(), end="") 74 | 75 | # 检查执行状态 76 | if stderr.channel.recv_exit_status() == 0: 77 | print(f"创建目录成功") 78 | else: 79 | print(f"创建目录失败") 80 | 81 | print() 82 | 83 | print(f"{name} 申请证书") 84 | 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)) 85 | print(f"正在申请中:") 86 | while not stdout.channel.exit_status_ready(): 87 | if stdout.channel.recv_ready(): 88 | print(stdout.channel.recv(1024).decode(), end="") 89 | 90 | # 检查执行状态 91 | if stderr.channel.recv_exit_status() == 0: 92 | print(f"申请成功") 93 | else: 94 | print(f"申请失败") 95 | 96 | print() 97 | 98 | print(f"{name} 下载证书") 99 | stdin, stdout, stderr = client.exec_command("~/.acme.sh/acme.sh --installcert -d {} --key-file /home/web/certs/key.pem --fullchain-file /home/web/certs/cert.pem".format(domain)) 100 | while not stdout.channel.exit_status_ready(): 101 | if stdout.channel.recv_ready(): 102 | print(stdout.channel.recv(1024).decode(), end="") 103 | 104 | # 检查执行状态 105 | if stderr.channel.recv_exit_status() == 0: 106 | print(f"下载证书成功") 107 | else: 108 | print(f"下载证书失败") 109 | 110 | print() 111 | 112 | print(f"{name} 配置nginx") 113 | stdin, stdout, stderr = client.exec_command('wget -O /home/web/nginx.conf https://raw.githubusercontent.com/kejilion/nginx/main/nginx6.conf && sed -i "s/yuming.com/' + domain + '/g" /home/web/nginx.conf') 114 | while not stdout.channel.exit_status_ready(): 115 | if stdout.channel.recv_ready(): 116 | print(stdout.channel.recv(1024).decode(), end="") 117 | 118 | # 检查执行状态 119 | if stderr.channel.recv_exit_status() == 0: 120 | print(f"配置成功") 121 | else: 122 | print(f"配置失败") 123 | 124 | print() 125 | 126 | print(f"{name} 配置docker-compose.yml") 127 | stdin, stdout, stderr = client.exec_command('wget -O /home/web/docker-compose.yml https://raw.githubusercontent.com/kejilion/docker/main/LNMP-docker-compose-1.yml') 128 | while not stdout.channel.exit_status_ready(): 129 | if stdout.channel.recv_ready(): 130 | print(stdout.channel.recv(1024).decode(), end="") 131 | 132 | # 检查执行状态 133 | if stderr.channel.recv_exit_status() == 0: 134 | print(f"配置成功") 135 | else: 136 | print(f"配置失败") 137 | 138 | print() 139 | 140 | print(f"{name} 下载网站源码-苹果CMS") 141 | stdin, stdout, stderr = client.exec_command('cd /home/web && wget https://github.com/magicblack/maccms_down/raw/master/maccms10.zip && sudo apt-get install -y unzip && unzip maccms10.zip -d html && rm maccms10.zip && mv /home/web/html/maccms10-master/* /home/web/html/') 142 | while not stdout.channel.exit_status_ready(): 143 | if stdout.channel.recv_ready(): 144 | print(stdout.channel.recv(1024).decode(), end="") 145 | 146 | # 检查执行状态 147 | if stderr.channel.recv_exit_status() == 0: 148 | print(f"下载成功") 149 | else: 150 | print(f"下载失败") 151 | 152 | print() 153 | 154 | print(f"{name} 下载电影先生2.0模板") 155 | stdin, stdout, stderr = client.exec_command('cd /home/web/html/template/ && wget https://github.com/kejilion/Website_source_code/raw/main/DYXS2.zip && unzip DYXS2.zip && rm /home/web/html/template/DYXS2.zip && cp /home/web/html/template/DYXS2/asset/admin/Dyxs2.php /home/web/html/application/admin/controller && cp /home/web/html/template/DYXS2/asset/admin/dycms.html /home/web/html/application/admin/view/system') 156 | while not stdout.channel.exit_status_ready(): 157 | if stdout.channel.recv_ready(): 158 | print(stdout.channel.recv(1024).decode(), end="") 159 | 160 | # 检查执行状态 161 | if stderr.channel.recv_exit_status() == 0: 162 | print(f"下载成功") 163 | else: 164 | print(f"下载失败") 165 | 166 | print() 167 | 168 | print(f"{name} 修改后台入口文件名为vip.php") 169 | stdin, stdout, stderr = client.exec_command('mv /home/web/html/admin.php /home/web/html/vip.php && wget -O /home/web/html/application/extra/maccms.php https://raw.githubusercontent.com/kejilion/Website_source_code/main/maccms.php') 170 | while not stdout.channel.exit_status_ready(): 171 | if stdout.channel.recv_ready(): 172 | print(stdout.channel.recv(1024).decode(), end="") 173 | 174 | # 检查执行状态 175 | if stderr.channel.recv_exit_status() == 0: 176 | print(f"设置成功") 177 | else: 178 | print(f"设置失败") 179 | 180 | print() 181 | 182 | print(f"{name} 启动环境") 183 | stdin, stdout, stderr = client.exec_command('cd /home/web && docker-compose up -d') 184 | print(f"启动中:") 185 | while not stdout.channel.exit_status_ready(): 186 | if stdout.channel.recv_ready(): 187 | print(stdout.channel.recv(1024).decode(), end="") 188 | 189 | # 检查执行状态 190 | if stderr.channel.recv_exit_status() == 0: 191 | print(f"启动成功") 192 | else: 193 | print(f"启动失败") 194 | 195 | print() 196 | 197 | 198 | print(f"{name} 赋予文件权限") 199 | stdin, stdout, stderr = client.exec_command('docker exec nginx chmod -R 777 /var/www/html && docker exec php chmod -R 777 /var/www/html') 200 | while not stdout.channel.exit_status_ready(): 201 | if stdout.channel.recv_ready(): 202 | print(stdout.channel.recv(1024).decode(), end="") 203 | 204 | # 检查执行状态 205 | if stderr.channel.recv_exit_status() == 0: 206 | print(f"赋予成功") 207 | else: 208 | print(f"赋予失败") 209 | 210 | print() 211 | 212 | print(f"{name} 安装PHP依赖") 213 | stdin, stdout, stderr = client.exec_command('docker exec php apt update && docker exec php apt install -y libmariadb-dev-compat libmariadb-dev libzip-dev && docker exec php docker-php-ext-install pdo_mysql zip && docker restart php') 214 | print(f"安装中:") 215 | while not stdout.channel.exit_status_ready(): 216 | if stdout.channel.recv_ready(): 217 | print(stdout.channel.recv(1024).decode(), end="") 218 | 219 | # 检查执行状态 220 | if stderr.channel.recv_exit_status() == 0: 221 | print(f"安装成功") 222 | else: 223 | print(f"安装失败") 224 | 225 | print() 226 | 227 | print(f"搭建完成\nhttps://{domain}") 228 | print() 229 | print() 230 | 231 | # 关闭 SSH 连接 232 | client.close() 233 | 234 | 235 | except Exception as e: 236 | print(f"连接 {name} 失败") 237 | 238 | 239 | # 遍历服务器列表,逐一更新 240 | for server in servers: 241 | name = server["name"] 242 | hostname = server["hostname"] 243 | port = server["port"] 244 | username = server["username"] 245 | password = server["password"] 246 | domain = server["domain"] 247 | update_server(name, hostname, port, username, password, domain) 248 | 249 | # 等待用户按下任意键后关闭窗口 250 | input("按任意键关闭窗口...") 251 | 252 | 253 | -------------------------------------------------------------------------------- /一键所有VPS重装Debian系统.py: -------------------------------------------------------------------------------- 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 12 -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 | 77 | -------------------------------------------------------------------------------- /一键查看所有VPS资源占用.py: -------------------------------------------------------------------------------- 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 | def get_server_info(name, hostname, port, username, password): 13 | try: 14 | # 连接服务器 15 | client = paramiko.SSHClient() 16 | client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 17 | client.connect(hostname, port=port, username=username, password=password) 18 | 19 | # 获取Debian系统版本 20 | stdin, stdout, stderr = client.exec_command("cat /etc/os-release | grep PRETTY_NAME | awk -F= '{print $2}' | tr -d '\"'") 21 | debian_version = stdout.read().decode().strip() 22 | 23 | # 获取Linux内核版本 24 | stdin, stdout, stderr = client.exec_command("uname -r") 25 | kernel_version = stdout.read().decode().strip() 26 | 27 | # 获取CPU信息 28 | stdin, stdout, stderr = client.exec_command("cat /proc/cpuinfo | grep 'model name' | uniq") 29 | cpu_info = stdout.read().decode().strip() 30 | 31 | # 获取CPU占用量 32 | stdin, stdout, stderr = client.exec_command("top -bn1 | grep 'Cpu(s)' | awk '{print $2 + $4}'") 33 | cpu_usage = stdout.read().decode().strip() + "%" 34 | 35 | # 获取CPU核心数 36 | stdin, stdout, stderr = client.exec_command("nproc") 37 | cpu_cores = stdout.read().decode().strip() 38 | 39 | # 获取内存信息 40 | stdin, stdout, stderr = client.exec_command("free -b | awk 'NR==2{printf \"%.2f/%.2f MB (%.2f%%)\", $3/1024/1024, $2/1024/1024, $3*100/$2 }'") 41 | mem_info = stdout.read().decode().strip() 42 | 43 | # 获取硬盘信息 44 | stdin, stdout, stderr = client.exec_command("df -h | awk '$NF==\"/\"{printf \"%d/%dGB (%s)\", $3,$2,$5}'") 45 | disk_info = stdout.read().decode().strip() 46 | 47 | # 打印服务器信息 48 | print(f"{name} 当前信息:") 49 | print(f"系统版本: {debian_version}") 50 | print(f"Linux版本: {kernel_version}") 51 | print(f"CPU架构: {cpu_info}") 52 | print(f"CPU占用: {cpu_usage}") 53 | print(f"CPU核心数: {cpu_cores}") 54 | print(f"内存占用: {mem_info}") 55 | print(f"硬盘占用: {disk_info}") 56 | 57 | print() 58 | 59 | # 关闭 SSH 连接 60 | client.close() 61 | except Exception as e: 62 | print(f"连接服务器 {name} 失败") 63 | 64 | # 遍历服务器列表,逐一获取信息 65 | for server in servers: 66 | name = server["name"] 67 | hostname = server["hostname"] 68 | port = server["port"] 69 | username = server["username"] 70 | password = server["password"] 71 | get_server_info(name, hostname, port, username, password) 72 | 73 | # 等待用户按下任意键后关闭窗口 74 | input("按任意键关闭窗口...") 75 | --------------------------------------------------------------------------------