centos7 搭建zookeeper集群

一  前期准备

1、centos7 (物理机或虚拟机 2n+1)
2、jdk环境   配置jdk

二 下载解压zookeeper

1 通过webget命令

 wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.12/zookeeper-3.4.12.tar.gz -p /home

备注:若没有webget命令工具 使用yum install webget进行安装

-p 指定下载目标目录 


2 通过rz命令

rz具体操作


3 解压zookeeper

tar -zxvf /home/zookeeper-3.4.12.tar.gz


4 其他两台虚拟机同样操作 or 使用 scp命令进行服务器间复制文件

三 配置zookeeper节点配置

1 配置host文件,为三个节点配置域名 方便访问(可以不设置 则对应域名使用真实ip)

vi /etc/hosts

在末尾加入 ip 域名 保存退出后生效

192.168.253.6 zk01
192.168.253.4 zk02
192.168.253.3 zk03

2 其他两台同样修改 or 使用 scp命令进行服务器间复制


3 测试网络连接


4 配置节点信息

复制模版文件并取名zoo.cfg

cp /home/zookeeper-3.4.12/conf/zoo_sample.cfg /home/zookeeper-3.4.12/conf/zoo.cfg

修改模版文件如下  需要指定数据保存位置  以及 行末添加节点配置信息

vi /home/zookeeper-3.4.12/conf/zoo.cfg
# The number of milliseconds of each tick       时间单位 2000ms
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take                初识化允许时间单位 10个
initLimit=10
# The number of ticks that can pass between     响应时间允许时间单位 5个
# 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=/home/data/zookeeper
# 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                     zookeeper node配置  service.x = ip:内部通信端口:leader监听端口
server.1=zk01:2888:3888
server.2=zk02:2888:3888
server.3=zk03:2888:3888

备注:在zookeeper安装目录conf内有一个模版文件zoo_sample.cfg 复制并保存为zoo.cfg 生效

        service.x = ip:内部端口:leader端口   x为数据保存路径下myid内容


5 创建数据保存目录以及myid文件

mkdir /home/data/zookeeper
cd /home/data/zookeeper
echo 1>> myid
备注:echo 1 >>myid 译为编写myid文件 内容为1  其中 1与zk01对应    与zoo.cfg 节点配置对应

6  其他虚拟机相同操作 or 使用scp 命令进行文件复制


四 启动集群

1 三台机器启动

/home/zookeeper-3.4.12/bin/zkServer.sh start

2 查看状态

/home/zookeeper-3.4.12/bin/zkServer.sh status


祝你成功

猜你喜欢

转载自blog.csdn.net/qq_22211217/article/details/80542250
今日推荐