1 [root@centos7 bin]# ./zkCli.sh -server 192.168.1.18:3001 2 Connecting to 192.168.1.18:3001
5.查看目录情况
1 [zk: 192.168.1.18:3001(CONNECTED) 0] ls / 2 [controller_epoch, controller, brokers, zookeeper, test, admin, isr_change_notification, consumers, config] 3 [zk: 192.168.1.18:3001(CONNECTED) 1]
上面的显示结果中:只有zookeeper是zookeeper原生的,其他都是Kafka创建的
6. 创建一个topic:
1 [root@centos7 bin]# ./kafka-topics.sh --create --zookeeper 192.168.1.18:3001,192.168.1.18:3002,192.168.1.18:3003 --replication-factor 3 --partitions 1 --topic test666 2 Created topic "test666".
7. 查看topic状态:
1 [root@centos7 bin]# ./kafka-topics.sh --describe --zookeeper 192.168.1.18:3001,192.168.1.18:3002,192.168.1.18:3003 --topic test666 2 Topic:test666 PartitionCount:1 ReplicationFactor:3 Configs: 3 Topic: test666 Partition: 0 Leader: 0 Replicas: 0,2,1 Isr: 0,2,1
输出参数解释:
第一行是对所有分区的一个描述,然后每个分区都会对应一行,因为我们只有一个分区所以下面就只加了一行。
Leader:负责处理消息的读和写,Leader是从所有节点中随机选择的。
Replicas:列出了所有的副本节点,不管节点是否在服务中
Isr:是正在服务中的节点
由上可见,此时的leader是0
下文会kill 0,看leader是否更改
8.往test666中发送消息:
1 [root@centos7 bin]# ./kafka-console-producer.sh --broker-list localhost:19092,localhost:19093,localhost:19094 --topic test666 2 hello kafka! 3 hello littleMonster! 4 hello world!
9.接收消息:
1 [root@centos7 bin]# ./kafka-console-consumer.sh --zookeeper 192.168.1.18:3001,192.168.1.18:3002,192.168.1.18:3003 --topic test666 --from-beginning 2 hello kafka! 3 hello littleMonster! 4 hello world!
消息接收成功。
10.找到为0的leader的进程,并杀死
1 [root@centos7 /]# ps -ef | grep ka
1 [root@centos7 /]# kill -9 25285
11.再次查看topic状态:
1 [root@centos7 bin]# ./kafka-topics.sh --describe --zookeeper 192.168.1.18:3001,192.168.1.18:3002,192.168.1.18:3003 --topic test666 2 Topic:test666 PartitionCount:1 ReplicationFactor:3 Configs: 3 Topic: test666 Partition: 0 Leader: 2 Replicas: 0,2,1 Isr: 2,1
由此可见,在Isr(正在服务中的节点)项,0已消失,新选举出的leader是2。
12.再次发送消息
接收消息
消息正常接收,该测试通过。
CentOS 7.2部署Elasticsearch+Kibana+Zookeeper+Kafka