Kafka 集群部署(CentOS 單機模擬版)

0.前置說明

由于我們手里只有一臺Linux機器,所以我們實現的是簡單的單機模擬的集群部署,通過修改配置文件,啟動 3 個 kafka 時用到 3 個不同的端口(9091,9092,9093)。

1.安裝Java11

  1. 切換到你的工作目錄下執行:
yum install java-11-openjdk -y
  1. 添加環境變量;
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.23.0.9-3.tl3.x86_64
export PATH=$PATH:$JAVA_HOME/bin
  1. 讓你的環境變量生效;
source /etc/profile
  1. 測試是否安裝成功;
java -version
openjdk version "11.0.23" 2024-04-16 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.23.0.9-2) (build 11.0.23+9-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.23.0.9-2) (build 11.0.23+9-LTS, mixed mode, sharing)

2.集群部署

  1. 在你的工作目錄下新建目錄 cluster(集群);
mkdir cluster
  1. 進入cluster目錄下,下載 kafka 安裝包 kafka-3.6.1-src.tgz并解壓。
rz -E # 上傳本地安裝包
tar -zxf kafka_2.12-3.6.1.tgz
  1. 改名為 kafka
mv kafka_2.12-3.6.1 kafka

2.1 安裝ZooKeeper

  1. 修改文件夾名為zookeeper

因為 kafka 內置了 ZooKeeper 軟件,所以此處將解壓縮的文件作為 ZooKeeper 軟件使用。

mv kafka/ zookeeper
  1. 修改config/zookeeper.properties文件;
cd zookeeper/
vim config/zookeeper.properties 
  • 修改dataDir,zookeeper 數據的存儲文件。
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
# 
#    http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# the directory where the snapshot is stored.
dataDir=/root/cluster/zookeeper-data/zookeeper
# the port at which the clients will connect
clientPort=2181
# disable the per-ip limit on the number of connections since this is a non-production config
maxClientCnxns=0
# Disable the adminserver by default to avoid port conflicts.
# Set the port to something non-conflicting if choosing to enable this
admin.enableServer=false
# admin.serverPort=8080

2.2 安裝Kafka

  1. 將上面解壓縮的文件復制一份,改名為broke-1
mv kafka_2.12-3.6.1/ broker-1
ll
total 8
drwxr-xr-x 7 root root 4096 Nov 24 17:43 broker-1
drwxr-xr-x 7 root root 4096 Nov 24 17:43 zookeeper
  1. 修改config/server.properties配置文件;
vim broker-1/config/server.properties
############################# Server Basics ############################## The id of the broker. This must be set to a unique integer for each broker.
broker.id=1 # kafka 節點數字標識,集群內具有唯一性
#......############################# Socket Server Settings ############################## The address the socket server listens on. If not configured, the host name will be equal to the value of
# java.net.InetAddress.getCanonicalHostName(), with PLAINTEXT listener name, and port 9092.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://:9091
#.......
############################# Log Basics ############################## A comma separated list of directories under which to store log files
log.dirs=/root/cluster/broker-data/broker-1 # 監聽器 9091 為本地端口,如果沖突,請重新指定
# .......
############################# Zookeeper ############################## Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2181 # 數據文件路徑,如果不存在,會自動創建# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=18000 # ZooKeeper 軟件連接地址,2181 為默認的ZK 端口號 /kafka 為ZK 的管理節點
  1. 同樣的步驟,復制一份broker-2broker-3,并修改配置文件。
# broker-2
############################# Server Basics ############################## The id of the broker. This must be set to a unique integer for each broker.
broker.id=2 # kafka 節點數字標識,集群內具有唯一性
#......############################# Socket Server Settings ############################## The address the socket server listens on. If not configured, the host name will be equal to the value of
# java.net.InetAddress.getCanonicalHostName(), with PLAINTEXT listener name, and port 9092.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://:9092
#.......
############################# Log Basics ############################## A comma separated list of directories under which to store log files
log.dirs=/root/cluster/broker-data/broker-2 # 監聽器 9091 為本地端口,如果沖突,請重新指定
# .......
############################# Zookeeper ############################## Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2181 # 數據文件路徑,如果不存在,會自動創建# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=18000 # ZooKeeper 軟件連接地址,2181 為默認的ZK 端口號 /kafka 為ZK 的管理節點
# broker-3
############################# Server Basics ############################## The id of the broker. This must be set to a unique integer for each broker.
broker.id=3 # kafka 節點數字標識,集群內具有唯一性
#......############################# Socket Server Settings ############################## The address the socket server listens on. If not configured, the host name will be equal to the value of
# java.net.InetAddress.getCanonicalHostName(), with PLAINTEXT listener name, and port 9092.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://:9093
#.......
############################# Log Basics ############################## A comma separated list of directories under which to store log files
log.dirs=/root/cluster/broker-data/broker-3 # 監聽器 9091 為本地端口,如果沖突,請重新指定
# .......
############################# Zookeeper ############################## Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2181 # 數據文件路徑,如果不存在,會自動創建# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=18000 # ZooKeeper 軟件連接地址,2181 為默認的ZK 端口號 /kafka 為ZK 的管理節點

