三台机器构成的Kafka集群
JDK: jdk-8u91-linux-x64.rpm
Zookeeper: zookeeper-3.4.14, 参照:https://my.oschina.net/jerval/blog/3057528
Kafka: kafka_2.12-2.2.0.tgz:http://kafka.apache.org/downloads
或者下载:http://117.136.191.146/cache/mirror.bit.edu.cn/apache/kafka/2.2.0/kafka_2.12-2.2.0.tgz?ich_args2=166-02195429030661_6dae8bb75316a4b07f2d1714978dd909_10001002_9c896125d3c4f7d5913f518939a83798_6e1715581b3d2ef2e259a586b8ab054f
>>安装JDK(三台机器): 参照 https://my.oschina.net/jerval/blog/3051256
>>解压kafka_2.12-2.2.0.tgz(三台机器)
tar -xzf kafka_2.12-2.2.0.tgz -C /usr/local
>>修改文件夹名到kafka(三台机器)
cd /usr/local
mv kafka_2.12-2.2.1 kafka
>>切换到Kafka目录(三台机器)
cd /usr/local/kafka
>>启动Zookeeper, 如果命令无法找到或者Zookeeper集群未安装,请参考https://my.oschina.net/jerval/blog/3057528 安装Zookeeper集群安装(三台机器)
zkServer.sh start
>>建立Kafka kafkalogs文件夹
mkdir /usr/local/kafka/kafkalogs
>>修改Kafka配置(三台机器)
vim /usr/local/kafka/config/server.properties
broker.id=0 #每台上id不一样,如0,1,2
host.name=192.168.31.111 #当前机器IP
log.dirs=/usr/local/kafka/kafkalogs
zookeeper.connect=192.168.31.111:2181,192.168.31.112:2181,192.168.31.113:2181
>>启动Kafka(三台机器)
cd /usr/local/kafka
bin/kafka-server-start.sh config/server.properties
>>创建测试topic(机器一)
cd /usr/local/kafka/
bin/kafka-topics.sh --create --bootstrap-server 192.168.31.111:9092 --replication-factor 2 --partitions 2 --topic test
>>显示所有topics(机器三)
cd /usr/local/kafka/
bin/kafka-topics.sh --list --bootstrap-server 192.168.31.113:9092
>>产生console消息(机器二)
cd /usr/local/kafka/
bin/kafka-console-producer.sh --broker-list 192.168.31.112:9092 --topic test
>>消费console消息(机器一)
bin/kafka-console-consumer.sh --bootstrap-server 192.168.31.111:9092 --topic test --from-beginning
>>显示test topic详情(机器三)
bin/kafka-topics.sh --describe --bootstrap-server 192.168.31.113:9092 --topic test
>>删除topic test,删除时所有的生产者和消费者都必须是与test topic断开的,否则不能成功删除
bin/kafka-topics.sh --delete --bootstrap-server 192.168.31.111:9092 --topic test
#显示当前topic list
bin/kafka-topics.sh --list --bootstrap-server 192.168.31.111:9092
#重新创建相同topic
bin/kafka-topics.sh --create --bootstrap-server 192.168.31.111:9092 --replication-factor 1 --partitions 1 --topic test