程序员潇然 发表于 2023-4-7 12:21:46

docker 安装kafka

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

!(data/attachment/forum/202304/07/102035palf983rdbezzgfg.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

## Get this image

The recommended way to get the Bitnami Apache Kafka Docker Image is to pull the prebuilt image from the (https://hub.docker.com/r/bitnami/kafka).

```console
docker pull bitnami/kafka:latest
```

To use a specific version, you can pull a versioned tag. You can view the (https://hub.docker.com/r/bitnami/kafka/tags/) in the Docker Hub Registry.

```console
docker pull bitnami/kafka:
```

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.

```console
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 dockerdocker-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`

!(data/attachment/forum/202304/07/173419s87yt03vtqzp0l82.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "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`

!(data/attachment/forum/202304/07/174207b1y7l0nkez08hz1z.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

可以看到正常安装

!(data/attachment/forum/202206/16/141330jha7st9soow8772i.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "common_log.png")
`转载务必注明出处:程序员潇然,疯狂的字节X,https://crazybytex.com/thread-257-1-1.html `

`本文作者:程序员潇然 疯狂的字节X https://crazybytex.com/`
页: [1]
查看完整版本: docker 安装kafka