2.3 封裝啟動腳本

因為 Kafka 啟動前,必須先啟動 ZooKeeper,并且Kafka集群中有多個節點需要啟動,所以啟動過程比較繁瑣,這里我們將啟動的指令進行封裝。

  1. zookeeper文件夾下創建zk.sh批處理文件;
cd zookeeper
vim zk.sh## zk.sh
./bin/zookeeper-server-start.sh config/zookeeper.propertieschmod +x zk.sh
  1. broker-1broker-2broker-3文件夾下分別創建kfk.sh批處理文件;
cd broker-1
vim kfk.sh## kfk.sh
./bin/kafka-server-start.sh config/server.propertieschmod +x kfk.sh
  1. cluster文件夾下創建cluster.sh批處理文件,用于啟動 kafka 集群。
vim cluster.sh
# cluster.sh
cd zookeeper
./zk.sh
cd ../broker-1
./kfk.sh
cd ../broker-2
./kfk.sh
cd ../broker-3
./kfk.sh
chmod +x cluster.sh
  1. cluster文件夾下創建cluster-clear.sh批處理文件,用于清理和重置 kafka 數據。
vim cluster-clear.sh# cluster-clear.sh 
rm -rf zookeeper-data
rm -rf broker-datachmod +x cluster-clear.sh 
  1. cluster目錄下,運行./cluster.sh文件即可啟動集群。
# 啟動集群
./cluster# 查看是否啟動成功,如果新建了data文件,說明啟動成功了
ll zookeeper-data/
total 4
drwxr-xr-x 3 root root 4096 May 27 10:20 zookeeperll broker-data/
total 12
drwxr-xr-x 2 root root 4096 May 27 10:21 broker-1
drwxr-xr-x 2 root root 4096 May 27 10:21 broker-2
drwxr-xr-x 2 root root 4096 May 27 10:21 broker-3
  1. 當我們想要關閉集群時,不僅要清理 zookeeper 和 kafka 的數據文件,還有kill -9 結束 zookeeper 進程與 kakfa 進程,這需要我們手動逐一kill
ps axj | grep zookeeper
kill -9 #zookeeper的PIDps axj | grep kafka
kill -9 #3個kafka節點的PID

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/16725.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/16725.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/16725.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

鏈接庫文件體積優化工具篇:bloaty

筆者之前參與過一個嵌入式智能手表項目,曾經碰到過這樣一個問題:手表的flash大小只有2M,這意味著只能在上面燒錄2M大小的代碼。隨著開發不斷進行,代碼越寫越多,編譯出來的bin也越來越大。最后bin大小超過了2M, 就沒法燒…

Vue3+Ant design 實現Select下拉框一鍵全選/清空

最近在做后臺管理系統項目的時候,產品增加了一個讓人非常苦惱的需求,讓在Select選擇器中添加一鍵全選和清空的功能,剛開始聽到的時候真是很懵,他又不讓在外部增加按鈕,其實如果說在外部增加按鈕實現全選或者清空的話&a…

3、python安裝-linux系統下

安裝前置依賴軟件,安裝完成后,打開官網,下載linux系統下的python安裝包: 選擇最新的版本 點擊最新版本,進入版本對應的界面, 選擇第一個進行源碼的編譯,右鍵選擇復制連接地址, 回到終…

HTML+CSS+JS(web前端大作業)~致敬鳥山明簡略版

