zookeeper参照https://www.cnblogs.com/wintersoft/p/11128484.html

mkdir /opt/kafka -p
vim /opt/kafka/Dockerfile

FROM wurstmeister/kafka:2.12-2.3.0
EXPOSE 9092

sudo mkdir -p /var/log/kafka;sudo chmod -R 777 /var/log/kafka

vim /opt/kafka/docker-compose.yml

version: '2'
services:
kafka:
image: v-kafka
container_name: kafka
build:
context: .
dockerfile: Dockerfile
restart: always
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: kafkaserver
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: "zookeeperserver:2181"
volumes:
- /var/log/kafka/:/kafka
- /var/run/docker.sock:/var/run/docker.sock
extra_hosts:
- "kafkaserver:192.168.0.101"
- "zookeeperserver:192.168.0.101"

生成启动
cd /opt/kafka/
docker-compose build
docker-compose up -d --force-recreate
docker-compose down
docker-compose restart

查看进程
netstat -anltp|grep 9092

查看日志
docker logs --tail="500" kafka
docker logs -f kafka

进入容器
docker exec -it kafka /bin/bash

伪集群

sudo mkdir -p /var/log/kafka/node1;sudo chmod -R 777 /var/log/kafka/node1
sudo mkdir -p /var/log/kafka/node2;sudo chmod -R 777 /var/log/kafka/node2
sudo mkdir -p /var/log/kafka/node3;sudo chmod -R 777 /var/log/kafka/node3

vim /opt/kafka/docker-compose.yml

version: '2'

services:
kafka1:
image: v-kafka1
container_name: kafka1
build:
context: .
dockerfile: Dockerfile
restart: always
ports:
- 9011:9092
environment:
KAFKA_PORT: 9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafkaserver1:9011
KAFKA_ADVERTISED_HOST_NAME: kafkaserver1
KAFKA_ADVERTISED_PORT: 9011
KAFKA_BROKER_ID: 1
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 2
KAFKA_ZOOKEEPER_CONNECT: zookeeperserver1:2181,zookeeperserver2:2182,zookeeperserver3:2183
KAFKA_DELETE_TOPIC_ENABLE: "true"
volumes:
- /var/log/kafka/node1:/kafka
- /var/run/docker.sock:/var/run/docker.sock
extra_hosts:
- "kafkaserver1:192.168.0.101"
- "kafkaserver2:192.168.0.101"
- "kafkaserver3:192.168.0.101"
- "zookeeperserver1:192.168.0.101"
- "zookeeperserver2:192.168.0.101"
- "zookeeperserver3:192.168.0.101"
kafka2:
image: v-kafka2
container_name: kafka2
build:
context: .
dockerfile: Dockerfile
restart: always
ports:
- 9012:9092
environment:
KAFKA_PORT: 9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafkaserver2:9012
KAFKA_ADVERTISED_HOST_NAME: kafkaserver2
KAFKA_ADVERTISED_PORT: 9012
KAFKA_BROKER_ID: 2
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 2
KAFKA_ZOOKEEPER_CONNECT: zookeeperserver1:2181,zookeeperserver2:2182,zookeeperserver3:2183
KAFKA_DELETE_TOPIC_ENABLE: "true"
volumes:
- /var/log/kafka/node2:/kafka
- /var/run/docker.sock:/var/run/docker.sock
extra_hosts:
- "kafkaserver1:192.168.0.101"
- "kafkaserver2:192.168.0.101"
- "kafkaserver3:192.168.0.101"
- "zookeeperserver1:192.168.0.101"
- "zookeeperserver2:192.168.0.101"
- "zookeeperserver3:192.168.0.101"
kafka3:
image: v-kafka3
container_name: kafka3
build:
context: .
dockerfile: Dockerfile
restart: always
ports:
- 9013:9092
environment:
KAFKA_PORT: 9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafkaserver3:9013
KAFKA_ADVERTISED_HOST_NAME: kafkaserver3
KAFKA_ADVERTISED_PORT: 9013
KAFKA_BROKER_ID: 3
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 2
KAFKA_ZOOKEEPER_CONNECT: zookeeperserver1:2181,zookeeperserver2:2182,zookeeperserver3:2183
KAFKA_DELETE_TOPIC_ENABLE: "true"
volumes:
- /var/log/kafka/node3:/kafka
- /var/run/docker.sock:/var/run/docker.sock
extra_hosts:
- "kafkaserver1:192.168.0.101"
- "kafkaserver2:192.168.0.101"
- "kafkaserver3:192.168.0.101"
- "zookeeperserver1:192.168.0.101"
- "zookeeperserver2:192.168.0.101"
- "zookeeperserver3:192.168.0.101"

