centos6使用docker部署kafka项目的方法分析
程序员文章站
2022-03-20 17:45:29
本文实例讲述了centos6使用docker部署kafka项目的方法。分享给大家供大家参考,具体如下:目录结构:/kafka /dockerfile /start.sh /readme /kafka_...
本文实例讲述了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容器使用有所帮助。