中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

centos7.6如何安裝docker-zookeeper-kafka

發布時間:2021-11-15 16:29:04 來源:億速云 閱讀:180 作者:小新 欄目:云計算

這篇文章將為大家詳細講解有關centos7.6如何安裝docker-zookeeper-kafka,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

單機方案:

# 安裝zookeeper
docker run -d \
    --name zk \
    -p 12181:2181 \
    -v /etc/localtime:/etc/localtime \
    --restart=always \
    zookeeper

# 安裝kafka
docker run -d \
    --name kafka \
    -p 9092:9092 \
    --link zk:zookeeper \
    -e KAFKA_BROKER_ID=0 \
    -e KAFKA_ZOOKEEPER_CONNECT=zk:2181 \
    -e KAFKA_LISTENERS=PLAINTEXT://:9092 \
    -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.1.100:9092 \
    --restart=always \
    wurstmeister/kafka

# 進入kafka
docker exec -it kafka /bin/bash

# 創建topic
/opt/kafka/bin/kafka-topics.sh --create --zookeeper zk:2181 --replication-factor 1 --partitions 1 --topic my_topic

# 查看topic列表
/opt/kafka/bin/kafka-topics.sh --list --zookeeper zk:2181

# 發送消息
/opt/kafka/bin/kafka-console-producer.sh --broker-list 122.228.113.229:9092 --topic my_topic

# 接受消息
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 122.228.113.229:9092 --topic my_topic --from-beginning

集群方案: 

-- 安裝docker-compose
curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

-- 賦予執行權限
chmod +x /usr/local/bin/docker-compose

-- 拉取鏡像
docker pull zookeeper:3.4
docker pull wurstmeister/kafka

-- 編寫docker-compose.yaml

-- 啟動服務
docker run -d zookeeper

-- 測試zookeeper
telnet 127.0.0.1 12181
docker exec -it zoo1 bash ./bin/zkServer.sh status
docker exec -it zoo2 bash ./bin/zkServer.sh status
docker exec -it zoo3 bash ./bin/zkServer.sh status

-- 測試kafka
telnet 127.0.0.1 19092

-- 鏈接kafka1容器
docker exec -it kafka1 /bin/bash

-- 創建topic
$KAFKA_HOME/bin/kafka-topics.sh --create --topic test --zookeeper zoo1:2181 --replication-factor 1 --partitions 1

-- 查看topic
$KAFKA_HOME/bin/kafka-topics.sh --zookeeper zoo1:2181 --describe --topic test

-- 發布消息
$KAFKA_HOME/bin/kafka-console-producer.sh --topic=test --broker-list kafka1:9092

-- 接收消息
$KAFKA_HOME/bin/kafka-console-consumer.sh --bootstrap-server kafka1:9092 --from-beginning --topic test
mkdir -p /home/docker_zoo_kafka

cat > /home/docker_zoo_kafka/docker-compose.yml <<EOF
version: "2"

services:
    zoo1:
        image: zookeeper:3.4
        container_name: zoo1
        restart: always
        ports:
            - 12181:2181
        environment:
            ZOO_MY_ID: 1
            ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
        volumes:
            - /etc/localtime:/etc/localtime

    zoo2:
        image: zookeeper:3.4
        container_name: zoo2
        restart: always
        ports:
            - 22181:2181
        environment:
            ZOO_MY_ID: 2
            ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
        volumes:
            - /etc/localtime:/etc/localtime

    zoo3:
        image: zookeeper:3.4
        container_name: zoo3
        restart: always
        ports:
            - 32181:2181
        environment:
            ZOO_MY_ID: 3
            ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
        volumes:
            - /etc/localtime:/etc/localtime

    kafka1:
        image: wurstmeister/kafka
        container_name: kafka1
        restart: always
        ports:
            - 19092:9092
        environment:
            KAFKA_HOST_NAME: kafka1
            KAFKA_ADVERTISED_HOST_NAME: kafka1
            KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
            KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://172.19.160.224:19092
            KAFKA_ADVERTISED_PORT: 19092
            KAFKA_BROKER_ID: 0
            KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
        volumes:
            - /etc/localtime:/etc/localtime
        links:
            - zoo1
            - zoo2
            - zoo3

    kafka2:
        image: wurstmeister/kafka
        container_name: kafka2
        restart: always
        ports:
            - 29092:9092
        environment:
            KAFKA_HOST_NAME: kafka2
            KAFKA_ADVERTISED_HOST_NAME: kafka2
            KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
            KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://172.19.160.224:29092
            KAFKA_ADVERTISED_PORT: 29092
            KAFKA_BROKER_ID: 1
            KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
        volumes:
            - /etc/localtime:/etc/localtime
        links:
            - zoo1
            - zoo2
            - zoo3

    kafka3:
        image: wurstmeister/kafka
        container_name: kafka3
        restart: always
        ports:
            - 39092:9092
        environment:
            KAFKA_HOST_NAME: kafka3
            KAFKA_ADVERTISED_HOST_NAME: kafka3
            KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
            KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://172.19.160.224:39092
            KAFKA_ADVERTISED_PORT: 39092
            KAFKA_BROKER_ID: 2
            KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092

        volumes:
            - /etc/localtime:/etc/localtime
        links:
            - zoo1
            - zoo2
            - zoo3
EOF

說明:172.19.160.224是宿主機IP

關于“centos7.6如何安裝docker-zookeeper-kafka”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

乌兰察布市| 应用必备| 桃源县| 太仓市| 温州市| 平山县| 织金县| 荥阳市| 陈巴尔虎旗| 佛坪县| 新民市| 梁河县| 桦甸市| 金乡县| 南宫市| 永春县| 边坝县| 晋宁县| 景东| 阿图什市| 万全县| 肇东市| 孙吴县| 福海县| 杂多县| 马山县| 平顶山市| 瑞金市| 贵溪市| 涿州市| 惠水县| 无为县| 西城区| 云南省| 新巴尔虎左旗| 城步| 浪卡子县| 泾源县| 德昌县| 鄂托克旗| 当阳市|