1、docker-compose
1.首先准备好docker服务
2.下载docker-compose:时间较长
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
3.添加docker-compose执行权限
sudo chmod +x /usr/local/bin/docker-compose
4.验证:docker-compose --version
5.创建zookeeper和kafka单点的docker-compose.yml文件
XML
version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper:latest
ports:
- "2181:2181"
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=0.0.0.0:2888:3888
kafka:
image: wurstmeister/kafka:latest
ports:
- "9092:9092"
expose:
- "9093" # Internal listener, not exposed to host
environment:
KAFKA_ADVERTISED_LISTENERS: INSIDE://kafka:9093,OUTSIDE://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT
KAFKA_LISTENERS: INSIDE://0.0.0.0:9093,OUTSIDE://0.0.0.0:9092
KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
- zookeeper
6.在文件所在目录下运行:docker-compose up -d (注意:-d是后台运行)
7.docker ps查看是否启动成功
8.进入kafka容器:docker exec -it zookeeper-kafka-kafka-1 bash
9.进入kafka脚本目录:/opt/kafka_2.13-2.8.1/bin,注意:对应自己安装的kafka版本,