当前位置:   article > 正文

docker学习:docker部署dolphinscheduler1.3.9伪分布式集群_docker 部署 dolphinscheduler

docker 部署 dolphinscheduler

一、环境准备

  • dolphinscheduler1.3.9伪分布式集群
  • zookeeper:3.7.1容器
  • mysql:5.7容器

二、构建镜像

(一)、dolphinscheduler镜像

1、编写build.sh(方便后面部署迁移)

#!/bin/sh
#Actively load user env
if [ -f "~/.bashrc" ];then
  echo "Warning! user bashrc file does not exist."
else
  source ~/.bashrc
fi

shellDir=`dirname $0`
workDir=`cd ${shellDir};pwd`


APP_HOME=${workDir}/app
APP_NAME=dolphinscheduler
APP_ORI_NAME=apache-dolphinscheduler-1.3.9-bin
APP_SQL_PATH="${APP_HOME}/sql/dolphinscheduler_mysql.sql"
DB_TYPE=mysql
DB_HOST=db-mysql:3306
DB_NAME=dolphinscheduler
USERNAME=test
PASSWORD=test
ZKQUORUM=zookeeper:2181
INSTALLPATH=/opt/soft/dolpherscheduler
DEPLOYUSER=hadoop
ADDRESS=localhost
WORKERS=localhost:default

#1 Init Database
cp -rf mysql-connector-java-5.1.47.jar ${APP_HOME}/lib/
MYSQL_DIR=${workDir}
MYSQL_INIT_SQL_PATH=${MYSQL_DIR}/init.sql
echo "create database if not exists ${APP_NAME};" >> ${MYSQL_INIT_SQL_PATH}
echo "GRANT ALL PRIVILEGES ON ${APP_NAME}.* TO '${USERNAME}'@'%' IDENTIFIED BY '${PASSWORD}';" >> ${MYSQL_INIT_SQL_PATH}
echo "GRANT ALL PRIVILEGES ON ${APP_NAME}.* TO '${USERNAME}'@'localhost' IDENTIFIED BY '${PASSWORD}';" >> ${MYSQL_INIT_SQL_PATH}
echo "flush privileges;" >> ${MYSQL_INIT_SQL_PATH}

#2 Modify Properties\\
DATASOURCE_PROPERTIES="${APP_HOME}/conf/datasource.properties"
sed -i "s/spring\.datasource\.driver-class-name=org.postgresql.Driver/spring.datasource.driver-class-name=com.mysql.jdbc.Driver/g" ${DATASOURCE_PROPERTIES}
sed -i "s/spring\.datasource\.url=jdbc:postgresql:\/\/127\.0\.0\.1:5432\/dolphinscheduler/spring.datasource.url=jdbc:mysql:\/\/${DB_HOST}\/dolphinscheduler?useUnicode=true\&characterEncoding=UTF-8\&useSSL=false/g" ${DATASOURCE_PROPERTIES}
sed -i "s/spring\.datasource\.username=root/spring.datasource.username=${USERNAME}/g" ${DATASOURCE_PROPERTIES}
sed -i "s/spring\.datasource\.password=root/spring.datasource.password=${PASSWORD}/g" ${DATASOURCE_PROPERTIES}


BOOTSTRAP_PROP_FILE="${APP_HOME}/conf/config/install_config.conf"
sed -ri "s![#]?(dbtype=)\S*!\1${DB_TYPE}!g" ${BOOTSTRAP_PROP_FILE}
sed -ri "s![#]?(dbhost=)\S*!\1${DB_HOST}!g" ${BOOTSTRAP_PROP_FILE}
sed -ri "s![#]?(dbname=)\S*!\1${DB_NAME}!g" ${BOOTSTRAP_PROP_FILE}
sed -ri "s![#]?(username=)\S*!\1${USERNAME}!g" ${BOOTSTRAP_PROP_FILE}
sed -ri "s![#]?(password=)\S*!\1${PASSWORD}!g" ${BOOTSTRAP_PROP_FILE}
sed -ri "s![#]?(zkQuorum=)\S*!\1${ZKQUORUM}!g" ${BOOTSTRAP_PROP_FILE}
sed -ri "s![#]?(installPath=)\S*!\1${INSTALLPATH}!g" ${BOOTSTRAP_PROP_FILE}
sed -ri "s![#]?(deployUser=)\S*!\1${DEPLOYUSER}!g" ${BOOTSTRAP_PROP_FILE}
sed -ri "s![#]?(ips=)\S*!\1${ADDRESS}!g" ${BOOTSTRAP_PROP_FILE}
sed -ri "s![#]?(masters=)\S*!\1${ADDRESS}!g" ${BOOTSTRAP_PROP_FILE}
sed -ri "s![#]?(workers=)\S*!\1${WORKERS}!g" ${BOOTSTRAP_PROP_FILE}
sed -ri "s![#]?(alertServer=)\S*!\1${ADDRESS}!g" ${BOOTSTRAP_PROP_FILE}
sed -ri "s![#]?(apiServers=)\S*!\1${ADDRESS}!g" ${BOOTSTRAP_PROP_FILE}

#3 Start Server
#echo "build docker"
#sudo docker build -t heracles/${APP_NAME}:latest .
#rm -rf $APP_HOME

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64

2、编写DockerFile

FROM datawarehouse
#datawarehouse是自己构建的镜像,里面包含jdk、hive、spark等
COPY app /dolphinscheduler

ENV APP_HOME /dolphinscheduler
ENV DOCKER true
RUN sh /dolphinscheduler/scripts/create_dolphinscheduler.sh
RUN sh /dolphinscheduler/install.sh
EXPOSE 12345
ENTRYPOINT ["sh", "/dolphinscheduler/bin/start-all.sh"]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
sh build.sh
  • 1

(二)、mysql镜像(直接拉取)

docker pull mysql:5.7
  • 1

同时下载mysql-connector-java-5.1.47.jar
当前目录下新建my.cnf文件,后面挂载到mysql容器中

[client]
default-character-set=utf8
[mysqld]
user=mysql
default_authentication_plugin=mysql_native_password
character_set_server=utf8
collation_server=utf8_general_ci
max-connections=2000
secure_file_priv=''
log_output=FILE
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

(三)、zookeeper镜像(直接拉取)

docker pull zookeeper:3.7.1
  • 1

三、容器编排

使用docker-compose.yml文件把三个容器放置于同一个网络中

version: '3'
services:
  dolphinscheduler:
    build: .
    depends_on:
      - mysql
      - zookeeper
    networks:
      - heracles-backend
      - heracles-db

  mysql:
    image: mysql:5.7
    restart: always
    privileged: true
    environment:
      MYSQL_ROOT_PASSWORD: 'Fintech!2023'
    volumes:
      - ./my.cnf:/etc/my.cnf
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
     #把当前目录下init.sql文件挂载到docker-entrypoint-initdb.d/init.sql下,docker-entrypoint-initdb.d是一个特殊的目录,它位于Docker容器中运行的MySQL、PostgreSQL、MongoDB等数据库镜像的根目录下。这个目录中的任何脚本都将在容器第一次启动时执行,并且只会在该容器第一次启动时执行一次。
    networks:
      heracles-db:
        aliases:
          - db-mysql

  zookeeper:
    image: zookeeper:3.7.1
    networks:
      - heracles-backend

networks:
  heracles-db:
  heracles-backend:

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
docker-compose up -d
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/405747
推荐阅读
相关标签
  

闽ICP备14008679号