ZooKeeper:搭建伪分布式集群

因为自己的笔记本性能很一般,所以搭建的伪分布式集群来学习一下ZooKeeper。

1.环境:ubuntu-16.04.4-server-amd64 + zookeeper-3.4.10

2.官网下载zookeeper:我下载的是:zookeeper-3.4.10.tar

https://archive.apache.org/dist/zookeeper/

3.在/usr目录下新建soft目录,并将下载的压缩包放入,解压:

tar -xzvf zookeeper-3.4.10.tar

4.进入zookeeper-3.4.10,新建data和logs两个文件夹,并在data文件夹中新建文件myid,文件中的内容写1.

# 新建data文件夹
mkdir data
# 新建logs文件夹
mkdir logs
# 新建文件myid
vi myid

5.进入到zookeeper-3.4.10/conf/目录下,根据模板复制一份zoo.cfg文件

cp zoo_sample.cfg zoo.cfg

6.原始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=/tmp/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

修改为:

# 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=/usr/soft/zookeeper-3.4.10/data
dataLogs=/usr/soft/zookeeper-3.4.10/logs
# 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=localhost:2881:3881
server.2=localhost:2882:3882
server.3=localhost:2883:3883

7.将配置好的zookeeper-3.4.10文件夹重命令为zookeeper1,再复制出两份:zookeeper2,zookeeper3.(这个也可以不用全部复制,配置文件复制一下,启动的时候指定配置文件也行)【伪分布模式下,三个节点的客户端的端口号必须不同,毕竟一个端口号只有一个进程】

1)zookeeper1:zoo.cfg文件中的配置的路径:

dataDir=/usr/soft/zookeeper1/data
dataLogs=/usr/soft/zookeeper1/logs

2)zookeeper2:

①修改zoo.cfg文件中的配置的路径:

dataDir=/usr/soft/zookeeper2/data
dataLogs=/usr/soft/zookeeper2/logs
修改zoo.cfg客户端的端口号:
clientPort=2182

③修改myid,将1设置成2

2)zookeeper3:

①修改zoo.cfg文件中的配置的路径:

dataDir=/usr/soft/zookeeper3/data
dataLogs=/usr/soft/zookeeper3/logs
②修改zoo.cfg客户端的端口号:
clientPort=2183
③修改myid,将1设置成3

8.分别切换到zookeeper1/bin,zookeeper2/bin,zookeeper3/bin,执行:

./zkServer.sh start

启动zookeeper集群




9.分别查看每个节点的状态




10.到此为止,肯定是装成功了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值