大致的内容就是:zookeeper 和 kafka 伪集群的安装和部署,然后使用监听机制实时读取订阅的消息。
首先是zookeeper伪集群的安装
首先是到官网下载 zookeeper 我使用的是3.4.14的版本。
第一步:建立一个集群安装的目录,就叫zookeeper。其次,在这个目录的下面解压三份ZooKeeper,形成3个节点,每一个目录中的ZooKeeper就代表一个节点。
这样就形成了如下的安装目录结构:
/zookeeper
|----zookeeper1/
|----zookeeper2/
|----zookeeper3/
第二步: 在3个节点目录中分别建立data目录、logs目录和myid文件。
新建目录data:mkdir data
新建目录logs:mkdir logs
新建文件myid:touch data/myid
myid文件的内容是节点在集群中的编号,zookeeper1节点的编号就写成1,后边的zookeeper2的编号是2,zookeeper3的编号就是3。
按照同样的方法,依次在zookeeper2和zookeeper3上都建立以上目录和文件。
第三步:添加配置文件
cd 到 conf 目录下
cp zoo_sample.cfg zoo.cfg 将zoo_sample.cfg 重命名为 zoo.cfg
添加如下的配置文件信息。
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=/kafka/zookeeper/zookeeper1/data
dataLogDir=/kafka/zookeeper/zookeeper1/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=127.0.0.1:8880:7770
server.2=127.0.0.1:8881:7771
server.3=127.0.0.1:8882:7772
针对不同zookeeper 只需要修改 dataDir dataLogDir 目录地址就可以了。
然后如果是要搭建真正的集群 只需要把server1,2,3 后面的地址改为对应的服务IP地址就可以了。
配置文件中配置项的含义:
- tickTime: zookeeper中使用的基本时间单位,毫秒值,比如可以设为1000,那么基本时间单位就是1000ms,也就是1s。
- initLimit: Follower在启动过程中