一. 常用指令\
1. 启动kafka服务
bin/kafka-server-start.sh config/server.properties &
2. 关闭kafka服务
bin/kafka-server-stop.sh
3. 查看主题topics
[root@dn1 bin]#./kafka-topics.sh --list -zookeeper dn1
ATLAS_ENTITIES
ATLAS_HOOK
__consumer_offsets
ambari_kafka_service_check
4. 添加主题topic
[root@dn1 bin]# ./kafka-topics.sh --create --zookeeperdn1:2181,dn2:2181 --replication-factor 1 --partitions 1 --topic test
Created topic "test"
5. 查看topic描述
[root@dn1 bin]# ./kafka-topics.sh--describe --zookeeper localhost:2181 --topic test
Topic:test PartitionCount:1 ReplicationFactor:1 Configs:
Topic: test Partition: 0 Leader: 1001 Replicas: 1001 Isr: 1001
6. 生产者发布消息
[root@dn1 bin]# ./kafka-console-producer.sh --broker-listdn1:6667,dn2:6667 --topic test
OSendMessage 1
Send Message 2
7. 消费者读取消息
[root@dn1bin]# ./kafka-console-consumer.sh --zookeeper dn1:2181,dn2:2181 --topic test--from-beginning
Using theConsoleConsumer with old consumer is deprecated and will be removed in a futuremajor release. Consider using the new consumer by passing [bootstrap-server]instead of [zookeeper].
{metadata.broker.list=dn1.hadoop:6667,request.timeout.ms=30000, client.id=console-consumer-9264,security.protocol=PLAINTEXT}
SendMessage 1
Send Message 2