Zookeeper伪分布式安装

Posted Mr.zhou_Zxy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Zookeeper伪分布式安装相关的知识,希望对你有一定的参考价值。

Zookeeper伪分布式安装

1.预备工作

1.一台服务器
2.伪分布式zookeeper 1,2,3
3.创建zookeeper目录结构
	zoo_1/2/3 用于存放节点的快照
	zoo_2_dataLog 用于存放节点的事务日志
4.将zookeeper的压缩包解压到此处并改名为zookeeper-3.6.3
5.配置环境变量:vim /etc/profile
	添加 export ZK_HOME=/zxy/apps/zookeeper/zookeeper-3.6.3
		export PATH=$PATH:$ZK_HOME/bin
	刷新资源 source /etc/profile

2.分配myid

#server1
echo "1" > /zxy/apps/zookeeper/zoo_1/myid
#server2
echo "2" > /zxy/apps/zookeeper/zoo_1/myid
#server3
echo "3" > /zxy/apps/zookeeper/zoo_1/myid

3.创建不同节点配置文件

[root@hadoop_zxy conf]# cp zoo_sample.cfg zoo1.cfg
[root@hadoop_zxy conf]# cp zoo_sample.cfg zoo2.cfg
[root@hadoop_zxy conf]# cp zoo_sample.cfg zoo3.cfg

[root@hadoop_zxy conf]# ls
configuration.xsl  log4j.properties  zoo1.cfg  zoo2.cfg  zoo3.cfg  zoo_sample.cfg

4.修改配置文件内容

(三个节点的配置文件只有dataDir、dataLogDir、clientPort不同)

vim zoo1.cfg

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/zxy/apps/zookeeper/zoo_1
dataLogDir=/zxy/apps/zookeeper/zoo_1_dataLog
clientPort=2181
server.1=hadoop_zxy:2887:3887
server.2=hadoop_zxy:2888:3888
server.3=hadoop_zxy:2889:3889

vim zoo2.cfg

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/zxy/apps/zookeeper/zoo_2
dataLogDir=/zxy/apps/zookeeper/zoo_2_dataLog
clientPort=2182
server.1=hadoop_zxy:2887:3887
server.2=hadoop_zxy:2888:3888
server.3=hadoop_zxy:2889:3889

vim zoo3.cfg

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/zxy/apps/zookeeper/zoo_3
dataLogDir=/zxy/apps/zookeeper/zoo_3_dataLog
clientPort=2183
server.1=hadoop_zxy:2887:3887
server.2=hadoop_zxy:2888:3888
server.3=hadoop_zxy:2889:3889

5.启动zookeeper

[root@hadoop_zxy zookeeper-3.6.3]#
bin/zkServer.sh start zoo1.cfg
bin/zkServer.sh start zoo2.cfg
bin/zkServer.sh start zoo3.cfg

6.查看进程(zookeeper已正常)

[root@hadoop_zxy zookeeper-3.6.3]# jps
29858 QuorumPeerMain
29715 QuorumPeerMain
19364 Jps
29977 QuorumPeerMain
[root@hadoop_zxy zookeeper-3.6.3]#

7.查看节点的leader和follower(半数原则)


[root@hadoop_zxy zookeeper-3.6.3]# bin/zkServer.sh status conf/zoo1.cfg
ZooKeeper JMX enabled by default
Using config: conf/zoo1.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[root@hadoop_zxy zookeeper-3.6.3]# bin/zkServer.sh status conf/zoo2.cfg
ZooKeeper JMX enabled by default
Using config: conf/zoo2.cfg
Client port found: 2182. Client address: localhost. Client SSL: false.
Mode: leader
[root@hadoop_zxy zookeeper-3.6.3]# bin/zkServer.sh status conf/zoo3.cfg
ZooKeeper JMX enabled by default
Using config: conf/zoo3.cfg
Client port found: 2183. Client address: localhost. Client SSL: false.
Mode: follower

8.使用脚本管理(拓展)

vim start-zookeeper.sh

#!/bin/bash
# filename:start-zookeeper.sh
# autho:zxy
# date:2022-01-12
# KAFKA的安装路径
ZOOKEEPER_HOME=/zxy/apps/zookeeper/zookeeper-3.6.3
# 接受参数
CMD=$1

## 帮助函数
usage() 
    echo "usage:"
    echo "start-zookeeper.sh z1/z2/z3"
    echo "description:"
    echo "      z1:start zoo_1.cfg"
    echo "      z2:start zoo_2.cfg"
    echo "      z3:stop zoo_3.cfg"
    exit 0


if [ $CMD == "z1" ];then
        # 启动zookeeper1服务
        sh $ZOOKEEPER_HOME/bin/zkServer.sh start $ZOOKEEPER_HOME/conf/zoo1.cfg
elif [ $CMD == "z2" ];then
        # 启动zookeeper2服务
        sh $ZOOKEEPER_HOME/bin/zkServer.sh start $ZOOKEEPER_HOME/conf/zoo2.cfg
elif [ $CMD == "z3" ];then
		# 启动zookeeper3服务
        sh $ZOOKEEPER_HOME/bin/zkServer.sh start $ZOOKEEPER_HOME/conf/zoo3.cfg
else
        usage
fi

整个zookeeper打包文件,包含脚本

以上是关于Zookeeper伪分布式安装的主要内容,如果未能解决你的问题,请参考以下文章

zookeeper伪集群安装

zookeeper 伪分布式安装

zookeeper 伪分布安装

ZooKeeper伪分布集群安装及使用 RMI+ZooKeeper实现远程调用框架

ZooKeeper:win7上安装单机及伪分布式安装

zookeeper伪分布安装配置