kafka|KRaft部署集群

实验环境

主机名/IP角色系统
server01/192.168.1.201controllerubuntu22.04
server02/192.168.1.202controllerubuntu22.04
server03/192.168.1.203brokerubuntu22.04
server04/192.168.1.204brokerubuntu22.04

All Nodes

安装kafka

apt install openjdk-11-jre-headless -y
wget https://dlcdn.apache.org/kafka/3.8.0/kafka_2.13-3.8.0.tgz
tar -zxvf kafka_2.13-3.8.0.tgz -C /usr/local/etc

server01

修改配置文件

vim /usr/local/etc/kafka_2.13-3.8.0/config/kraft/server.properties
process.roles=controller
node.id=1
controller.quorum.voters=1@192.168.1.201:9093,2@192.168.1.202:9093
listeners=CONTROLLER://192.168.1.201:9093
controller.listener.names=CONTROLLER
listener.security.protocol.map=CONTROLLER:PLAINTEXT

server02

vim /usr/local/etc/kafka_2.13-3.8.0/config/kraft/server.properties
process.roles=controller
node.id=2
controller.quorum.voters=1@192.168.1.201:9093,2@192.168.1.202:9093
listeners=CONTROLLER://192.168.1.202:9093
controller.listener.names=CONTROLLER
listener.security.protocol.map=CONTROLLER:PLAINTEXT

server03

vim /usr/local/etc/kafka_2.13-3.8.0/config/kraft/server.properties
process.roles=broker
node.id=3
controller.quorum.voters=1@192.168.1.201:9093,2@192.168.1.202:9093
listeners=PLAINTEXT://192.168.1.203:9092
inter.broker.listener.name=PLAINTEXT
controller.listener.names=CONTROLLER
listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT

server04

vim /usr/local/etc/kafka_2.13-3.8.0/config/kraft/server.properties
process.roles=broker
node.id=4
controller.quorum.voters=1@192.168.1.201:9093,2@192.168.1.202:9093
listeners=PLAINTEXT://192.168.1.204:9092
inter.broker.listener.name=PLAINTEXT
controller.listener.names=CONTROLLER
listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT

server01

生成uuid

/usr/local/etc/kafka_2.13-3.8.0/bin/kafka-storage.sh random-uuid
# 这个生成的uuid后面要用在其他节点上
viJ79TulTXaN7yG53fdp7w

All Nodes

初始化集群数据目录

/usr/local/etc/kafka_2.13-3.8.0/bin/kafka-storage.sh format -t viJ79TulTXaN7yG53fdp7w -c /usr/local/etc/kafka_2.13-3.8.0/config/kraft/server.properties
/usr/local/etc/kafka_2.13-3.8.0/bin/kafka-server-start.sh  /usr/local/etc/kafka_2.13-3.8.0/config/kraft/server.properties

检查节点状态

/usr/local/etc/kafka_2.13-3.8.0/bin/kafka-metadata-quorum.sh --bootstrap-server 192.168.1.203:9092 describe --status
/usr/local/etc/kafka_2.13-3.8.0/bin/kafka-metadata-quorum.sh --bootstrap-server 192.168.1.204:9092 describe --status
ClusterId:              viJ79TulTXaN7yG53fdp7w
LeaderId:               1
LeaderEpoch:            2
HighWatermark:          4014
MaxFollowerLag:         0
MaxFollowerLagTimeMs:   0
CurrentVoters:          [1,2]
CurrentObservers:       [3,4]

输出信息表示:

  1. ClusterId:集群的ID
  2. LeaderId:当前的控制器领导者节点的 ID。在这个例子中,领导者节点 ID 是 1
  3. LeaderEpoch:显示当前领导者的任期号。任期号每次选举领导者时都会增加
  4. HighWatermark:表示所有副本已确认的最高位移
  5. MaxFollowerLag:显示最大跟随者的滞后量。这里是 0,表示跟随者与领导者同步
  6. MaxFollowerLagTimeMs:显示最大跟随者滞后的时间(ms)
  7. CurrentVoters:列出当前参与投票的节点 ID
  8. CurrentObservers:列出当前的观察者节点 ID。观察者不会参与投票,仅用于同步数据

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!