集群规划
我们准备部署6个容器,分别安装3个zookeeper和3个Kafka,总共6个服务下表为各个服务的IP和端口映射
安装Docker的服务编排工具
1.运行以下命令以下载Docker Compose的当前稳定版本:
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
复制代码
2.将可执行权限应用于二进制文件:
sudo chmod +x /usr/local/bin/docker-compose
复制代码
3.测试安装
docker-compose --version
复制代码
官网安装地址:docs.docker.com/compose/ins…
创建网络
docker network create --subnet=172.20.0.0/24 br17219
复制代码
拉取镜像(建议网络不好的同学先拉起镜像)
docker pull wurstmeister/zookeeper
dcoker pull wurstmeister/kafka
docker pull sheepkiller/kafka-manager:latest
复制代码
通过 docker ps 查看已经拉起的镜像
编写docker-compose
1.新建一个 docker-compose.yml
vim docker-compose.yml
复制代码
编写服务编排脚本
version: '2'
services:
zoo1:
image: wurstmeister/zookeeper
restart: always
hostname: zoo1
container_name: zoo1
ports:
- 2184:2181
volumes:
- "/root/zk/zoo1/data:/data"
- "/root/zk/zoo1/datalog:/datalog"
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=0.0.0.0:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
networks:
br17219:
ipv4_address: 172.20.0.11
zoo2:
image: wurstmeister/zookeeper
restart: always
hostname: zoo2
container_name: zoo2
ports:
- 2185:2181
volumes:
- "/root/zk/zoo2/data:/data"
- "/root/zk/zoo2/datalog:/datalog"
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=0.0.0.0:2888:3888 server.3=zoo3:2888:3888
networks:
br17219:
ipv4_address: 172.20.0.12
zoo3:
image: wurstmeister/zookeeper
restart: always
hostname: zoo3
container_name: zoo3
ports:
- 2186:2181
volumes:
- "/root/zk/zoo3/data:/data"
- "/root/zk/zoo3/datalog:/datalog"
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=0.0.0.0:2888:3888
networks:
br17219:
ipv4_address: 172.20.0.13
kafka1:
image: wurstmeister/kafka
restart: always
hostname: kafka1
container_name: kafka1
ports:
- 9092:9092
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka1
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka1:9092
KAFKA_LISTENERS: PLAINTEXT://kafka1:9092
volumes:
- /root/kafka/kafka1/logs:/kafka
external_links:
- zoo1
- zoo2
- zoo3
networks:
br17219:
ipv4_address: 172.20.0.14
kafka2:
image: wurstmeister/kafka
restart: always
hostname: kafka2
container_name: kafka2
ports:
- 9093:9093
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka2
KAFKA_ADVERTISED_PORT: 9093
KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka2:9093
KAFKA_LISTENERS: PLAINTEXT://kafka2:9093
volumes:
- /root/kafka/kafka2/logs:/kafka
external_links:
- zoo1
- zoo2
- zoo3
networks:
br17219:
ipv4_address: 172.20.0.15
kafka3:
image: wurstmeister/kafka
restart: always
hostname: kafka3
container_name: kafka3
ports:
- 9094:9094
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka3
KAFKA_ADVERTISED_PORT: 9094
KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka3:9094
KAFKA_LISTENERS: PLAINTEXT://kafka3:9094
volumes:
- /root/kafka/kafka3/logs:/kafka
external_links:
- zoo1
- zoo2
- zoo3
networks:
br17219:
ipv4_address: 172.20.0.16
kafka-manager:
image: sheepkiller/kafka-manager:latest
restart: always
container_name: kafka-manager
hostname: kafka-manager
ports:
- "9010:9000"
links: # 连接本compose文件创建的container
- kafka1
- kafka2
- kafka3
external_links: # 连接本compose文件以外的container
- zoo1
- zoo2
- zoo3
environment:
ZK_HOSTS: zoo1:2181,zoo2:2181,zoo3:2181 ## 修改:宿主机IP
TZ: CST-8
networks:
br17219:
ipv4_address: 172.20.0.20
networks:
br17219:
external:
name: br17219
复制代码
提供一个yml文件验证器:yamlvalidator.com/ 3.:wq 保存并退出
以下命令在docker-compose.yml 文件目录执行
4.验证(docker-compose.yml)文件配置,当配置正确时,不输出任何内容,当文件配置错误,输出错误信息
docker-compose config -q
复制代码
5.构建docker-compose
docker-compose build
复制代码
6.启动docker-compose
docker-compose up -d
复制代码
7.查看状态
docker-compose ps
复制代码
登录kafka-manager管理Kafka
http//:ip:9010
复制代码
Cluster Name 随便起
Cluster Zookeeper Hosts
zoo1:2181,zoo2:2181,zoo3:2181
复制代码
save 保存