HTMLCSSJS【動漫網站】網頁設計期末課程大作業 web前端開發技術 web課程設計 文章目錄 一、網站題目 二、網站描述 三、網站介紹 四、網站效果 五、 網站代碼 文章目錄 一、 網站題目 動漫網站-鳥山明-龍珠超 二、 網站描述 頁面分為頁頭、菜單導航欄(最好可下拉&…

CDC 數據實時同步入湖的技術、架構和方案(截至2024年5月的現狀調研)

近期,對 “實時攝取 CDC 數據同步到數據湖” 這一技術主題作了一系列深入的研究和驗證,目前這部分工作已經告一段落,本文把截止目前(2024年5月)的研究結果和重要結論做一下梳理和匯總。為了能給出針對性的技術方案&…

Redis和MySQL的結合方式

Redis和MySQL的結合方式可以多樣化,以滿足不同的應用需求。以下是幾種常見的結合方式,以及它們的特點和適用場景: 緩存數據庫查詢結果: 應用程序首先嘗試從Redis中查詢數據。如果Redis中沒有所需數據,則從MySQL數據庫中…

ESP32-C6接入巴法云,Arduino方式

ESP32-C6接入巴法云,Arduino方式 第一、ESP32-C6開發環境搭建第一步:安裝arduino IDE 軟件第二步:安裝esp32庫第三:arduino 軟件設置 第二:簡單AP配網程序第一步:程序下載第二步:程序使用第三步…

電腦微信群發 500 1000人以上怎么群發,微信營銷群發助手軟件,本人親測,增加十倍業績!!!

今天給大家推薦一款我們目前在使用的電腦群發工具掘金小蜜,不僅可以無限多開,方便你同時管理多個賬號,群發功能更是十分強大,輕松釋放你的雙手。 掘金小蜜(只支持Win7及以上操作系統,沒有推Mac版和手機客戶…

[碼蹄集新手訓練營]MT1016-MT1020

目錄 題號MT1016 寬度與對齊MT1017 左右對齊MT1018 輸入寬度MT1020 %s格式符 題號 MT1016 寬度與對齊 #include<stdio.h> int main() { printf("%-5d %5d\n%-5d %5d\n%-5d %5d",455,455,-123,-123,987654,987654);return 0; }MT1017 左右對齊 #include<s…

Mac | macOs系統安裝Monuty解決外接u盤ntfs讀寫問題

問題 mac電腦的macOs系統無法將文件讀寫入外接u盤或硬盤中&#xff1b; 解決方案 安裝Monuty 官網&#xff1a;mounty官網 下載軟件 安裝其他配置 macbook:~ uwe$ brew install --cask macfuse macbook:~ uwe$ brew install gromgit/fuse/ntfs-3g-mac macbook:~ uwe$ brew…

【Vue】組件用法

【前言】 … 【目標】 1 了解組件間傳參 2 組件間自定義事件綁定與解綁 3 組件的事件總線,消息訂閱與發布的用法 4 組件插槽 一 組件間傳參 #mermaid-svg-CAQFgxRrMK5KRFOr {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#merma…

機頂盒也可以跑量--上機指南

一、背景介紹 隨著科技的進步和智能設備的普及&#xff0c;機頂盒已不再是單純的電視接收器&#xff0c;而是逐漸演變成為家庭娛樂中心。越來越多的機頂盒支持各種應用、游戲和功能&#xff0c;使得用戶可以在大屏幕上享受更多樣化的內容。本指南將帶你深入了解如何讓你的機頂…

Spring中如何配置和使用Properties文件?

在Spring框架中&#xff0c;.properties 文件通常用于存儲配置信息&#xff0c;如數據庫連接、服務地址、應用參數等。以下是配置和使用 Properties 文件的詳細步驟&#xff1a; 1. 創建 Properties 文件 在項目的 src/main/resources 目錄下創建一個 .properties 文件&#…

價格預言機領導者 Pyth 與 Eclipse 平臺集成,為高頻 DeFi 應用提供支持

本篇文章將對這一戰略合作伙伴關系&#xff0c;以及 Pyth 網絡在 Eclipse 生態系統中扮演的關鍵角色進行深入探討。 目前&#xff0c;Pyth 價格數據已正式上線于 Eclipse 測試網。Eclipse 是首個結合了以太坊安全性、Solana 性能和 Celestia DA 的 Solana虛擬機(SVM) Layer2 方…

Key Chain has stopped 是什么

Key Chain has stopped 是一個特定的錯誤消息&#xff0c;通常出現在Android設備上。這個錯誤提示意味著設備上的“Key Chain”服務出現了問題&#xff0c;Key Chain服務在Android中負責管理設備的安全密鑰和證書&#xff0c;包括用戶的隱私密鑰、應用簽名密鑰等。當這個服務意…

無線麥克風哪個牌子性價比高?揭秘領夾麥克風性價比最高品牌

隨著自媒體行業的興起&#xff0c;現在視頻直播或者是個人Vlog都越來越受歡迎了&#xff0c;要想做好內容&#xff0c;除了畫面之外&#xff0c;聲音效果同樣重要。而我們手機上自帶的麥克風&#xff0c;容易受環境影響&#xff0c;特別是在戶外或者拍攝距離較遠時&#xff0c;…

微軟改進WSL子系統 新版將支持鏡像宿主機網絡接口及使用外部DNS

Windows SubSystem for Linux (即 WSL) 是微軟在 Windows 10/11 中開發的子系統功能&#xff0c;該功能允許用戶在 Windows 上安裝 Linux 系統和相關環境&#xff0c;對開發者來說可以構建 Linux 開發環境進行工作。不過 WSL 系統在功能上也有不少缺點&#xff0c;典型的就是默…

【Docker實戰】進入四大數據庫的命令行模式

上一篇我們講了docker exec命令&#xff0c;這一次我們使用docker exec命令來進入四大數據庫的命令行模式。 我們進行游戲開發或軟件開發是離不開四大數據庫的&#xff0c;這四大數據庫分別是關系型數據庫mysql、postgres&#xff0c;nosql數據庫redis、mongodb。將它們容器化…

TopK問題

前言&#xff1a;本篇對TopK問題的解答是介于堆的基礎上講的 TopK問題&#xff1a; 就是在許多數據中找到前K個最大的數據或者最小的數據 比如&#xff1a;專業前10、世界五百強、富豪榜、以及游戲排行榜等等 對于TopK問題&#xff1a;能想到的最簡單直接的方式就是排序解決,…

fastadmin二次開發 修改默認的前端彈出樣式

需要修改fastadmin后臺默認的彈出提示樣式效果&#xff1a; 在項目里搜索這個關鍵詞&#xff1a;Toastr 首先這個文件&#xff0c;里面的success和error就是彈出提示的方法。 public/assets/js/fast.js 然后是下面這個文件&#xff1a; public/assets/js/require-form.js 你…