expect 是一个用来与终端交互的一个命令,必须先安装才能使用
yum install expect
yum install expect -y
准备boot.sh
#!/bin/bash
SERVERS="linux2 linux3 linux4"
PASSWORD=miaomiao77!
BASE_SERVER=linux1
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=linux1
yum install -y wget
wget $BASE_SERVER/soft/jdk-7u65-linux-i586.tar.gz
tar -zxvf jdk-7u65-linux-i586.tar.gz -C /usr/local
cat >> /etc/profile << EOF
export JAVA_HOME=/usr/local/jdk1.7.0_65
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
准备一个web服务器,放置jdk安装包
[root@Linux1 ~]# cd /var/www/html/
[root@Linux1 html]# ll
总用量 0
[root@Linux1 html]# mkdir soft
[root@Linux1 html]# cp /root/mxSoftware/jdk-7u65-linux-i586.tar.gz ./soft/
[root@Linux1 html]# cd soft/
[root@Linux1 soft]# ll
总用量 140224
-rw-r--r--. 1 root root 143588167 7月 25 21:41 jdk-7u65-linux-i586.tar.gz
[root@Linux1 soft]#
修改权限,添加执行权限给 install.sh、boot.sh
[root@Linux1 ~]# chmod +x install.sh boot.sh
[root@Linux1 ~]#
执行 boot.sh
[root@Linux2 ~]# ./boot.sh
更新配置
[root@Linux2 ~]# source /etc/profile
linux环境变量配置后报错..-bash: /usr/local/java/jdk1.7.0_55/bin/java: /lib/ld-linux.so.2: bad ELF interpreter
登录root账户
[root@Linux2 ~]# yum install glibc.i686