Analysis of centos6 method of deploying kafka project using docker

Analysis of centos6 method of deploying kafka project using docker

This article describes how to use docker to deploy the kafka project on centos6. Share with you for your reference, the details are as follows:

Directory structure:

/kafka
/Dockerfile
./start.sh
/Readme
/kafka_2.11-0.10.2.1.tgz

Dockfile

FROM centos
MAINTAINER qiongtao.li [email protected]
ADD ./kafka_2.11-0.10.2.1.tgz /opt
ADD ./start.sh /start.sh
ENV KAFKA_PORT=9092\
 KAFKA_DIR=/opt/kafka \
 KAFKA_DATA_DIR=/data/kafka
RUN echo "Asia/shanghai" > /etc/timezone \
 && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
 && yum -y install java \
 && mkdir -p $KAFKA_DATA_DIR \
 && mv /opt/kafka_2.11-0.10.2.1 $KAFKA_DIR
EXPOSE $KAFKA_PORT
ENV PATH=$PATH:$KAFKA_DIR/bin
ENTRYPOINT ["sh", "/start.sh"]

start.sh

conf=$KAFKA_DIR/config/server.properties
sed -i "s|broker.id=0|broker.id=${BROKER_ID:-1}|g" $conf
sed -i "s|#delete.topic.enble=true|delete.topic.enble=true|g" $conf
sed -i "s|log.dirs=/tmp/kafka-logs|log.dirs=${KAFKA_DATA_DIR}|g" $conf
sed -i "s|#advertised.listeners=PLAINTEXT://your.host.name:9092|advertised.listeners=PLAINTEXT://${KAFKA_HOST}:${KAFKA_PORT:-9092}|g" $conf
sed -i "s|zookeeper.connect=localhost:2181|zookeeper.connect=${ZOOKEEPER_HOST}:${ZOOKEEPER_PORT:-2181}|g" $conf
sh kafka-server-start.sh $conf

Readme

docker rm -f kafka
docker rmi -f kafka
docker build -t kafka .
docker run -d \
 -p 9092:9092 \
 --name kafka \
 -e KAFKA_HOST=101.201.111.163 \
 -e ZOOKEEPER_HOST=10.171.8.236 \
 -e BROKER_ID=1 \
  -v /data:/data \
 Kafka
docker ps -a
docker logs -f kafka

Note: KAFKA_HOST = host IP , which corresponds to advertised.listeners in the configuration file

Test the installation and deployment

cat Readme|while read line; do $line; done

Kafka download address:

http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/0.10.2.1/kafka_2.11-0.10.2.1.tgz

I hope this article will help you use Docker containers.

You may also be interested in:
  • Summary of common commands for building ZooKeeper3.4 middleware under centos7
  • Detailed explanation of the use based on Zookeeper
  • Shell script to automatically install zookeeper
  • Understanding the Zookeeper election mechanism
  • Configure the corresponding acl permissions for Zookeeper
  • A brief analysis of the working principle of ZooKeeper
  • Implementation of Docker to build Zookeeper&Kafka cluster
  • CentOS 6 uses Docker to deploy redis master-slave database operation example
  • Tutorial on deploying the open source project Tcloud with Docker on CentOS8
  • CentOS 6 uses Docker to deploy Zookeeper operation example

<<:  Detailed explanation of the difference between Vue life cycle

>>:  MySQL 5.7 installation and configuration tutorial under CentOS7 64 bit

Recommend

How to view MySQL links and kill abnormal links

Preface: During database operation and maintenanc...

MySQL stored procedure method example of returning multiple values

This article uses an example to describe how to r...

36 principles of MySQL database development (summary)

Preface These principles are summarized from actu...

Vue3 setup() advanced usage examples detailed explanation

Table of contents 1. Differences between option A...

In-depth understanding of the matching logic of Server and Location in Nginx

Server matching logic When Nginx decides which se...

Detailed explanation of Alibaba Cloud security rule configuration

Two days ago, I took advantage of the Double 11 s...

CentOS8 - bash: garbled characters and solutions

This situation usually occurs because the Chinese...

Measured image HTTP request

Please open the test page in a mainstream browser...

Detailed explanation of common Docker Compose commands

1. The use of Docker compose is very similar to t...

Briefly describe the difference between Redis and MySQL

We know that MySQL is a persistent storage, store...

How to install MySQL Community Server 5.6.39

This article records the detailed tutorial of MyS...

Tutorial on building file sharing service Samba under CentOS6.5

Samba Services: This content is for reference of ...