共计 1863 个字符,预计需要花费 5 分钟才能阅读完成。
1 装置
# 1. 装置 docker-compose,须要事后装置好 Docker
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 减少可执行权限
sudo chmod +x /usr/local/bin/docker-compose
# 2. 创立相干文件夹
mkdir -p /opt/zookeeper && mkdir -p /opt/kafka
# 3. 筹备配置文件
echo 'version:'3.7'
services:
zookeeper:
image: wurstmeister/zookeeper
volumes:
- /opt/zookeeper/data:/data
container_name: zookeeper
mem_limit: 1024M
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- 2181:2181
restart: always
kafka_node1:
image: wurstmeister/kafka
container_name: kafka_node1
mem_limit: 1024M
depends_on:
- zookeeper
ports:
- 9092:9092
volumes:
- /opt/kafka/data:/kafka
environment:
KAFKA_CREATE_TOPICS: "test"
KAFKA_BROKER_NO: 0
KAFKA_LISTENERS: PLAINTEXT://kafka_node1:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://${kafka_service_public_ip}:${kafka_service_public_port}
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_HEAP_OPTS: "-Xmx512M -Xms16M"
restart: always
kafka_manager:
image: hlebalbau/kafka-manager:stable
ports:
- 9000:9000
environment:
ZK_HOSTS: "zookeeper:2181"
depends_on:
- zookeeper
- kafka_node1
restart: always' > /etc/kafka/kafka.yml
# 3. 启动容器服务
docker-compose -f /etc/kafka/kafka.yml up -d
2 应用 Kafka-Mgr 治理集群
拜访服务所在主机的 9000
端口,按如下图所示创立集群:
-
若呈现 Yikes! KeeperErrorCode = Unimplemented for /kafka-manager/mutex Try again. 谬误,参考此 issue 解决,具体步骤如下:
docker exec -it zookeeper bashroot@98747a9eac65:/zookeeper-3.4.14# ./bin/zkCli.sh [zk: localhost:2181(CONNECTED) 2] ls /kafka-manager[configs, deleteClusters, clusters] [zk: localhost:2181(CONNECTED) 3] create /kafka-manager/mutex ""Created /kafka-manager/mutex [zk: localhost:2181(CONNECTED) 5] create /kafka-manager/mutex/locks ""Created /kafka-manager/mutex/locks [zk: localhost:2181(CONNECTED) 6] create /kafka-manager/mutex/leases ""Created /kafka-manager/mutex/leases
3 参考
- Docker 环境下部署 Kafka
- docker-compose 部署 Kafka
- Kafka-Mgr 的应用
正文完