centos6 docker部署kafka项目 centos6使用docker部署kafka项目的方法分析
李琼涛 人气:0本文实例讲述了centos6使用docker部署kafka项目的方法。分享给大家供大家参考,具体如下:
目录结构:
/kafka
/Dockerfile
/start.sh
/Readme
/kafka_2.11-0.10.2.1.tgz
Dockfile
FROM centos MAINTAINER qiongtao.li hnatao@126.com 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
说明:KAFKA_HOST=宿主机IP,其对应配置文件的advertised.listeners
测试安装部署
cat Readme|while read line; do $line; done
kafka下载地址:
http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/0.10.2.1/kafka_2.11-0.10.2.1.tgz
希望本文所述对大家Docker容器使用有所帮助。
您可能感兴趣的文章:
加载全部内容