樹莓派下docker-compose安裝kafka集群 (arm64v8 raspberrypi 64位系統(tǒng))

一.拉取zookeeper, kafka, kafka-manager鏡像
docker pull wyh1791/zookeeper-arm64v8
docker pull wyh1791/kafka-arm64v8 
docker pull wyh1791/kafka-manager-arm64v8:v2
image.png
二.創(chuàng)建必要文件及文件夾
1.建立根文件夾
cd /
mkdir kafka
2.kafka節(jié)點(diǎn)文件夾
cd /kafka
mkdir kafka1
mkdir kafka2
mkdir kafka3
3.zookeeper文件夾
mkdir zookeeper1
mkdir zookeeper2
mkdir zookeeper3
4.zookeeper配置文件
mkdir zooConfig
cd zooConfig
mkdir zoo1
mkdir zoo2
mkdir zoo3
5.在zoo1,zoo2,zoo3中分別創(chuàng)建myid文件讯榕,并寫入分別寫入id數(shù)字越走,如zoo1中的myid中寫入1
echo "1" > ./zoo1/myid
echo "2" > ./zoo2/myid
echo "3" > ./zoo3/myid
6.創(chuàng)建zoo配置文件zoo.cfg
touch zoo.cfg

填寫如下內(nèi)容

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/data
dataLogDir=/datalog
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
autopurge.purgeInterval=1
server.1= zoo1:2888:3888
server.2= zoo2:2888:3888
server.3= zoo3:2888:3888
三.創(chuàng)建網(wǎng)絡(luò)
docker network create --driver bridge --subnet 172.23.0.0/25 --gateway 172.23.0.1  zookeeper_network
四.創(chuàng)建docker-compose.yml文件
cd /kafka
touch docker-compose.yml
填寫內(nèi)容
  • 備注: 暴露在外的地址 必須修改為你的樹莓派ip
version: '2'
services:
  zoo1:
    image: wyh1791/zookeeper-arm64v8
    restart: always # 重啟
    container_name: zoo1
    hostname: zoo1
    ports:
    - "2181:2181"
    volumes:
    - "./zooConfig/zoo.cfg:/conf/zoo.cfg" # 配置
    - "./zookeeper1/data:/data"
    - "./zookeeper1/datalog:/datalog"
    environment:
      ZOO_MY_ID: 1 # id
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
    networks:
      default:
        ipv4_address: 172.23.0.11

  zoo2:
    image: wyh1791/zookeeper-arm64v8
    restart: always
    container_name: zoo2
    hostname: zoo2
    ports:
    - "2182:2181"
    volumes:
    - "./zooConfig/zoo.cfg:/conf/zoo.cfg"
    - "./zookeeper2/data:/data"
    - "./zookeeper2/datalog:/datalog"
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
    networks:
      default:
        ipv4_address: 172.23.0.12

  zoo3:
    image: wyh1791/zookeeper-arm64v8
    restart: always
    container_name: zoo3
    hostname: zoo3
    ports:
    - "2183:2181"
    volumes:
    - "./zooConfig/zoo.cfg:/conf/zoo.cfg"
    - "./zookeeper3/data:/data"
    - "./zookeeper3/datalog:/datalog"
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
    networks:
      default:
        ipv4_address: 172.23.0.13

  kafka1:
    image: wyh1791/kafka-arm64v8 # 鏡像
    restart: always
    container_name: kafka1
    hostname: kafka1
    ports:
    - 9092:9092
    # - 9999:9999
    environment:
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.2.104:9092 # 暴露在外的地址
      KAFKA_ADVERTISED_HOST_NAME: kafka1 #
      KAFKA_HOST_NAME: kafka1
      KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
      KAFKA_ADVERTISED_PORT: 9092 # 暴露在外的端口
      KAFKA_BROKER_ID: 0 #
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
      # JMX_PORT: 9999 # jmx
    volumes:
    - /etc/localtime:/etc/localtime
    - "./kafka1/logs:/kafka"
    links:
    - zoo1
    - zoo2
    - zoo3
    networks:
      default:
        ipv4_address: 172.23.0.14

  kafka2:
    image: wyh1791/kafka-arm64v8
    restart: always
    container_name: kafka2
    hostname: kafka2
    ports:
    - 9093:9092
    # - 9998:9999
    environment:
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.2.104:9093
      KAFKA_ADVERTISED_HOST_NAME: kafka2
      KAFKA_HOST_NAME: kafka2
      KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
      KAFKA_ADVERTISED_PORT: 9093
      KAFKA_BROKER_ID: 1
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
      # JMX_PORT: 9999
    volumes:
    - /etc/localtime:/etc/localtime
    - "./kafka2/logs:/kafka"
    links:
    - zoo1
    - zoo2
    - zoo3
    networks:
      default:
        ipv4_address: 172.23.0.15

  kafka3:
    image: wyh1791/kafka-arm64v8
    restart: always
    container_name: kafka3
    hostname: kafka3
    ports:
    - 9094:9092
    # - 9997:9999
    environment:
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.2.104:9094
      KAFKA_ADVERTISED_HOST_NAME: kafka3
      KAFKA_HOST_NAME: kafka3
      KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
      KAFKA_ADVERTISED_PORT: 9094
      KAFKA_BROKER_ID: 2
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
      # JMX_PORT: 9999
    volumes:
    - /etc/localtime:/etc/localtime
    - "./kafka3/logs:/kafka"
    links:
    - zoo1
    - zoo2
    - zoo3
    networks:
      default:
        ipv4_address: 172.23.0.16

  kafka-manager:
    image: wyh1791/kafka-manager-arm64v8:v2
    restart: always
    container_name: kafka-manager
    hostname: kafka-manager
    ports:
    - 9000:9000
    links:
    - kafka1
    - kafka2
    - kafka3
    - zoo1
    - zoo2
    - zoo3
    environment:
      ZK_HOSTS: zoo1:2181,zoo2:2181,zoo3:2181
      KAFKA_BROKERS: kafka1:9092,kafka2:9093,kafka3:9094
      APPLICATION_SECRET: letmein
      KAFKA_MANAGER_AUTH_ENABLED: "true" # 開啟驗(yàn)證
      KAFKA_MANAGER_USERNAME: "admin" # 用戶名
      KAFKA_MANAGER_PASSWORD: "admin" # 密碼
      KM_ARGS: -Djava.net.preferIPv4Stack=true
    networks:
      default:
        ipv4_address: 172.23.0.10

