赞
踩
Docker Compose是用于定义和运行多容器 Docker 应用程序的工具。通过 Compose,可以使用 YML 文件来配置应用程序需要的所有服务。然后使用一个命令,就可以从 YML 文件配置中创建并启动所有服务。
从Github上下载
sudo curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)" -o /opt/docker-compose
若网络出现问题,输入下列命令查看下载地址,可在Windows系统中加入科技后下载
echo "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)
为Docker Compose的二进制文件赋予执行权限:
sudo chmod +x /opt/docker-compose
到配置文件中配置环境变量
vim /etc/profile
输入路径
export PATH="/opt:$PATH"
刷新环境变量
source /etc/profile
验证是否安装
docker-compose --version
开启
docker-compose up -d
关闭
docker-compose down
使用docker-compose.yml文件,创建一个包含了一个 ZooKeeper 节点和一个 Kafka 节点的集群
version: '3' services: zookeeper: image: confluentinc/cp-zookeeper:7.1.0 volumes: - /tmp/zookeeper:/var/lib/zookeeper/data - /tmp/zookeeper/logs:/var/lib/zookeeper/logs ports: - "2181:2181" kafka1: image: confluentinc/cp-kafka:7.1.0 volumes: - /tmp/kafka:/var/lib/kafka1/data depends_on: - zookeeper ports: - "9092:9092" environment: KAFKA_BROKER_ID: 1 KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181" KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:9092 KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 kafka2: image: confluentinc/cp-kafka:7.1.0 volumes: - /tmp/kafka:/var/lib/kafka2/data depends_on: - zookeeper ports: - "9093:9092" environment: KAFKA_BROKER_ID: 2 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka2:9092 kafka3: image: confluentinc/cp-kafka:7.1.0 volumes: - /tmp/kafka:/var/lib/kafka3/data depends_on: - zookeeper ports: - "9094:9092" environment: KAFKA_BROKER_ID: 3 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka3:9092
启动kafka集群
docker-compose up -d
关闭集群
docker-compose down
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。