zookeeper (HA高可用、hbase、kafka)
- 下载
- 上传至服务器解压
cd /opt/modules
tar -zxvf zookeeper-3.4.5-cdh5.3.6
//进入zookeeper 的conf 目录
cd ./zookeeper-3.4.5-cdh5.3.6/conf/
//修改zoo_sample.cfg 为zoo.cfg
mv ./zoo_sample.cfg ./zoo.cfg
//编辑zoo.cfg文件 ,五个参数已经给了默认值了,并修改dataDir为指定目录
vi ./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
#
# 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 为单机模式
参数说明:
- tickTime: zookeeper中使用的基本时间单位, 毫秒值.
- dataDir: 数据目录. 可以是任意目录.
- dataLogDir: log目录, 同样可以是任意目录. 如果没有设置该参数, 将使用和dataDir相同的设置.
- clientPort: 监听client连接的端口号.
- initLimit: zookeeper集群中的包含多台server, 其中一台为leader, 集群中其余的server为follower. initLimit参数配置初始化连接时, follower和leader之间的最长心跳时间. 此时该参数设置为5, 说明时间限制为5倍tickTime, 即5*2000=10000ms=10s.
- syncLimit: 该参数配置leader和follower之间发送消息, 请求和应答的最大时间长度. 此时该参数设置为2, 说明时间限制为2倍tickTime, 即4000ms.
集群模式
配置文件
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.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/opt/modules/zookeeper-3.4.5-cdh5.3.6/zkData
dataLogDir=/opt/modules/zookeeper-3.4.5-cdh5.3.6/logs
# 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.0=hadoop1:2888:3888
server.1=hadoop2:2888:3888
server.2=hadoop3:2888:3888
新增参数
server.X=A:B:C 其中X是一个数字, 表示这是第几号server. A是该server所在的IP地址. B配置该server和集群中的leader交换消息所使用的端口. C配置选举leader时所使用的端口. 如果配置的是伪集群模式, 各个server的B, C参数必须不同.
2. 配置myid文件在dataDir目录下
在之前设置的dataDir中新建myid文件, 写入一个数字, 该数字表示这是第几号server.
该数字必须和zoo.cfg文件中的server.X中的X一一对应.
opt/modules/zookeeper-3.4.5-cdh5.3.6/zkData/myid文件中写入0
opt/modules/zookeeper-3.4.5-cdh5.3.6/zkData/myid文件中写入1
opt/modules/zookeeper-3.4.5-cdh5.3.6/zkData/myid文件中写入2
启动zookeeper进程
//启动zookeeper
./zookeeper-3.4.5-cdh5.3.6/bin/zkServer.sh start
问题:
JMX enabled by default
Using config: /hadoop/zookeeper/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
//全部进程开启后,再查看状态(否则会报上述错误)
./zookeeper-3.4.5-cdh5.3.6/bin/zkServer.sh status
//系统会多出如下进程
jps
17345 QuorumPeerMain
//启动之后
[root@hadoop1 modules]# ./zookeeper-3.4.5-cdh5.3.6/bin/zkServer.sh status
JMX enabled by default
Using config: /opt/modules/zookeeper-3.4.5-cdh5.3.6/bin/../conf/zoo.cfg
Mode: follower
[root@hadoop2 modules]# ./zookeeper-3.4.5-cdh5.3.6/bin/zkServer.sh status
JMX enabled by default
Using config: /opt/modules/zookeeper-3.4.5-cdh5.3.6/bin/../conf/zoo.cfg
Mode: follower
[root@hadoop3 modules]# ./zookeeper-3.4.5-cdh5.3.6/bin/zkServer.sh status
JMX enabled by default
Using config: /opt/modules/zookeeper-3.4.5-cdh5.3.6/bin/../conf/zoo.cfg
Mode: leader