networks:
  default:
    external:
      name: zookeeper_network

五.啟停集群
1.啟動(dòng)集群
docker-compose up -d
2.停止集群
docker-compose stop
3.單個(gè)節(jié)點(diǎn)停止
docker rm -f zoo1
六.查看zookeeper集群是否正常
docker exec -it zoo1 bash
bin/zkServer.sh status # mode 為leader或follower正常
七.驗(yàn)證集群
1.新建topic
docker exec -it kafka1 bash
cd /opt/kafka/bin/
./kafka-topics.sh --create --zookeeper zoo1:2181 --replication-factor 1 --partitions 3 --topic test001
./kafka-topics.sh --list --zookeeper zoo1:2181
./kafka-topics.sh --list --zookeeper zoo2:2181
./kafka-topics.sh --list --zookeeper zoo3:2181
image.png
2.生產(chǎn)消息
./kafka-console-producer.sh --broker-list kafka1:9092,kafka2:9092,kafka3:9092 --topic test001

image.png
3.消費(fèi)消息
./kafka-console-consumer.sh --bootstrap-server kafka1:9092,kafka2:9092,kafka3:9092 --topic test001

image.png
八.kafka-manager
image.png
九.java工程發(fā)送/消費(fèi)kafka消息

git工程下載地址

image.png

image.png

參考: centos7下docker-compose安裝kafka集群

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末舱呻,一起剝皮案震驚了整個(gè)濱河市览爵,隨后出現(xiàn)的幾起案子惭婿,更是在濱河造成了極大的恐慌,老刑警劉巖怨酝,帶你破解...
    沈念sama閱讀 211,042評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件费薄,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡丁溅,警方通過(guò)查閱死者的電腦和手機(jī)唤蔗,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 89,996評(píng)論 2 384
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)窟赏,“玉大人妓柜,你說(shuō)我怎么就攤上這事⊙那睿” “怎么了棍掐?”我有些...
    開封第一講書人閱讀 156,674評(píng)論 0 345
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)拷况。 經(jīng)常有香客問(wèn)我作煌,道長(zhǎng),這世上最難降的妖魔是什么赚瘦? 我笑而不...
    開封第一講書人閱讀 56,340評(píng)論 1 283
  • 正文 為了忘掉前任粟誓,我火速辦了婚禮,結(jié)果婚禮上起意,老公的妹妹穿的比我還像新娘鹰服。我一直安慰自己,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,404評(píng)論 5 384
  • 文/花漫 我一把揭開白布悲酷。 她就那樣靜靜地躺著套菜,像睡著了一般。 火紅的嫁衣襯著肌膚如雪设易。 梳的紋絲不亂的頭發(fā)上逗柴,一...
    開封第一講書人閱讀 49,749評(píng)論 1 289
  • 那天,我揣著相機(jī)與錄音顿肺,去河邊找鬼戏溺。 笑死,一個(gè)胖子當(dāng)著我的面吹牛挟冠,可吹牛的內(nèi)容都是我干的于购。 我是一名探鬼主播,決...
    沈念sama閱讀 38,902評(píng)論 3 405
  • 文/蒼蘭香墨 我猛地睜開眼知染,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了斑胜?” 一聲冷哼從身側(cè)響起控淡,我...
    開封第一講書人閱讀 37,662評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎止潘,沒(méi)想到半個(gè)月后掺炭,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,110評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡凭戴,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,451評(píng)論 2 325
  • 正文 我和宋清朗相戀三年涧狮,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片么夫。...
    茶點(diǎn)故事閱讀 38,577評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡者冤,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出档痪,到底是詐尸還是另有隱情涉枫,我是刑警寧澤,帶...
    沈念sama閱讀 34,258評(píng)論 4 328
  • 正文 年R本政府宣布腐螟,位于F島的核電站愿汰,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏乐纸。R本人自食惡果不足惜衬廷,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,848評(píng)論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望汽绢。 院中可真熱鬧吗跋,春花似錦、人聲如沸庶喜。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,726評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至秩冈,卻和暖如春本缠,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背入问。 一陣腳步聲響...
    開封第一講書人閱讀 31,952評(píng)論 1 264
  • 我被黑心中介騙來(lái)泰國(guó)打工丹锹, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人芬失。 一個(gè)月前我還...
    沈念sama閱讀 46,271評(píng)論 2 360
  • 正文 我出身青樓楣黍,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親棱烂。 傳聞我的和親對(duì)象是個(gè)殘疾皇子租漂,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,452評(píng)論 2 348