给60台服务器装docker

写个一键安装docker的脚本

#! /bin/sh
#
# rsipac_docker.sh
# Copyright (C) 2021 user <user@4029GP-TR>
#
# 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 "yes\r"}
expect "*password*" {send "$password\r"}

interact

spawn scp root@$host:/root/run.log "$host.log"
expect "*password*" {send "$password\r"}
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])
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值