赞
踩
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
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"]
sh build.sh
docker pull mysql:5.7
同时下载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
docker pull zookeeper:3.7.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:
docker-compose up -d
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。