自动分发部署的前提


1、安装expect 软件包,安装方法配置好epel源或者源码安装, 这里推荐 配置好epe 源,实现yum 安装 yum install  expect  -y 


2、生成 ssh 公钥 ssh-keygen

cat fenfa.expect

#!/usr/bin/expect
#date:2017/11/10
Author: http://sdsca.blog.51cto.com/
Usage: sh fenfa.expect ip
set ip [lindex $argv 0 ] 
set password 123.com #远程服务器密码
set timeout 10

cd ~

spawn ssh-copy-id -i .ssh/id_rsa.pub root@$ip  

 expect {

 "*yes/no" { send "yes\r"; exp_continue}      

 "*password:" { send "$password\r" }          

 }

expect "#*"

expect eof

 

分发到多台服务器上面

cat fenfa.sh

#!/bin/bash
#date:2017/11/10
Author:http://sdsca.blog.51cto.com/
Usage: sh fenfa.sh

for ip in 32 ; do #这里可以配置好ip ,进行for 循环
         
     /root/fenfa.expect 192.168.10.$ip
    
done