Zookeeper学习笔记2

本文详细介绍了Zookeeper的安装步骤及单机与集群环境的配置方法。包括从下载到解压,再到配置文件的创建与调整,最后是服务启动与状态检查等关键环节。

环境搭建

JDK(>1.6)安装

Zookeeper安装

1、下载
http://mirror.bit.edu.cn/apache/zookeeper/stable/zookeeper-3.4.10.tar.gz
2、解压

tar -zxvf zookeeper-3.4.10.tar.gz

3、在zookeeper-xx/conf文件夹下面创建配置文件,可直接复制zoo_sample.cfg

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.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181

运行

单机环境

1、配置文件默认zoo.cfg
2、启动服务
1226359-20180327113837774-1545925179.png

3、启动客户端
1226359-20180327113929673-514058819.png
1226359-20180327114100858-1747808571.png

集群环境

搭建集群只需要修改配置文件,添加一个myid的文件
1、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.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
server.1=192.168.2.192:2888:3888
server.2=192.168.2.200:2888:3888
server.3=192.168.2.233:2888:3888

server.server_id=server_ip:port_1:port_2
server_id:服务器编号1~255
server_ip:服务器ip
port_1:flower和leader同步数据的端口
port_2:flower进行leader选举的端口

2、在192.168.2.192机器上添加/tmp/zookeeper/myid
内容为1,
同理,其他机器的zoo.cfg一样,添加对应的myid文件

3、在其中任意台机器中运行

./bin/zkServer.sh status

你将会看到是leader还是flower

JMX enabled by default
Using config: /opt/Java/zookeeper-3.3.6/bin/../conf/zoo.cfg
Mode: leader

如果提示未运行,请查看zookeeper.out找到原因

4、在任一台机器创建节点,其他机器将同步数据

转载于:https://www.cnblogs.com/lanqie/p/8656220.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值