Kafka单节点部署
一. 单节点单broker的部署和使用1. 启动Zookeeper ./zkServer.sh start 或 zookeeper-server-start.sh config/zookeeper.properties2. 启动Kafka kafka-server-start.sh config/server.properties3. 创建topic ...
·
一. 单节点单broker的部署和使用
1. 启动Zookeeper
./zkServer.sh start
或
zookeeper-server-start.sh config/zookeeper.properties
2. 启动Kafka
kafka-server-start.sh config/server.properties
3. 创建topic
kafka-topics.sh --create --zookeeper hadoop000:2181 --replication-factor 1 --partitions 1 --topic hello_test_topic
创建 一个topic 指向zookeeper地址 副本数目为1 1个分区
4. 查看所有topic
kafka-topics.sh --list --zookeeper hadoop000:2181
5. 发送消息
kafka-console-producer.sh --broker-list hadoop000:9092 --topic hello_test_topic
控制台生产者 发送是brokerlist
6. 消费消息
kafka-console-consumer.sh --bootstrap-server localhost:2181 --topic hello_test_topic --from-beginning
kafka-console-consumer.sh --zookeeper localhost:2181 --topic hello_test_topic --from-beginning
--from-beginning 代表从头开始消费,即重启消费者,仍会接收之前的消息
7. 查看所有topic的详细信息:kafka-topics.sh --describe --zookeeper hadoop000:2181
查看指定topic的详细信息:kafka-topics.sh --describe --zookeeper hadoop000:2181 --topic hello_test_topic
-------------------------------------------------------
二. 单节点多broker的部署和使用
1. 复制并修改server.properties文件
> cp config/server.properties config/server-1.properties
> cp config/server.properties config/server-2.properties
> cp config/server.properties config/server-3.properties
config/server-1.properties:
broker.id=1
listeners=PLAINTEXT://:9093
log.dirs=/home/hadoop/app/tmp/kafka-logs-1
config/server-2.properties:
broker.id=2
listeners=PLAINTEXT://:9094
log.dirs=/home/hadoop/app/tmp/kafka-logs-2
config/server-3.properties:
broker.id=3
listeners=PLAINTEXT://:9095
log.dirs=/home/hadoop/app/tmp/kafka-logs-3
2. 启动kafka
kafka-server-start.sh -daemon $KAFKA_HOME/config/server-1.properties &
kafka-server-start.sh -daemon $KAFKA_HOME/config/server-2.properties &
kafka-server-start.sh -daemon $KAFKA_HOME/config/server-3.properties &
3. 创建topic
kafka-topics.sh --create --zookeeper hadoop000:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic-test
一个分区,三个副本
Topic:my-replicated-topic-test PartitionCount:1 ReplicationFactor:3 Configs:
Topic: my-replicated-topic-test Partition: 0 Leader: 0 Replicas: 0,2,3 Isr: 0,2,3
Leader是0号,具有0,2,3 三个副本 Isr:代表活着的
4. 发送消息(一定注意发送消息是broker)
kafka-console-producer.sh --broker-list hadoop000:9093,hadoop000:9094,hadoop000:9095 --topic my-replicated-topic-test
5. 消费消息(一定注意消费消息是zookeeper)
kafka-console-consumer.sh --zookeeper hadoop000:2181 --topic my-replicated-topic-test --from-beginning
更多推荐
已为社区贡献1条内容
所有评论(0)