<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
1. 刪除所有dangling資料卷(即無用的Volume,殭屍檔案)
docker volume rm $(docker volume ls -qf dangling=true)
2. 刪除所有dangling映象(即無tag的映象)
docker rmi $(docker images | grep "^<none>" | awk "{print $3}"
3. 刪除所有關閉的容器
docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs docker rm
環境為M1版本的mbp:
1. 新建docker網路
docker network create docker-net --subnet 172.20.10.0/16
docker network ls
2. 叢集規劃
hostname | Ip addr | port | listener |
---|---|---|---|
zook1 | 172.20.10.11 | 2184:2181 | |
zook2 | 172.20.10.12 | 2185:2181 | |
zook3 | 172.20.10.13 | 2186:2181 | |
kafka1 | 172.20.10.14 | 內部9092:9092,外部9192:9192 | kafka1 |
kafka2 | 172.20.10.15 | 內部9093:9093,外部9193:9193 | kafka2 |
Kafka3 | 172.20.10.16 | 內部9094:9094,外部9194:9194 | Kafka3 |
本機(宿主機Mbp) | 172.20.10.2 | ||
kafka manager | 172.20.10.10 | 9000:9000 |
1. 新建檔案zk-docker-compose.yml
version: '3.4' services: zook1: image: zookeeper:latest restart: always hostname: zook1 container_name: zook1 #容器名稱,方便在rancher中顯示有意義的名稱 ports: - 2183:2181 #將本容器的zookeeper預設埠號對映出去 volumes: # 掛載資料卷 - "/Users/konsy/Development/volume/zkcluster/zook1/data:/data" - "/Users/konsy/Development/volume/zkcluster/zook1/datalog:/datalog" - "/Users/konsy/Development/volume/zkcluster/zook1/logs:/logs" environment: ZOO_MY_ID: 1 #即是zookeeper的節點值,也是kafka的brokerid值 ZOO_SERVERS: server.1=zook1:2888:3888;2181 server.2=zook2:2888:3888;2181 server.3=zook3:2888:3888;2181 networks: docker-net: ipv4_address: 172.20.10.11 zook2: image: zookeeper:latest restart: always hostname: zook2 container_name: zook2 #容器名稱,方便在rancher中顯示有意義的名稱 ports: - 2184:2181 #將本容器的zookeeper預設埠號對映出去 volumes: - "/Users/konsy/Development/volume/zkcluster/zook2/data:/data" - "/Users/konsy/Development/volume/zkcluster/zook2/datalog:/datalog" - "/Users/konsy/Development/volume/zkcluster/zook2/logs:/logs" environment: ZOO_MY_ID: 2 #即是zookeeper的節點值,也是kafka的brokerid值 ZOO_SERVERS: server.1=zook1:2888:3888;2181 server.2=zook2:2888:3888;2181 server.3=zook3:2888:3888;2181 networks: docker-net: ipv4_address: 172.20.10.12 zook3: image: zookeeper:latest restart: always hostname: zook3 container_name: zook3 #容器名稱,方便在rancher中顯示有意義的名稱 ports: - 2185:2181 #將本容器的zookeeper預設埠號對映出去 volumes: - "/Users/konsy/Development/volume/zkcluster/zook3/data:/data" - "/Users/konsy/Development/volume/zkcluster/zook3/datalog:/datalog" - "/Users/konsy/Development/volume/zkcluster/zook3/logs:/logs" environment: ZOO_MY_ID: 3 #即是zookeeper的節點值,也是kafka的brokerid值 ZOO_SERVERS: server.1=zook1:2888:3888;2181 server.2=zook2:2888:3888;2181 server.3=zook3:2888:3888;2181 networks: docker-net: ipv4_address: 172.20.10.13 networks: docker-net: external: name: docker-net
2. 執行指令碼部署zookeeper至Docker:
docker compose -f ./zk-docker-compose.yml up -d
1. 新建檔案kafka-docker-compose.yml
version: '2' services: kafka1: image: docker.io/wurstmeister/kafka restart: always hostname: kafka1 container_name: kafka1 ports: - 9093:9093 - 9193:9193 environment: KAFKA_BROKER_ID: 1 KAFKA_LISTENERS: INSIDE://:9093,OUTSIDE://:9193 #KAFKA_ADVERTISED_LISTENERS=INSIDE://<container>:9092,OUTSIDE://<host>:9094 SKAFKA_ADVERTISED_LISTENERS: INSIDE://kafka1:9093,OUTSIDE://localhost:9193 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE KAFKA_ZOOKEEPER_CONNECT: zook1:2181,zook2:2181,zook3:2181 ALLOW_PLAINTEXT_LISTENER : 'yes' JMX_PORT: 9999 #開放JMX監控埠,來監測叢集資料 volumes: - /Users/konsy/Development/volume/kafka/kafka1/wurstmeister/kafka:/wurstmeister/kafka - /Users/konsy/Development/volume/kafka/kafka1/kafka:/kafka external_links: - zook1 - zook2 - zook3 networks: docker-net: ipv4_address: 172.20.10.14 kafka2: image: docker.io/wurstmeister/kafka restart: always hostname: kafka2 container_name: kafka2 ports: - 9094:9094 - 9194:9194 environment: KAFKA_BROKER_ID: 2 KAFKA_LISTENERS: INSIDE://:9094,OUTSIDE://:9194 #KAFKA_ADVERTISED_LISTENERS=INSIDE://<container>:9092,OUTSIDE://<host>:9094 KAFKA_ADVERTISED_LISTENERS: INSIDE://kafka2:9094,OUTSIDE://localhost:9194 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE KAFKA_ZOOKEEPER_CONNECT: zook1:2181,zook2:2181,zook3:2181 ALLOW_PLAINTEXT_LISTENER : 'yes' JMX_PORT: 9999 #開放JMX監控埠,來監測叢集資料 volumes: - /Users/konsy/Development/volume/kafka/kafka2/wurstmeister/kafka:/wurstmeister/kafka - /Users/konsy/Development/volume/kafka/kafka2/kafka:/kafka external_links: - zook1 - zook2 - zook3 networks: docker-net: ipv4_address: 172.20.10.15 kafka3: image: docker.io/wurstmeister/kafka restart: always hostname: kafka3 container_name: kafka3 ports: - 9095:9095 - 9195:9195 environment: KAFKA_BROKER_ID: 3 KAFKA_LISTENERS: INSIDE://:9095,OUTSIDE://:9195 #KAFKA_ADVERTISED_LISTENERS=INSIDE://<container>:9092,OUTSIDE://<host>:9094 KAFKA_ADVERTISED_LISTENERS: INSIDE://kafka3:9095,OUTSIDE://localhost:9195 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE KAFKA_ZOOKEEPER_CONNECT: zook1:2181,zook2:2181,zook3:2181 ALLOW_PLAINTEXT_LISTENER : 'yes' JMX_PORT: 9999 #開放JMX監控埠,來監測叢集資料 volumes: - /Users/konsy/Development/volume/kafka/kafka3/wurstmeister/kafka:/wurstmeister/kafka - /Users/konsy/Development/volume/kafka/kafka3/kafka:/kafka external_links: - zook1 - zook2 - zook3 networks: docker-net: ipv4_address: 172.20.10.16 networks: docker-net: external: name: docker-net
2. 執行指令碼部署kafka至Docker:
docker compose -f ./kafka-docker-compose.yml up -d
3. listeners 和 advertised.listeners
比如說:
listeners: INSIDE://172.17.0.10:9092,OUTSIDE://172.17.0.10:9094 advertised_listeners: INSIDE://172.17.0.10:9092,OUTSIDE://<公網 ip>:埠 kafka_listener_security_protocol_map: "INSIDE:SASL_PLAINTEXT,OUTSIDE:SASL_PLAINTEXT" kafka_inter_broker_listener_name: "INSIDE"
advertised_listeners 監聽器會註冊在 zookeeper 中;
當我們對 172.17.0.10:9092 請求建立連線,kafka 伺服器會通過 zookeeper 中註冊的監聽器,找到 INSIDE 監聽器,然後通過 listeners 中找到對應的 通訊 ip 和 埠;
同理,當我們對 <公網 ip>:埠 請求建立連線,kafka 伺服器會通過 zookeeper 中註冊的監聽器,找到 OUTSIDE 監聽器,然後通過 listeners 中找到對應的 通訊 ip 和 埠 172.17.0.10:9094;
總結:advertised_listeners 是對外暴露的伺服器埠,真正建立連線用的是 listeners。
4.安裝kafka-manager
4.1 新建檔案kafka-manager-docker-compose.yml
version: '2' services: kafka-manager: image: scjtqs/kafka-manager:latest restart: always hostname: kafka-manager container_name: kafka-manager ports: - 9000:9000 external_links: # 連線本compose檔案以外的container - zook1 - zook2 - zook3 - kafka1 - kafka2 - kafka3 environment: ZK_HOSTS: zook1:2181,zook2:2181,zook3:2181 KAFKA_BROKERS: kafka1:9093,kafka2:9094,kafka3:9095 APPLICATION_SECRET: letmein KM_ARGS: -Djava.net.preferIPv4Stack=true networks: docker-net: ipv4_address: 172.20.10.10 networks: docker-net: external: name: docker-net
4.2 執行指令碼部署kafka-manager至Docker:
docker compose -f ./kafka-manager-docker-compose.yml up -d
4.3 設定Cluster
5. 測試kafka
5.1連線容器
進入kafka容器的命令列:
docker exec -ti kafka /bin/bash
進入kafka所在目錄:
cd opt/kafka_2.13-2.8.1/
5.2 建立Replication為2,Partition為2的topic
bin/kafka-topics.sh --create --zookeeper zook1:2181 --replication-factor 2 --partitions 2 --topic partopic
5.3 檢視topic的狀態
在kafka容器中的 opt/kafka_2.12-1.1.0/ 目錄下輸入
bin/kafka-topics.sh --describe --zookeeper zook1:2181 --topic partopic
到此這篇關於docker搭建kafka叢集的方法實現的文章就介紹到這了,更多相關docker搭建kafka叢集內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45