温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

【kafka】单节点多broker配置

发布时间:2020-08-05 13:06:08 来源:网络 阅读:2454 作者:君子远小人 栏目:大数据

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

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


2.复制kafka的server.properties文件

cd /usr/local/kafka/config/
cp -a server.properties server1.properties
cp -a server.properties server2.properties

vim 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 on
listeners=PLAINTEXT://:9092
port=9092
# A comma seperated list of directories under which to store log files
log.dirs=/tmp/kafka-logs


vim 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 on
listeners=PLAINTEXT://:9093
port=9093
# A comma seperated list of directories under which to store log files
log.dirs=/tmp/kafka-logs-1

vim 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 on
listeners=PLAINTEXT://:9094
port=9094
# A comma seperated list of directories under which to store log files
log.dirs=/tmp/kafka-logs-2


3.启动3个broker

# Broker1
cd /usr/local/kafka
bin/kafka-server-start.sh config/server.properties &

# Broker2
cd /usr/local/kafka
bin/kafka-server-start.sh config/server1.properties &

# Broker3
cd /usr/local/kafka
bin/kafka-server-start.sh config/server2.properties &

# jps
8274 Jps
8079 Kafka
8145 Kafka
8210 Kafka
2004 QuorumPeerMain


4.创建topic

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

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

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


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

cd /usr/local/kafka
bin/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-beginning

jps
2290 ConsoleConsumer
1974 Kafka
1946 QuorumPeerMain
2042 Kafka
2107 Kafka
2460 Jps
2364 ConsoleProducer
2414 ConsoleProducer
2239 ConsoleProducer





向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI