美文网首页
03_自动部署的脚本

03_自动部署的脚本

作者: 对方不想理你并向你抛出一个异常 | 来源:发表于2017-08-15 00:41 被阅读0次

自动下载安装java

  • boot.sh:配置SSH远程免密登录,并将install.sh拷贝到远程主机执行
#!/bin/bash

SERVERS="mini3"
PASSWORD=huachao
BASE_SERVER=mini

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;}
            *(yes/no)* {send -- yes\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:下载解压jdk-7u45-linux-x64.tar.gz,并配置java环境变量
#!/bin/bash

BASE_SERVER=mini1
yum install -y wget
wget $BASE_SERVER/soft/jdk-7u45-linux-x64.tar.gz
tar -zxvf jdk-7u45-linux-x64.tar.gz -C /usr/local
cat >> /etc/profile << EOF
export JAVA_HOME=/usr/local/jdk1.7.0_45
export PATH=\$PATH:\$JAVA_HOME/bin
EOF

~

执行上面脚本的环境和条件

  • 在主机和每一台从机上安装expect
    yum -y install expect
  • 在主机和每一台从机上安装ssh_client(scp命令依赖ssh客户端)
    yum -y install openssh-clients.x86_64
  • 在主机上要先生成ssh的key
    ssh-keygen

问题

  • 问题1:expect:command not found
    解决:yum -y install expect
  • 问题2: WARNING: POSSIBLE DNS SPOOFING DETECTED!
    出现这种问题可以是因为之前使用过命令ssh-copy-id对要远程连接的主机,现在该主机的IP发生了变化
    解决: vi /root/.ssh/known_hosts, 删除掉那个主机对应的公钥,保存退出再连接就可以了
  • 问题3:spawn ssh-copy-id mini1
    /usr/bin/ssh-copy-id: ERROR: No identities found
    未生成ssh的key
    解决:在主机上执行:ssh-keygen

相关文章

网友评论

      本文标题:03_自动部署的脚本

      本文链接:https://www.haomeiwen.com/subject/pxaprxtx.html