机器需要安装expect
httpd服务需要开启
/etc/hosts 需要配置
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.203.130 test1
192.168.203.131 test2
创建boot.sh
#!/bin/bash
SERVERS="test1 test2"
PASSWORD="123456"
auto_ssh_copy_id() {
expect -c "set timeout -1;
spawn ssh-copy-id $1;
expect {
*(yes/no)* {send -- yes\r;exp_continue;}
*assword:* {send -- $2\r;exp_continue;}
eof {exit 0;}
}";
}
ssh_copy_id_to_all(){
for SERVER in $SERVERS
do
auto_ssh_copy_id $SERVER $PASSWORD
done
}
ssh_copy_id_to_all
for SERVER in $SERVERS
do
scp install.sh root@$SERVER:/root
ssh root@$SERVER /root/install.sh
done
创建文件install.sh
#!/bin/bash
BASE_SERVER=192.168.203.129
yum install -y wet
wget $BASE_SERVER/apps/jdk-linux-x64.tar.gz
tar -zxvf jdk-linux-x64.tar.gz -C /usr/local
cat >> /etc/profile << EOF
export JAVA_HOME=/usr/local/jdk1.8.0_191
exprot PATH=\$PATH:$JAVA_HOME/bin
EOF