便捷高效的搭建zookeeper集群和批量启动脚本

Posted Peter-OK

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了便捷高效的搭建zookeeper集群和批量启动脚本相关的知识,希望对你有一定的参考价值。

便捷高效的搭建zookeeper集群和批量启动脚本

# zookeeper下载和集群安装配置
cd /usr/local/src
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.5.5/apache-zookeeper-3.5.5-bin.tar.gz
tar -zxvf apache-zookeeper-3.5.5-bin.tar.gz -C /usr/local
cd /usr/local/apache-zookeeper-3.5.5-bin

mkdir -p /zkdata/zk1,zk2,zk3

cp conf/zoo_sample.cfg conf/zoo_1.cfg
# vim conf/zoo_1.cfg
    dataDir=/zkdata/zk1
    clientPort=2181

    server.1=127.0.0.1:2888:3888
    server.2=127.0.0.1:2889:3889
    server.3=127.0.0.1:2890:3890

cp conf/zoo_1.cfg conf/zoo_2.cfg
cp conf/zoo_1.cfg conf/zoo_3.cfg

vim conf/zoo_2.cfg
    dataDir=/zkdata/zk2
    clientPort=2182

    server.1=127.0.0.1:2888:3888
    server.2=127.0.0.1:2889:3889
    server.3=127.0.0.1:2890:3890

vim conf/zoo_3.cfg
    dataDir=/zkdata/zk3
    clientPort=2183

    server.1=127.0.0.1:2888:3888
    server.2=127.0.0.1:2889:3889
    server.3=127.0.0.1:2890:3890

echo '1' > /zkdata/zk1/myid
echo '2' > /zkdata/zk2/myid 
echo '3' > /zkdata/zk3/myid 



# 修改启动文件,避免后续出现如下错误
# stat is not executed because it is not in the whitelist.
# envi is not executed because it is not in the whitelist.

# nc命令需要安装其他软件
yum install nmap-ncat

# envi命令执行报错提示:envi is not executed because it is not in the whitelist.
# 解决办法 修改启动指令 zkServer.sh ,往里面添加 :ZOOMAIN="-Dzookeeper.4lw.commands.whitelist=* $ZOOMAIN"
vi apache-zookeeper-3.5.5-bin/bin/zkServer.sh

    else
        echo "JMX disabled by user request" >&2
        ZOOMAIN="org.apache.zookeeper.server.quorum.QuorumPeerMain" # 注意找到这个信息
    fi

# 如果不想添加在这里,注意位置和赋值的顺序
ZOOMAIN="-Dzookeeper.4lw.commands.whitelist=* $ZOOMAIN"

# 然后重启zookeeper



# 集群启动脚本
vim start.sh
    bash bin/zkServer.sh start conf/zoo_1.cfg
    bash bin/zkServer.sh start conf/zoo_2.cfg
    bash bin/zkServer.sh start conf/zoo_3.cfg

# 集群关闭脚本
vim stop.sh
    bash bin/zkServer.sh stop conf/zoo_1.cfg
    bash bin/zkServer.sh stop conf/zoo_2.cfg
    bash bin/zkServer.sh stop conf/zoo_3.cfg

# 执行启动脚本
[root@peter apache-zookeeper-3.5.5-bin]# bash start.sh 
    /bin/java
    ZooKeeper JMX enabled by default
    Using config: conf/zoo_1.cfg
    Starting zookeeper ... STARTED
    /bin/java
    ZooKeeper JMX enabled by default
    Using config: conf/zoo_2.cfg
    Starting zookeeper ... STARTED
    /bin/java
    ZooKeeper JMX enabled by default
    Using config: conf/zoo_3.cfg
    Starting zookeeper ... STARTED




# 检测集群状态
[root@peter apache-zookeeper-3.5.5-bin]# bash bin/zkServer.sh status conf/zoo_1.cfg
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: conf/zoo_1.cfg
    Client port found: 2181. Client address: localhost.
    Mode: follower

[root@peter apache-zookeeper-3.5.5-bin]# bash bin/zkServer.sh status conf/zoo_2.cfg
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: conf/zoo_2.cfg
    Client port found: 2182. Client address: localhost.
    Mode: leader

[root@peter apache-zookeeper-3.5.5-bin]# bash bin/zkServer.sh status conf/zoo_3.cfg
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: conf/zoo_3.cfg
    Client port found: 2183. Client address: localhost.
    Mode: follower

 

以上是关于便捷高效的搭建zookeeper集群和批量启动脚本的主要内容,如果未能解决你的问题,请参考以下文章

便捷高效的搭建Kafka集群和批量启动脚本

便捷高效的搭建Kafka集群和批量启动脚本

使用ZK UI监控管理zookeeper集群

使用ZK UI监控管理zookeeper集群

使用Kafka Eagle监控管理Kafka集群

使用Kafka Eagle监控管理Kafka集群