您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關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”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。