二丫讲梵 二丫讲梵
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)

二丫讲梵

行者常至,为者常成
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)
  • 最佳实践

  • 迎刃而解

  • Nginx

  • Php

  • Zabbix

  • AWS

  • Prometheus

  • Grafana

  • Loki

  • CentOS

  • Supervisord

  • Systemd

  • Docker

    • 从DockerHub到阿里云镜像仓库:整理汇总我同步过的docker镜像(公开可匿名pull)
    • docker的几种安装方式
    • docker配置加速器的几种方案
    • docker搭建官方版私有仓库(了解)
    • Docker笔记之企业级仓库harbor搭建
    • 认识了解Dockerfile
    • 利用Dockerfile创建一些基础镜像
    • Docker笔记之与镜像相关的命令整理
    • 从docker容器时间问题探究到Namespace问题
    • Docker笔记之制作kafka镜像
      • 1,准备工作
        • 1,下载 kafka。
        • 2,基础镜像。
      • 2,创建镜像
        • 1,原料准备。
        • 2,查看内容。
        • 3,构建镜像。
      • 3,启动验证
      • 4,上传公用
        • 1,阿里云。
        • 2,官方。
    • Docker笔记之制作lnmp镜像
    • Docker笔记之使用apline镜像
    • Docker笔记之修改默认数据存储目录
    • Docker笔记之修改默认网段
    • docker磁盘或者镜像清理相关内容
    • centos镜像添加chrome浏览器以及中文字体
    • 利用buildx构建支持多CPU架构平台的docker镜像
    • docker exec命令中含有通配符执行失败的问题
    • Docker 调试构建失败的 Dockerfile 的方法
    • Docker容器如何优雅地访问宿主机网络
  • Docker-Compose

  • Rancher

  • Ansible

  • OpenLdap

  • GitLab

  • GitHub

  • Etcd

  • Consul

  • RabbitMQ

  • Kafka

  • Mysql

  • MongoDB

  • OpenVPN

  • Kvm

  • VMware

  • 配置文件详解

  • Other

  • 运维观止
  • Docker
二丫讲梵
2019-07-04
目录

Docker笔记之制作kafka镜像

文章发布较早,内容可能过时,阅读注意甄别。

# 1,准备工作

# 1,下载 kafka。

wget https://mirrors.cnnic.cn/apache/kafka/0.11.0.2/kafka_2.11-0.11.0.2.tgz
1

然后上传到服务器。

# 2,基础镜像。

需要准备一个 jdk 镜像。

docker pull eryajf/jdk:1.8
1

# 2,创建镜像

# 1,原料准备。

创建一个目录,有如下内容。

[root@jenkins kafka]$ls
Dockerfile  kafka.tar  run.sh
1
2

其中kafka.tar是在解压之后,重命名为kafka,然后再次打包而成,这样方便后续操作。

申明

原创文章eryajf,未经授权,严禁转载,侵权必究!此乃文中随机水印,敬请读者谅解。

Copyright 二丫讲梵 (opens new window) 版权所有

# 2,查看内容。

查看两个文件的内容。

[root@jenkins kafka]$cat run.sh
#!/bin/bash
source /etc/profile
sed -i '34s/^#//g' /opt/kafka/config/server.properties
sed -i '63s/tmp/opt\/kafka/g' /opt/kafka/config/server.properties
/opt/kafka/bin/zookeeper-server-start.sh -daemon /opt/kafka/config/zookeeper.properties
sleep 3
/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties
1
2
3
4
5
6
7
8

服务通过run.sh进行初始化,里边简单配置了一下 kafka,然后启动。

[root@jenkins kafka]$cat Dockerfile
FROM eryajf/jdk:1.8
MAINTAINER eryajf <liqilong@edspay.com>
ENV LANG en_US.UTF-8
ADD kafka.tar /opt
ADD   run.sh  /
EXPOSE 9092
ENTRYPOINT [ "sh", "-c", "/run.sh" ]
1
2
3
4
5
6
7
8

# 3,构建镜像。

[root@jenkins kafka]$docker build -t test .
Sending build context to Docker daemon 236.7 MB
Step 1/7 : FROM 192.168.112.69/public/jdk:1.8
 ---> 88d717766e50
Step 2/7 : MAINTAINER eryajf <liqilong@edspay.com>
 ---> Using cache
 ---> ce9a81c38f6c
Step 3/7 : ENV LANG en_US.UTF-8
 ---> Using cache
 ---> d8ed2ae6a64f
Step 4/7 : ADD kafka.tar /opt
 ---> 1e6337f7c14d
Removing intermediate container b1127716d99e
Step 5/7 : ADD run.sh /
 ---> 1ca96a5d1728
Removing intermediate container 4c5750914f16
Step 6/7 : EXPOSE 9092
 ---> Running in a62aca3a277d
 ---> ce25e74f2acb
Removing intermediate container a62aca3a277d
Step 7/7 : ENTRYPOINT sh -c /run.sh
 ---> Running in 77536f76e370
 ---> 9d368303d96e
Removing intermediate container 77536f76e370
Successfully built 9d368303d96e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

# 3,启动验证

启动一下刚刚构建的镜像。

[root@jenkins kafka]$docker run -itd -p 9092:9092 --name aa test
c49f55f91edf1c6ecdf2c37d842f250a562a55df164a51571cfc71747f330e13
1
2

进入镜像创建消息验证。

[root@jenkins kafka]$docker exec -it aa sh
sh-4.2#cd opt/kafka/bin
sh-4.2# ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
Created topic "test".
sh-4.2# ./kafka-topics.sh --list --zookeeper localhost:2181
test
sh-4.2# ./kafka-console-producer.sh --broker-list localhost:9092 --topic test
>hello world
>hello eryajf
然后退出一下这个终端,查看一下刚刚的消息
sh-4.2# ./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
hello world
hello eryajf
1
2
3
4
5
6
7
8
9
10
11
12
13
14

可以看出,消息收发都是正常的。

img

# 4,上传公用

# 1,阿里云。

[root@jenkins kafka]$ docker tag test registry.cn-hangzhou.aliyuncs.com/eryajf/kafka:2.11
[root@jenkins kafka]$ docker push registry.cn-hangzhou.aliyuncs.com/eryajf/kafka:2.11
1
2

# 2,官方。

[root@jenkins kafka]$ docker tag test eryajf/kafka:2.11
[root@jenkins kafka]$ docker push eryajf/kafka:2.11
1
2

有需要使用的,可以直接通过上边两个地址进行 pull 使用。

docker pull registry.cn-hangzhou.aliyuncs.com/eryajf/kafka:2.11
docker pull eryajf/kafka:2.11
1
2

使用注意,其中将 kafka 的消息目录定义在了/opt/kafka/kafka-logs目录,需要持久化的,可以针对这个目录进行持久化!

微信 支付宝
#docker#kafka
上次更新: 2024/07/04, 22:40:37
从docker容器时间问题探究到Namespace问题
Docker笔记之制作lnmp镜像

← 从docker容器时间问题探究到Namespace问题 Docker笔记之制作lnmp镜像→

最近更新
01
睡着的人不关灯
06-12
02
学习周刊-总第215期-2025年第24周
06-12
03
学习周刊-总第214期-2025年第23周
06-05
更多文章>
Theme by Vdoing | Copyright © 2017-2025 | 点击查看十年之约 | 浙ICP备18057030号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式