发现的脚本
boot_all.sh
下面的脚本完成了两个任务
- 将脚本执行机器对其他的服务器免登陆
- 将 install.sh 脚本复制到其他的服务器,并且执行
#!/bin/bash
SERVERS="$1"
PWD=123
BASE_SERVER=server1
auto_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_all
for SERVER in $SERCERS
do
scp install.sh root@$SERVER:/root/
ssh root@$SERVER /root/install.sh
done
调用这个脚本例子如下所示:
./boot_all.sh "192.168.1.1 192.168.1.2"
注意:这里的 IP 是使用空格隔开的。
install.sh
这个脚本完成了下面任务
- 下载 zookeeper 的 zip
- 解压 zip
- 配置 zookeeper 的环境变量
#!/bin/bash
wget zookeeper 的地址
tar xzvf zookeeper.tar.gz -C ~/
cat >> ~/.bashrc << EOF
export ZOOKEEPER=~/zookeeper
expoer PATH=\$PATH:$ZOOKEEPER/bin
EOF
source ~/.bashrc