1 Docker ce安装
rpm 安装命令(下面的包在上述的下载链接中都有)
rpm -ivh containerd.io-1.2.0-3.el7.x86_64.rpm
rpm -ivh docker-ce-cli-18.09.3-3.el7.x86_64.rpm
rpm -ivh docker-ce-18.09.0-3.el7.x86_64.rpm
2 Docker-compose安装
Docker-compose安装就下载对一个的二进制文件,并给下载的二级制文件赋予可执权限,并复制到系统目录下即可,如:/usr/bin目录。
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 docker-compose
cp docker-compose /usr/bin
docker-compose下载地址
3 镜像及对应项目代码下载
kafka依赖zookeeper,因此需要下载zookeeper镜像。本文选择docker hub上start最后的镜像进行试验。
docker pull wurstmeister/zookeeper:latest
docker pull wurstmeister/kafka:latest
git clone git clone https:
- Docker hub上镜像地址。wurstmeister/kafka。
- Github上对应的测试脚本和docker-compose的yml样例文件。wurstmeister/kafka-docker
4 通过docker-compose启动kafka
同主机上启动单节点kafka
修改 kafka-docker项目中的docker-compose-single-broker.yml,修改后内容如下:
version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: 192.168.2.200
KAFKA_CREATE_TOPICS: "test:1:1"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock
启动集群
docker-compose up -d # 默认使用当前目录下的docker-compose.yml文件
docker-compose -f ./kafka-docker/docker-compose-single-broker.yml up -d # 指定使用某得yaml文件。
启动结果如下:
[root@localhost open-source]# docker-compose up -d
Creating open-source_zookeeper_1 ... done
Creating open-source_kafka_1 ... done