zookeeper集群/单机搭建
前言
zookeeper模式介绍
zookeeper集群中有三种角色:1、老大Leader(领导者) 2、老二Follower (跟随者) 3、老三Observer(观察者)。 在单机中有一种模式:standlone
zookeeper集群搭建
第一步解压
tar -zxvf /chinaskills/zookeeper-3.4.5.tar.gz -C /opt/module
第二步更改配置
进入zookeeper配置文件目录
cd /opt/module/zookeeper-3.4.5/conf
复制配置文件
cp zoo_sample.cfg zoo.cfg
修改配置及配置介绍
修改dataDir及增加dataLogDir,增加server.x,加粗为具体修改项
# 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/data
dataLogDir=/tmp/zookeeper/log
# the port at which the clients will connect
clientPort=2181
#
# 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.x,端口写没有用的统一一样
server.1=master:2188:3188
server.2=slave1:2188:3188
server.3=slave2:2188:3188
定义集群id
mkdir /tmp/zookeeper/data
vi /tmp/zookeeper/data/myid
然后按照配置的server.x,x就写多少,比如1
其余机器
将zookeeper目录分发下去后,定义集群id
启动
若没有环境变量,在zookeeper目录下bin/命令 zkServer.sh start 需要分别启动,无法统一启动,随后zkServer.sh status查看模式即可,master先启动成为领导者
zookeeper单机搭建
第一步解压
tar -zxvf /chinaskills/zookeeper-3.4.5.tar.gz -C /opt/module
第二步更改配置
进入目录及配置修改
cd /opt/module/zookeeper-3.4.5/conf cp zoo_sample.cfg zoo.cfg 修改dataDir及增加dataLogDir,加粗为具体修改项
# 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/data
dataLogDir=/tmp/zookeeper/log
# the port at which the clients will connect
clientPort=2181
#
# 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目录下bin/命令 zkServer.sh start zkServer.sh status 查看状态,为standlone为成功
微信扫描下方的二维码阅读本文