kafka版本: kafka_2.12-2.8.0
1.解压
[root@node1 software]# tar -zxf kafka_2.12-2.8.0.tgz -C /opt/module/
2.修改环境变量
[root@node1 software]# vim /etc/profile
3.修改文件名
[root@node1 module]# mv kafka_2.12-2.8.0/ kafka212
4.进入config文件夹,修改server.properties文件
[root@node1 config]# vim ./server.properties
21 broker.id=0
36 advertised.listeners=PLAINTEXT://192.168.153.136:9092
60 log.dirs=/opt/module/kafka212/kfkdata
103 log.retention.hours=1680
123 zookeeper.connect=192.168.153.136:2181,192.168.153.137:2181,192.168.153.138:2181
127 delete.topic.enable=true
5.在Kafka212文件夹下创建kfkdata文件夹
[root@node1 kafka212]# mkdir kfkdata
6.分发Kafka和profile文件
[root@node1 kafka212]# scp -r /opt/module/kafka212/ root@node2:/opt/module/
[root@node1 kafka212]# scp -r /opt/module/kafka212/ root@node3:/opt/module/
[root@node1 kafka212]# scp /etc/profile root@node2:/etc/profile
[root@node1 kafka212]# scp /etc/profile root@node3:/etc/profile
7.[root@node1 kafka212]# source /etc/profile
8.启动zookeeper服务
zkServer.sh start
9.启动Kafka服务
nohup kafka-server-start.sh /opt/module/kafka212/config/server.properties &
10.创建topic
kafka-topics.sh --create --zookeeper 192.168.153.136:2181, 192.168.153.137:2181, 192.168.153.138:2181 --topic njzb --partitions 3 –replication-factor 3
11.查看指定topic的详细信息
kafka-topics.sh --zookeeper 192.168.153.136:2181, 192.168.153.137:2181, 192.168.153.138:2181 --topic njzb
12.查看topic的offset(偏移量)
kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list 192.168.153.136:9092 --topic njzb
13.通过控制台发送消息
kafka-console-producer.sh --bootstrap-server 192.168.153.136:9092 --topic njzb
14.通过控制台订阅并接收消息
kafka-console-consumer.sh --bootstrap-server 192.168.153.138:9092 --topic njzb