请选择 进入手机版 | 继续访问电脑版

[Linux/Docker] docker 安装kafka

技术实战 技术实战 2822 人阅读 | 0 人回复

https://hub.docker.com/search?q=kafka

image.png

Get this image

The recommended way to get the Bitnami Apache Kafka Docker Image is to pull the prebuilt image from the Docker Hub Registry.

docker pull bitnami/kafka:latest

To use a specific version, you can pull a versioned tag. You can view the list of available versions in the Docker Hub Registry.

docker pull bitnami/kafka:[TAG]

If you wish, you can also build the image yourself by cloning the repository, changing to the directory containing the Dockerfile and executing the docker build command. Remember to replace the APP, VERSION and OPERATING-SYSTEM path placeholders in the example command below with the correct values.

git clone https://github.com/bitnami/containers.git
cd bitnami/APP/VERSION/OPERATING-SYSTEM
docker build -t bitnami/APP:latest .

安装docker以及docker compose

推荐使用docker compose进行安装 如果没有安装过,可以先安装docker

#升级yum
sudo yum update
#卸载旧版本docker
sudo yum remove docker  docker-common docker-selinux docker-engine
#安装依赖
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
#设置源
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum makecache fast
#安装docker
sudo yum install docker-ce
#启动服务
sudo systemctl start docker
#查看版本
docker version
#拉取镜像
docker pull hello-world
#启动容器
docker run hello-world

然后安装docker compose

sudo curl -L https://github.com/docker/compose/releases/download/2.17.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

注意: 如果网络不行,可以先下载,我是win10上面的centos虚拟机,下载的是docker-compose-linux-x86_64,然后上传上去,放到某个位置后,修改下名字,比如上面的路径就可以 查看版本号确认情况

docker-compose -v

dockerfile文件

官网有说明: https://hub.docker.com/r/bitnami/kafka

image.png 分别介绍了使用zk以及不用zk的方式 上面的文件中最左边的+ - 号是对比标识,-号的删除,+号的保留,没有符号的也保留,然后最后去掉这个最左边的+ - 号。

最终文件如下:

version: "3"
services:
   kafka:
     image: 'bitnami/kafka:latest'
     ports:
       - '9092:9092'
     environment:
       - KAFKA_ENABLE_KRAFT=yes
       - KAFKA_CFG_PROCESS_ROLES=broker,controller
       - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
       - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
       - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093
       - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
       - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092
       - KAFKA_BROKER_ID=1
       - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@127.0.0.1:9093
       - ALLOW_PLAINTEXT_LISTENER=yes

我只是本地测试用,其他参数就不配置了,就这样

保存为docker-compose.yml

安装启动kafka

在这个路径下执行: docker-compose up -d

image.png

可以看到正常安装

common_log.png 转载务必注明出处:程序员潇然,疯狂的字节X,https://crazybytex.com/thread-257-1-1.html

本文作者:程序员潇然 疯狂的字节X https://crazybytex.com/

关注下面的标签,发现更多相似文章
    黄小斜学Java

    疯狂的字节X

  • 目前专注于分享Java领域干货,公众号同步更新。原创以及收集整理,把最好的留下。
    包括但不限于JVM、计算机科学、算法、数据库、分布式、Spring全家桶、微服务、高并发、Docker容器、ELK、大数据等相关知识,一起进步,一起成长。
热门推荐
[若依]微服务springcloud版新建增添加一个
[md]若依框架是一个比较出名的后台管理系统,有多个不同版本。
[CXX1300] CMake '3.18.1' was not
[md][CXX1300] CMake '3.18.1' was not found in SDK, PATH, or
java 解析modbus 协议 Modbus4j应用 使用mo
[md]本文记录使用java开发modbus协议程序,与串口进行连接,使用