自动运维的脚本分析

来源:互联网 发布:武汉理工大学网络教育 编辑:程序博客网 时间:2024/05/29 02:04

发现的脚本

boot_all.sh

下面的脚本完成了两个任务

  • 将脚本执行机器对其他的服务器免登陆
  • 将 install.sh 脚本复制到其他的服务器,并且执行
#!/bin/bashSERVERS="server1 server2"PWD=123BASE_SERVER=server1auto_ssh_copy_id(){    expect -c "set timeout -1;// expect -c 进入 expect 运行环境               spawn ssh-copy-id $1// spawn 是 expect 的内置命令,注意不是 shell 的内置命令               expect { // expect 在这里类似 case when 的语法                   *(yes/no)* {send -- yes\r;exp_continue;} // 返回的字符串中包含(yes/no),则执行{}中的语句                   *assword*  {send -- $2\r;exp_continue;}                   eof        {exit 0;}               }";}ssh_copy_id_to_all(){    for SERVER in SERVERS    do        auto_ssh_copy_id $SERVER $PWD    done}ssh_copy_id_to_allfor SERVER in $SERCERSdo    scp install.sh root@$SERVER:/root/    ssh root@$SERVER /root/install.shdone

install.sh

这个脚本完成了下面任务

  • 下载 zookeeper 的 zip
  • 解压 zip
  • 配置 zookeeper 的环境变量
#!/bin/bashwget zookeeper 的地址tar xzvf zookeeper.tar.gz -C ~/cat >> ~/.bashrc << EOFexport ZOOKEEPER=~/zookeeperexpoer PATH=\$PATH:$ZOOKEEPER/binEOFsource ~/.bashrc