栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

给60台服务器装docker

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

给60台服务器装docker

写个一键安装docker的脚本

#! /bin/sh
#
# rsipac_docker.sh
# Copyright (C) 2021 user 
#
# Distributed under terms of the MIT license.
#


curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey | 
apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list | 
 tee /etc/apt/sources.list.d/nvidia-container-runtime.list
apt-get update && apt-get -y install nvidia-container-runtime
cd && wget https://hjr-share.obs.cn-north-4.myhuaweicloud.com/get-docker.sh && sh get-docker.sh --mirror Aliyun && rm get-docker.sh

利用expect去自动执行安装docker的脚本

set host [lindex $argv 0]
# set username [lindex $argv 1]
set password [lindex $argv 2]

# spawn ssh root@$host "nohup sh -c "$(curl -fsSL https://hjr-tmp.obs.cn-north-4.myhuaweicloud.com/rsipac_docker.sh)" > run.log"
spawn ssh root@$host "wget https://hjr-tmp.obs.cn-north-4.myhuaweicloud.com/rsipac_docker.sh && nohup bash rsipac_docker.sh > run.log"
expect "*Are you sure you want to continue connecting (yes/no)?*" {send "yesr"}
expect "*password*" {send "$passwordr"}

interact

spawn scp root@$host:/root/run.log "$host.log"
expect "*password*" {send "$passwordr"}
interact

利用python的多线程去安装

import os
f = open('ip60.txt')
lines = f.readlines()
f.close()
#  for line in lines[2:4]:
#      url = line.strip()
#      print('############################## {} #############################'.format(url))
#      print('############################## url #############################')
#      print('############################## url #############################')
#      print('############################## url #############################')
#      os.system("./rsipac.sh {}".format(url))

def multiprocess_run(process, obj_list):
    # python -c "import multiprocessing; print(multiprocessing.cpu_count())"
    import sys
    from tqdm import tqdm
    from multiprocessing import Pool
    import multiprocessing
    import time
    cpus = multiprocessing.cpu_count()
    pool = Pool(processes=30)
    result_list = []
    tic = time.time()
    for result in tqdm(pool.imap(process, obj_list)):
        result_list.append(result)
        sys.stdout.flush()
    toc = time.time()
    print('time waste', toc - tic)
    return result_list


def process(line):
    url = line.strip()
    print('############################## {} #############################'.format(line))
    #  print('############################## url #############################')
    #  print('############################## url #############################')
    #  print('############################## url #############################')
    #  os.system("./rsipac.sh {}".format(url))
    os.system("nohup ./rsipac.sh {} > {}.fuck.log".format(url, url))
    #  os.system("nohup ./change_data.sh {} > {}.fuck.log".format(url, url))

multiprocess_run(process, lines[30:60])
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/330963.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号