配置key规则:在前面加KAFKA_前缀 全部大写 “.”用“_”代替

如:
增加 Kafka 堆的内存大小 KAFKA_HEAP_OPTS=-Xmx4G -Xms4G
KAFKA_LOG_DIRS=/kafka/logs 时 volumes:- "./kafka3/logs:/kafka/logs"

kafka-manager的environment可设置APPLICATION_SECRET: "xxx"
KAFKA_LISTENERS的值 为内网地址

没配置delete.topic.enable=true,只是软删除

如果将topic软删除,java客户端会报:

WARN Error while fetching metadata with correlation id 0 : {test=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

报 org.apache.kafka.clients.NetworkClient   : [Producer clientId=producer-3] 1 partitions have leader brokers without a matching listener, including [log-0]

一般是zookeeper的ip:port配置导致kafka报错问题,配置好后需清理zookeeper数据才会正常。

复制配置
docker cp kafka1:/opt/kafka/config/ /opt/kafka/kafka1_config_bak/

kafka-manager需在界面手动添加集群配置才能显示。

测试kafka

进入容器
docker exec -it kafka1 /bin/bash

创建topic
/opt/kafka/bin/kafka-topics.sh --create --bootstrap-server 192.168.0.101:9011,192.168.0.101:9012,192.168.0.101:9013 --topic myTestTopic --partitions 3 --replication-factor 3
注:replication-factor个数不能超过broker的个数

查看当前topic列表
/opt/kafka/bin/kafka-topics.sh --list --bootstrap-server 192.168.0.101:9011,192.168.0.101:9012,192.168.0.101:9013

运行一个消息生产者,指定topic为刚刚创建的myTestTopic
/opt/kafka/bin/kafka-console-producer.sh --broker-list 192.168.0.101:9011,192.168.0.101:9012,192.168.0.101:9013 --topic myTestTopic
输入任意字符 然后ctrl+c退出

查看指定topic明细
/opt/kafka/bin/kafka-topics.sh --describe --bootstrap-server 192.168.0.101:9011,192.168.0.101:9012,192.168.0.101:9013 --topic myTestTopic

消费消息
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 192.168.0.101:9011,192.168.0.101:9012,192.168.0.101:9013 --topic myTestTopic --from-beginning
ctrl+c退出

删除topic
/opt/kafka/bin/kafka-topics.sh --delete --bootstrap-server 192.168.0.101:9011,192.168.0.101:9012,192.168.0.101:9013 --topic myTestTopic
如果不能删除,docker启动时配置KAFKA_DELETE_TOPIC_ENABLE: "true"

 

kafka安装运行(docker)的更多相关文章

  1. Docker——MacOS上安装运行docker

    近几年来,Docker越来越流行,使用场景也越来越广泛.为了能尽快跟上时代步伐.学习并应用到实际工作中,我也开始了Docker之旅. Docker版本 Docker共有两种版本: 社区版(Commun ...

  2. elastic stack安装运行(docker)

    https://www.docker.elastic.co 注:目前阿里云为7.4 elasticsearch 参考https://www.elastic.co/guide/en/elasticsea ...

  3. TICK/TIGK运维栈安装运行 docker【中】

    InfluxDB docker search influxdb docker pull influxdb docker run -d -p 8086:8086 -v /var/lib/influxdb ...

  4. Centos7基于容器安装运行Docker私有仓库及添加认证

    一.前言 官方的Docker hub是一个用于管理公共镜像的好地方,我们可以在上面找到我们想要的镜像,也可以把我们自己的镜像推送上去.但是,有时候,我们的使用场景需要我们拥有一个私有的镜像仓库用于管理 ...

  5. skywalking安装运行(docker)

    https://github.com/apache/skywalking-docker/tree/master/6/6.5 https://hub.docker.com/r/apache/skywal ...

  6. zookeeper安装运行(docker)

    拉取镜像docker pull zookeeper:latest 获取镜像基本信息docker inspect zookeeper mkdir /opt/zookeeper -p vim /opt/z ...

  7. Windows OS上安装运行Apache Kafka教程

    Windows OS上安装运行Apache Kafka教程 下面是分步指南,教你如何在Windows OS上安装运行Apache Zookeeper和Apache Kafka. 简介 本文讲述了如何在 ...

  8. Windows系统下安装运行Kafka

    一.安装JAVA JDK 1.下载安装包 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151. ...

  9. 在Windows安装运行Kafka

    一.安装JAVA JDK 1.下载安装包 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151. ...

随机推荐

  1. 2. vue基础-vue-cli(vue脚手架)

    1. 作用 ​ 快速创建一个基于webpack模板的项目 2. 安装工具 安装webpack:使用npm全局安装webpack,打开命令行工具,输入 npm install webpack -g,安装 ...

  2. Java 面向对象—杂项(方法不能重写,修饰符,变量)

    一.哪些方法不能被重写? 1.final 修饰的不能重写 2.static 修饰的不能重写 3.private 修饰的,因为私有的在子类中不可见 4.如果跨包的话,修饰符缺省的也不能被重写,因为缺省的 ...

  3. eclipse 小提示

    1.模糊提示插件 Code Recommenders alt+/ 模糊提示插件 Code Recommenders

  4. 微信小程序引入外部组件 iView Weapp

    iview Weapp组件的使用方法: 1. 下载小程序组件库 (前提是你已经有了项目目录) 你可以直接去github把iView Weapp的代码下载下来,也可以用过npm来下载. github地址 ...

  5. Cleaning Robot POJ - 2688

    题目链接:https://vjudge.net/problem/POJ-2688 题意:在一个地面上,有一个扫地机器人,有一些障碍物,有一些脏的地砖,问,机器热能不能清扫所有的地砖, (机器人不能越过 ...

  6. 词向量---LSA(Latent Semantic Analysis)

    举例: 矩阵分解之后,取前两维,k=2, 单词距离:   文档距离: 通过LSA分析之后计算文档间的余弦相似度,属于同一个类型文本之间的相似度很接近:在原始文档间计算相似度,效果不如LSA 当出现新的 ...

  7. Vcode的生成工具类,生成制定长度验证码,图文验证码工具类

    public class VCodeUtils { // 使用到Algerian字体,系统里没有的话需要安装字体,字体只显示大写,去掉了1,0,i,o几个容易混淆的字符 public static f ...

  8. mysql 的 docker image 使用(官方文档节选)

    1.创建一个 mysql 实例: $ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag 2.创 ...

  9. 13、Python文件处理、os模块、json/pickle序列化模块

    一.字符编码 Python3中字符串默认为Unicode编码. str类型的数据可以编码成其他字符编码的格式,编码的结果为bytes类型. # coding:gbk x = '上' # 当程序执行时, ...

  10. 【Java】SpringBoot-Ajax-Json:Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported for @RequestBody XXX

    1.重新组装数据 var params=JSON.stringify({"userword":XXXXX,"password":"XXXXX" ...