千家信息网

【kafka】单节点多broker配置

发表于:2024-12-02 作者:千家信息网编辑
千家信息网最后更新 2024年12月02日,1.在进入多个broker设置之前,首先启动ZooKeeper服务器/usr/local/zookeeper/bin/zkServer.sh start2.复制kafka的server.propert
千家信息网最后更新 2024年12月02日【kafka】单节点多broker配置

1.在进入多个broker设置之前,首先启动ZooKeeper服务器

/usr/local/zookeeper/bin/zkServer.sh start


2.复制kafka的server.properties文件

cd /usr/local/kafka/config/cp -a server.properties server1.propertiescp -a server.properties server2.propertiesvim server.properties----------------------# The id of the broker. This must be set to a unique integer for each broker.broker.id=0# The port the socket server listens onlisteners=PLAINTEXT://:9092port=9092# A comma seperated list of directories under which to store log fileslog.dirs=/tmp/kafka-logsvim server1.properties----------------------# The id of the broker. This must be set to a unique integer for each broker.broker.id=1# The port the socket server listens onlisteners=PLAINTEXT://:9093port=9093# A comma seperated list of directories under which to store log fileslog.dirs=/tmp/kafka-logs-1vim server2.properties----------------------# The id of the broker. This must be set to a unique integer for each broker.broker.id=2# The port the socket server listens onlisteners=PLAINTEXT://:9094port=9094# A comma seperated list of directories under which to store log fileslog.dirs=/tmp/kafka-logs-2


3.启动3个broker

# Broker1cd /usr/local/kafkabin/kafka-server-start.sh config/server.properties &# Broker2cd /usr/local/kafkabin/kafka-server-start.sh config/server1.properties &# Broker3cd /usr/local/kafkabin/kafka-server-start.sh config/server2.properties &# jps8274 Jps8079 Kafka8145 Kafka8210 Kafka2004 QuorumPeerMain


4.创建topic

(1)为此topic的复制因子值(replication-factor)指定为3个,因为我们有三个不同的broker运行

(2)如果有两个broker,那么分配的复制因子值也得是2个

cd /usr/local/kafkabin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 -partitions 1 --topic Three


5.检查哪个broker正在侦听当前创建的主题

cd /usr/local/kafkabin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic Three------------Topic: Three       PartitionCount:1        ReplicationFactor:3     Configs:             # 分区摘要信息,topic名,分区数量,复制因子Topic: Three       Partition: 0       Leader: 0  Replicas: 0,1,2    Isr: 0,1,2   # broker 0是领导者------------


6.生产和消费(注意ip和port)

# 生产/usr/local/kafka/bin/kafka-console-producer.sh --broker-list   10.1.44.188:9092 --topic Three/usr/local/kafka/bin/kafka-console-producer.sh --broker-list   10.1.44.188:9093 --topic Three/usr/local/kafka/bin/kafka-console-producer.sh --broker-list   10.1.44.188:9094 --topic Three# 消费/usr/local/kafka/bin/kafka-console-consumer.sh --zookeeper 10.1.44.188:2181 --topic Three --from-beginningjps2290 ConsoleConsumer1974 Kafka1946 QuorumPeerMain2042 Kafka2107 Kafka2460 Jps2364 ConsoleProducer2414 ConsoleProducer2239 ConsoleProducer





0