下载
wget 官网
tar -zxvf kafka_2.13-2.5.0.tgz
启动kafka和zookeeper
编写一个sh文件启动
/opt/kafka_2.13-3.0.0/bin/zookeeper-server-start.sh /opt/kafka_2.13-3.0.0/config/zookeeper.properties & sleep 5 /opt/kafka_2.13-3.0.0/bin/kafka-server-start.sh /opt/kafka_2.13-3.0.0/config/server.properties &
创建topic
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic first_topic 输出 #Exception in thread "main" joptsimple.UnrecognizedOptionException: zookeeper is not a recognized option #新版本的kafka,已经不需要依赖zookeeper来创建topic,新版的kafka创建topic bin/kafka-topics.sh --bootstrap-server 127.0.0.1:9092 --topic first_topic --create --replication-factor 1 --partitions 3
创建消费者和生产者
bin/kafka-console-producer.sh --broker-list 127.0.0.1:9092 --topic first_topic 生产 >hello >kafka bin/kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --topic first_topic --from-beginning 消费 hello kafka
查看Topic数量
bin/kafka-topics.sh --bootstrap-server 127.0.0.1:9092 --list 输出: __consumer_offsets first_topic sec_topic
查看topic详情
bin/kafka-topics.sh --bootstrap-server 127.0.0.1:9092 --topic sec_topic --describe 输出: Topic: sec_topic TopicId: qF0PmlMaSrWZZpvc-wv14Q PartitionCount: 3 ReplicationFactor: 1 Configs: segment.bytes=1073741824 Topic: sec_topic Partition: 0 Leader: 0 Replicas: 0 Isr: 0 Topic: sec_topic Partition: 1 Leader: 0 Replicas: 0 Isr: 0 Topic: sec_topic Partition: 2 Leader: 0 Replicas: 0 Isr: 0
查看消费者数量
bin/kafka-consumer-groups.sh --bootstrap-server 127.0.0.1:9092 --list 输出: console-consumer-95968
查看消费者详情
bin/kafka-consumer-groups.sh --bootstrap-server 127.0.0.1:9092 --group console-consumer-95968 --describe 输出,下host为内网ip GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID console-consumer-95968 sec_topic 0 - 1 - consumer-console-consumer-95968-1-388cc30a-19ec-444f-82f1-b172405834b6 /172.17.2.173 consumer-console-consumer-95968-1 console-consumer-95968 sec_topic 1 - 0 - consumer-console-consumer-95968-1-388cc30a-19ec-444f-82f1-b172405834b6 /172.17.2.173 consumer-console-consumer-95968-1 console-consumer-95968 sec_topic 2 - 1 - consumer-console-consumer-95968-1-388cc30a-19ec-444f-82f1-b172405834b6 /172.17.2.173 consumer-console-consumer-95968-1
配置远程访问:
1.配置server.properties
listeners = PLAINTEXT://172.17.2.173:9093(内网ip)
advertised.listeners=PLAINTEXT://121.41.107.235:9093(外网ip)
2.关闭防火墙