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

Detailed explanation of JSON.parse and JSON.stringify usage

Table of contents JSON.parse JSON.parse Syntax re...

A brief discussion on the use of GROUP BY and HAVING in SQL statements

Before introducing the GROUP BY and HAVING clause...

Tutorial on upgrading from Centos7 to Centos8 (with pictures and text)

If you upgrade in a formal environment, please ba...

Tips for implementing list loop scrolling based on jQuery (super simple)

I saw a good idea and recorded it. I have used jQ...

React Fiber structure creation steps

Table of contents React Fiber Creation 1. Before ...

Detailed explanation of Vue px to rem configuration

Table of contents Method 1 1. Configuration and i...

Summary of various implementation methods of mysql database backup

This article describes various ways to implement ...

Solution to the Multiple primary key defined error in MySQL

There are two ways to create a primary key: creat...

js implements a simple countdown

This article example shares the specific code of ...

How to play local media (video and audio) files using HTML and JavaScript

First of all, for security reasons, JavaScript ca...

Nginx configuration 80 port access 8080 and project name address method analysis

Tomcat accesses the project, usually ip + port + ...

Example code for implementing dotted border scrolling effect with CSS

We often see a cool effect where the mouse hovers...

How to use docker to build redis master-slave

1. Build a Docker environment 1. Create a Dockerf...