【zookeeper】linux中編寫腳本批量啓動zookeeper

實現功能:一鍵啓動、關閉主從端3個節點上的zookeeper,附加查看啓動狀態java

mkdir bin --新建文件夾
cd bin 跳轉到bin文件夾裏
touch  zookeeperstart.sh --新建一鍵啓動文件
touch  zookeeperstop.sh --新建一鍵中止文件

zookeeperstart.sh添加內容:linux

#!/bin/bash
ZOOKEEPER_HOME=/home/hadoop/apache-zookeeper-3.5.5
 
if [ $ZOOKEEPER_HOME != ""  ]; then
        ZOOCFG=$ZOOKEEPER_HOME/conf/zoo.cfg
        for s in 01 02 03 --循環啓動
                do
                        echo "INFO:starting zookeeper on ${s}"
                        ssh hadoop$s "source /etc/profile;$ZOOKEEPER_HOME/bin/zkServer.sh start" --利用ssh登錄對應的節點,執行當前對應啓動命令
                        if [ $? != 0 ];
                                then
                                echo "Can not starting zookeeper server on host $s}"
                                exit 1
                        fi
                done
        for s in 01 02 03 --循環查看zookeeper狀態
                do
                        echo "INFO:starting zookeeper on ${s}"
                        ssh hadoop$s "source /etc/profile;$ZOOKEEPER_HOME/bin/zkServer.sh status" --顯示各節點zookeeper的啓動狀態
                        if [ $? != 0 ];
                                then
                                echo "Can not starting zookeeper server on host $s}"
                                exit 1
                        fi
                done
fi

 



zookeeperstopsh添加內容:apache

#!/bin/bash
ZOOKEEPER_HOME=/home/hadoop/apache-zookeeper-3.5.5
if [ $ZOOKEEPER_HOME != ""  ]; then
        ZOOCFG=$ZOOKEEPER_HOME/conf/zoo.cfg
        for s in 01 02 03
                do
                        echo "INFO:starting zookeeper on ${s}"
                        ssh hadoop$s "source /etc/profile;$ZOOKEEPER_HOME/bin/zkServer.sh stop"
                        if [ $? != 0 ];
                                then
                                echo "Can not starting zookeeper server on host $s}"
                                exit 1
                        fi
                done
fi


啓動腳本:bash

sh zookeeperstart.sh
sh zookeeperstop.sh

 

例:以個人linux虛擬機上配置zookeeper爲例ssh

[hadoop@hadoop01 bin]$ sh zookeeperstop.sh
INFO:starting zookeeper on 01
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
INFO:starting zookeeper on 02
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
INFO:starting zookeeper on 03
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[hadoop@hadoop01 bin]$ sh zookeeperstart.sh
INFO:starting zookeeper on 01
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
INFO:starting zookeeper on 02
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
INFO:starting zookeeper on 03
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
INFO:starting zookeeper on 01
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
INFO:starting zookeeper on 02
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
INFO:starting zookeeper on 03
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower

最後,咱們能夠看見,系統給出的信息代表,有兩個follower,一個leader,這是zookeeper的工做原理oop

相關文章
相關標籤/搜索