这篇文章将为大家详细讲解有关centos7.6如何安装docker-zookeeper-kafka,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
开原网站制作公司哪家好,找创新互联公司!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设等网站项目制作,到程序开发,运营维护。创新互联公司从2013年创立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联公司。
单机方案:
# 安装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”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
网页标题:centos7.6如何安装docker-zookeeper-kafka
分享地址:https://www.cdcxhl.com/article24/jhgdje.html
成都网站建设公司_创新互联,为您提供外贸网站建设、静态网站、品牌网站制作、ChatGPT、自适应网站、关键词优化
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联