docker学习笔记–制作kafka镜像 |坐而言不如起而行! 二丫讲梵
source link: http://www.eryajf.net/2949.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
1,准备工作
1,下载kafka。
wget https://mirrors.cnnic.cn/apache/kafka/0.11.0.2/kafka_2.11-0.11.0.2.tgz
然后上传到服务器。
2,基础镜像。
需要准备一个jdk镜像。
docker pull eryajf/jdk:1.8
2,创建镜像
1,原料准备。
创建一个目录,有如下内容。
[root@jenkins kafka]$ls
Dockerfile kafka.tar run.sh
其中kafka.tar
是在解压之后,重命名为kafka
,然后再次打包而成,这样方便后续操作。
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
服务通过run.sh
进行初始化,里边简单配置了一下kafka,然后启动。
[root@jenkins kafka]$cat Dockerfile
FROM eryajf/jdk:1.8
MAINTAINER eryajf <[email protected]>
ENV LANG en_US.UTF-8
ADD kafka.tar /opt
ADD run.sh /
EXPOSE 9092
ENTRYPOINT [ "sh", "-c", "/run.sh" ]
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 <[email protected]>
---> 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
3,启动验证
启动一下刚刚构建的镜像。
[root@jenkins kafka]$docker run -itd -p 9092:9092 --name aa test
c49f55f91edf1c6ecdf2c37d842f250a562a55df164a51571cfc71747f330e13
进入镜像创建消息验证。
[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
可以看出,消息收发都是正常的。
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
2,官方。
[root@jenkins kafka]$ docker tag test eryajf/kafka:2.11
[root@jenkins kafka]$ docker push eryajf/kafka:2.11
有需要使用的,可以直接通过上边两个地址进行pull使用。
docker pull registry.cn-hangzhou.aliyuncs.com/eryajf/kafka:2.11
docker pull eryajf/kafka:2.11
使用注意,其中将kafka的消息目录定义在了/opt/kafka/kafka-logs
目录,需要持久化的,可以针对这个目录进行持久化!
Recommend
-
13
ELK-学习笔记–filebeat报错too many open files处理 |坐而言不如起而行! 二丫讲梵 > 迎刃而解 > <十七>ELK-学习笔记–filebeat报错too many open files处理
-
10
本文预计阅读时间 14 分钟 有时候有一些PHP项目,可能稳定性并不是最高的指标,简单,便捷,好用才是,那么使用一个镜像来跑,似乎也是非常合适的,今天就来做一下lnmp的镜像,以便于后边使用。 此镜像基于lnmp一键安装包制作,制作过程如下...
-
8
本文预计阅读时间 4 分钟Dockerfile由一行行命令语句组成,并且支持用“#”开头作为注释,一般的,Dockerfile分为四部分:基础镜像信息,维护者信息,镜像操作指令和容器启动时执行的指...
-
9
本文预计阅读时间 6 分钟 prometheus监控MySQL需要用到mysql_exporter。 mysql_exporter 项目地址:https://github.com/prometheus/mysqld_exporter 1、安装部署...
-
10
本文预计阅读时间 6 分钟 prometheus监控redis需要用到redis_exporter。 redis_exporter 项目地址:https://github.com/oliver006/redis_exporter 1、安装部署 ...
-
8
ELK-学习笔记–elasticsearch的mapping |坐而言不如起而行! 二丫讲梵 > 日志管理 >
-
7
本文预计阅读时间 4 分钟 之前一直不太喜欢使用apline这个镜像,因为太小了,这当然是一个优点,但是真正的生产业务放在这么小的一个镜像里边跑,总是无法让人放心,于是,我所做的镜像都是基于centos镜像而作。 但是,有时候有一些场景时只...
-
8
Rancher-2.2.2学习笔记-rancher-cli的使用 |坐而言不如起而行! 二丫讲梵 > 术业专攻 >
-
10
本文预计阅读时间 6 分钟 prometheus监控kafka常见的有两种开源方案,一种是传统的部署exporter的方式,一种是通过jmx配置监控,本文将采用第二种方式进行配置。 项目地址: kafka_exporter:https://github.com/danielqsj/kafk...
-
9
本文预计阅读时间 4 分钟 Kafka 是一种高吞吐的分布式发布订阅消息系统,能够替代传统的消息队列用于解耦合数据处理,缓存未处理消息等,同时具有更高的吞吐率,支持分区、多副本、冗余,因此被广泛用于大规模消息数据处理应用。Kafka 支持Java 及...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK