在搭建集群的过程中如果每台机器都要手动配置环境变量那简直太难受了,
用shell脚本批量配置最好不过了,先写一个boot.sh1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
SERVERS="192.168.33.61 192.168.33.62 192.168.33.63 192.168.33.64"
PASSWORD=hadoop
BASE_SERVER=192.168.33.64
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_everyone.sh
1 |
|
keepAlived 脚本
#!/bin/bash
while true;
do
A=ps -ef|grep tomcat |wc -l
B=ps -ef|grep keepalived |wc -l
echo $A
if [ $A -eq 1 ];then
echo ‘restart tomcat!!!!’
/usr/local/server/apache-tomcat-6.0.37/bin/startupsss.sh
if [ $A -eq 1 ];then
if [ $B -gt 1 ];then
echo ‘tomcat dead !!!! kill keepalived’
killall keepalived
fi
fi
fi
if [ $A -eq 2 ];then
if [ $B -eq 1 ];then
echo ‘tomcat live !!!! start keepalived’
service keepalived start
fi
fi
sleep 3
done