不知道zookeeper是什么的,可以先查查资料,因为搭storm集群,需要zookeeper集群,所以就顺手搭一个。废话少说,直接上手配置集群。
1.准备环境
三台机器 系统是centos
172.17.0.2/172.17.0.3/172.17.0.4
安装好了jdk 配置好环境变量JAVA_HOME
2.下载zookeeper
用国内的镜像下载会快些,我用的是清华的镜像站点:
https://mirror.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gz
3.解压
tar -xvf zookeeper-3.4.8.tar.gz
4.修改默认配置文件
假设在172.17.0.2上操作
进入zookeepr的目录,默认会使用conf目录下的zoo.cfg ,这个文件默认不存,需要把conf下面的zoo_sample.cfg拷贝一份叫zoo.cfg
用vi打开conf下的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=/root/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=1i
# 这里默认没有,需要手动添加
# host:port:port 主机名:follower与leader的通信端口号:leader宕了重新选举的端口号
server.1=hadoop01:2888:3888
server.2=hadoop02:2888:3888
server.3=hadoop03:2888:3888
特别需要注意一点:
server.1 server.2 server.3 这三个配置中,server后面的数字需要和每个zookeeper的id对应,zookeeper的id通过,dataDir目录下的myid文件中指定(文件默认不存在,要新建),这里myid里面只需要写入数字1,其他两台机器分别写入2和3.
5.分发安装包
把这个配置好的zookeeper分发给另外两台机器:
scp -r zoopker-3.4.8 root@172.17.0.3:~
scp -r zoopker-3.4.8 root@172.17.0.4:~
注意修改dataDir里面的myid文件中的值。
6.启动
在三台机器上都运行下面的命令,选一个就行了。
# 不指定配置文件 默认使用conf/zoo.cfg bin/zkServer.sh start
# 指定配置文件 bin/zkServer.sh start conf/zoo.cfg
7.观察集群状态
bin/zkServer.sh status
有两个节点是follower,一个leader
8.连接zookeeper集群
# 默认连接localhost:2181 bin/zkCli.sh
或者
# 指定连接的主机和端口 bin/zkCli.sh -server 127.0.0.1:2181
进入到zookeeper的shell里面:输入help就可以看到支持的命令了。
删除刚创建的znode。
rmr /zookeeper/zoo