We know that zookeeper requires each node to start up, and then vote for the master and slave. In practice, this is achieved using automated scripts.
#!/bin/sh
echo "start zkService ..."
for i in 1 2 3
do
ssh mini$i "source /etc/profile;/root/apps/zookeeper-3.4.5/bin/zkServer.sh start"
done
source
The command is used in the above code , because ssh
when the connection is made, the variables in the load are not loaded profile
. Make it JAVA_HOME
not found in the current script process, which will cause the failure of startup.
Similarly, we can also view the status of each server in this way:
#!/bin/sh
echo "show zkService status..."
for i in 1 2 3
do
echo "mini$i :"
ssh mini$i "source /etc/profile;/root/apps/zookeeper-3.4.5/bin/zkServer.sh status"
done