自动化部署脚本-jdk和单向配置免密登录

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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值