zookeeper集群搭建
zookeeper集群搭建
版本: VMware Workstation Pro16.2 hadoop2.7 centos7
1.下载
到apache官网下载对应的zookeeper
2.解压
# tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /opt
3.配置环境变量
# vim /etc/profile
添加环境变量
export ZOOKEEPER_HOME=/opt/zookeeper
export PATH=$ZOOKEEPER_HOME/bin:$PATH
使环境变量生效
# source /etc/profile
4.修改配置
进入安装目录的 conf/
目录下,拷贝配置样本并进行修改:
# cp zoo_sample.cfg zoo.cfg
指定数据存储目录和日志文件目录(目录不用预先创建,程序会自动创建),修改后完整配置如下:
# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/opt/zookeeper-3.5.7/zkData # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 server.1=hadoop01:2888:3888 server.2=hadoop02:2888:3888 server.3=hadoop03:2888:3888
配置参数说明:
- tickTime:用于计算的基础时间单元。比如 session 超时:N*tickTime;
- initLimit:用于集群,允许从节点连接并同步到 master 节点的初始化连接时间,以 tickTime 的倍数来表示;
- syncLimit:用于集群, master 主节点与从节点之间发送消息,请求和应答时间长度(心跳机制);
- dataDir:数据存储位置;
- dataLogDir:日志目录;
- clientPort:用于客户端连接的端口,默认 2181
5.标识节点
分别在三台主机的 dataDir
目录下新建 myid
文件,并写入对应的节点标识。Zookeeper 集群通过 myid
文件识别集群节点,并通过上文配置的节点通信端口和选举端口来进行节点通信,选举出 Leader 节点。
创建存储目录
mkdir /opt/zookeeper-3.5.7/zkData
创建并写入节点标识到 myid
文件:
vim myid
hadoop01中写入:1
hadoop02中写入:2
hadoop03中写入:3
6.启动集群
在三台集群zookeeper的bin/分别启动zookeeper
zkServer.sh start
7.验证集群
启动后使用zkServer.sh status查看集群各个节点。如图hadoop02是leader,hadoop01,hadoop03是follower。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类