From b1885c7a26a5404ce42d8fb0f2d8533d9a7c83c1 Mon Sep 17 00:00:00 2001 From: caishunfeng Date: Mon, 16 May 2022 15:41:45 +0800 Subject: [PATCH] [Bug] fix run on docker and k8s (#10026) * fix docker-compose init schema * recovery depend on zk * update doc and dockerfile * fix run on k8s * udpate doc * add DOCKER flag & update doc * remove repeat DOCKER env --- deploy/docker/docker-compose.yml | 22 +++++++++---------- .../deployment-dolphinscheduler-alert.yaml | 2 ++ .../deployment-dolphinscheduler-api.yaml | 6 +++-- ...b-dolphinscheduler-schema-initializer.yaml | 4 +++- .../statefulset-dolphinscheduler-master.yaml | 2 ++ .../statefulset-dolphinscheduler-worker.yaml | 2 ++ docs/docs/en/guide/start/docker.md | 17 ++++++++++---- docs/docs/zh/guide/start/docker.md | 17 ++++++++++---- .../src/main/bin/upgrade-schema.sh | 4 +++- .../src/main/docker/Dockerfile | 3 ++- 10 files changed, 55 insertions(+), 24 deletions(-) diff --git a/deploy/docker/docker-compose.yml b/deploy/docker/docker-compose.yml index 2c557c4dd7..032d4208a6 100644 --- a/deploy/docker/docker-compose.yml +++ b/deploy/docker/docker-compose.yml @@ -19,6 +19,9 @@ version: "3.8" services: dolphinscheduler-postgresql: image: bitnami/postgresql:11.11.0 + ports: + - "5432:5432" + profiles: ["all", "schema"] environment: POSTGRESQL_USERNAME: root POSTGRESQL_PASSWORD: root @@ -35,6 +38,7 @@ services: dolphinscheduler-zookeeper: image: bitnami/zookeeper:3.6.2 + profiles: ["all"] environment: ALLOW_ANONYMOUS_LOGIN: "yes" ZOO_4LW_COMMANDS_WHITELIST: srvr,ruok,wchs,cons @@ -51,7 +55,8 @@ services: dolphinscheduler-schema-initializer: image: ${HUB}/dolphinscheduler-tools:${TAG} env_file: .env - command: [ bin/create-schema.sh ] + profiles: ["schema"] + command: [ tools/bin/upgrade-schema.sh ] depends_on: dolphinscheduler-postgresql: condition: service_healthy @@ -66,15 +71,14 @@ services: image: ${HUB}/dolphinscheduler-api:${TAG} ports: - "12345:12345" + profiles: ["all"] env_file: .env healthcheck: - test: [ "CMD", "curl", "http://localhost:12345/actuator/health" ] + test: [ "CMD", "curl", "http://localhost:12345/dolphinscheduler/actuator/health" ] interval: 30s timeout: 5s retries: 3 depends_on: - dolphinscheduler-schema-initializer: - condition: service_completed_successfully dolphinscheduler-zookeeper: condition: service_healthy volumes: @@ -86,15 +90,13 @@ services: dolphinscheduler-alert: image: ${HUB}/dolphinscheduler-alert-server:${TAG} + profiles: ["all"] env_file: .env healthcheck: test: [ "CMD", "curl", "http://localhost:50053/actuator/health" ] interval: 30s timeout: 5s retries: 3 - depends_on: - dolphinscheduler-schema-initializer: - condition: service_completed_successfully volumes: - dolphinscheduler-logs:/opt/dolphinscheduler/logs networks: @@ -102,6 +104,7 @@ services: dolphinscheduler-master: image: ${HUB}/dolphinscheduler-master:${TAG} + profiles: ["all"] env_file: .env healthcheck: test: [ "CMD", "curl", "http://localhost:5679/actuator/health" ] @@ -109,8 +112,6 @@ services: timeout: 5s retries: 3 depends_on: - dolphinscheduler-schema-initializer: - condition: service_completed_successfully dolphinscheduler-zookeeper: condition: service_healthy volumes: @@ -121,6 +122,7 @@ services: dolphinscheduler-worker: image: ${HUB}/dolphinscheduler-worker:${TAG} + profiles: ["all"] env_file: .env healthcheck: test: [ "CMD", "curl", "http://localhost:1235/actuator/health" ] @@ -128,8 +130,6 @@ services: timeout: 5s retries: 3 depends_on: - dolphinscheduler-schema-initializer: - condition: service_completed_successfully dolphinscheduler-zookeeper: condition: service_healthy volumes: diff --git a/deploy/kubernetes/dolphinscheduler/templates/deployment-dolphinscheduler-alert.yaml b/deploy/kubernetes/dolphinscheduler/templates/deployment-dolphinscheduler-alert.yaml index aba9e60d22..49ff69ac83 100644 --- a/deploy/kubernetes/dolphinscheduler/templates/deployment-dolphinscheduler-alert.yaml +++ b/deploy/kubernetes/dolphinscheduler/templates/deployment-dolphinscheduler-alert.yaml @@ -67,6 +67,8 @@ spec: env: - name: TZ value: {{ .Values.timezone }} + - name: SPRING_JACKSON_TIME_ZONE + value: {{ .Values.timezone }} {{- include "dolphinscheduler.database.env_vars" . | nindent 12 }} {{ range $key, $value := .Values.alert.env }} - name: {{ $key }} diff --git a/deploy/kubernetes/dolphinscheduler/templates/deployment-dolphinscheduler-api.yaml b/deploy/kubernetes/dolphinscheduler/templates/deployment-dolphinscheduler-api.yaml index 64ff6abd2e..f571f8c2fa 100644 --- a/deploy/kubernetes/dolphinscheduler/templates/deployment-dolphinscheduler-api.yaml +++ b/deploy/kubernetes/dolphinscheduler/templates/deployment-dolphinscheduler-api.yaml @@ -65,6 +65,8 @@ spec: env: - name: TZ value: {{ .Values.timezone }} + - name: SPRING_JACKSON_TIME_ZONE + value: {{ .Values.timezone }} {{- include "dolphinscheduler.database.env_vars" . | nindent 12 }} {{- include "dolphinscheduler.registry.env_vars" . | nindent 12 }} {{- include "dolphinscheduler.fs_s3a.env_vars" . | nindent 12 }} @@ -82,7 +84,7 @@ spec: {{- if .Values.api.livenessProbe.enabled }} livenessProbe: exec: - command: ["curl", "-s", "http://localhost:12345/actuator/health/liveness"] + command: ["curl", "-s", "http://localhost:12345/dolphinscheduler/actuator/health/liveness"] initialDelaySeconds: {{ .Values.api.livenessProbe.initialDelaySeconds }} periodSeconds: {{ .Values.api.livenessProbe.periodSeconds }} timeoutSeconds: {{ .Values.api.livenessProbe.timeoutSeconds }} @@ -92,7 +94,7 @@ spec: {{- if .Values.api.readinessProbe.enabled }} readinessProbe: exec: - command: ["curl", "-s", "http://localhost:12345/actuator/health/readiness"] + command: ["curl", "-s", "http://localhost:12345/dolphinscheduler/actuator/health/readiness"] initialDelaySeconds: {{ .Values.api.readinessProbe.initialDelaySeconds }} periodSeconds: {{ .Values.api.readinessProbe.periodSeconds }} timeoutSeconds: {{ .Values.api.readinessProbe.timeoutSeconds }} diff --git a/deploy/kubernetes/dolphinscheduler/templates/job-dolphinscheduler-schema-initializer.yaml b/deploy/kubernetes/dolphinscheduler/templates/job-dolphinscheduler-schema-initializer.yaml index 4df2ebd3ec..bb5780d670 100644 --- a/deploy/kubernetes/dolphinscheduler/templates/job-dolphinscheduler-schema-initializer.yaml +++ b/deploy/kubernetes/dolphinscheduler/templates/job-dolphinscheduler-schema-initializer.yaml @@ -38,10 +38,12 @@ spec: image: {{ include "dolphinscheduler.image.fullname.tools" . }} imagePullPolicy: {{ .Values.image.pullPolicy }} args: - - bin/create-schema.sh + - tools/bin/upgrade-schema.sh env: - name: TZ value: {{ .Values.timezone }} + - name: SPRING_JACKSON_TIME_ZONE + value: {{ .Values.timezone }} {{- include "dolphinscheduler.database.env_vars" . | nindent 12 }} {{- include "dolphinscheduler.registry.env_vars" . | nindent 12 }} {{- include "dolphinscheduler.fs_s3a.env_vars" . | nindent 12 }} diff --git a/deploy/kubernetes/dolphinscheduler/templates/statefulset-dolphinscheduler-master.yaml b/deploy/kubernetes/dolphinscheduler/templates/statefulset-dolphinscheduler-master.yaml index 503ff23f84..f1f8f4b86e 100644 --- a/deploy/kubernetes/dolphinscheduler/templates/statefulset-dolphinscheduler-master.yaml +++ b/deploy/kubernetes/dolphinscheduler/templates/statefulset-dolphinscheduler-master.yaml @@ -62,6 +62,8 @@ spec: env: - name: TZ value: {{ .Values.timezone }} + - name: SPRING_JACKSON_TIME_ZONE + value: {{ .Values.timezone }} {{- include "dolphinscheduler.database.env_vars" . | nindent 12 }} {{- include "dolphinscheduler.registry.env_vars" . | nindent 12 }} {{- include "dolphinscheduler.fs_s3a.env_vars" . | nindent 12 }} diff --git a/deploy/kubernetes/dolphinscheduler/templates/statefulset-dolphinscheduler-worker.yaml b/deploy/kubernetes/dolphinscheduler/templates/statefulset-dolphinscheduler-worker.yaml index d148f5122c..ebab09f279 100644 --- a/deploy/kubernetes/dolphinscheduler/templates/statefulset-dolphinscheduler-worker.yaml +++ b/deploy/kubernetes/dolphinscheduler/templates/statefulset-dolphinscheduler-worker.yaml @@ -62,6 +62,8 @@ spec: env: - name: TZ value: {{ .Values.timezone }} + - name: SPRING_JACKSON_TIME_ZONE + value: {{ .Values.timezone }} - name: ALERT_LISTEN_HOST value: {{ include "dolphinscheduler.fullname" . }}-alert {{- include "dolphinscheduler.database.env_vars" . | nindent 12 }} diff --git a/docs/docs/en/guide/start/docker.md b/docs/docs/en/guide/start/docker.md index 6d7966da63..7b0c8acba0 100644 --- a/docs/docs/en/guide/start/docker.md +++ b/docs/docs/en/guide/start/docker.md @@ -9,7 +9,7 @@ or zookeeper server already exists. ## Prepare - [Docker](https://docs.docker.com/engine/install/) 1.13.1+ -- [Docker Compose](https://docs.docker.com/compose/) 1.11.0+ +- [Docker Compose](https://docs.docker.com/compose/) 1.28.0+ ## Start Server @@ -54,9 +54,13 @@ $ tar -zxf apache-dolphinscheduler-"${DOLPHINSCHEDULER_VERSION}"-src.tar.gz # Going to docker-compose's location # For Mac or Linux users $ cd apache-dolphinscheduler-"${DOLPHINSCHEDULER_VERSION}"-src/deploy/docker -# For Windows users -$ cd apache-dolphinscheduler-"${DOLPHINSCHEDULER_VERSION}"-src\deploy\docker -$ docker-compose up -d +# For Windows users, you should run command `cd apache-dolphinscheduler-"${DOLPHINSCHEDULER_VERSION}"-src\deploy\docker` + +# Initialize the database, use profile schema +$ docker-compose --profile schema up -d + +# start all dolphinscheduler server, use profile all +$ docker-compose --profile all up -d ``` > NOTES: It will not only start DolphinScheduler servers but also some others necessary services like PostgreSQL(with `root` @@ -78,6 +82,7 @@ $ docker run -d --name dolphinscheduler-tools \ -e SPRING_DATASOURCE_URL="jdbc:postgresql://localhost:5432/" \ -e SPRING_DATASOURCE_USERNAME="" \ -e SPRING_DATASOURCE_PASSWORD="" \ + --net host \ apache/dolphinscheduler-tools:"${DOLPHINSCHEDULER_VERSION}" bin/create-schema.sh # Starting DolphinScheduler service $ docker run -d --name dolphinscheduler-master \ @@ -87,6 +92,7 @@ $ docker run -d --name dolphinscheduler-master \ -e SPRING_DATASOURCE_USERNAME="" \ -e SPRING_DATASOURCE_PASSWORD="" \ -e REGISTRY_ZOOKEEPER_CONNECT_STRING="localhost:2181" \ + --net host \ -d apache/dolphinscheduler-master:"${DOLPHINSCHEDULER_VERSION}" $ docker run -d --name dolphinscheduler-worker \ -e DATABASE="postgresql" \ @@ -95,6 +101,7 @@ $ docker run -d --name dolphinscheduler-worker \ -e SPRING_DATASOURCE_USERNAME="" \ -e SPRING_DATASOURCE_PASSWORD="" \ -e REGISTRY_ZOOKEEPER_CONNECT_STRING="localhost:2181" \ + --net host \ -d apache/dolphinscheduler-worker:"${DOLPHINSCHEDULER_VERSION}" $ docker run -d --name dolphinscheduler-api \ -e DATABASE="postgresql" \ @@ -103,6 +110,7 @@ $ docker run -d --name dolphinscheduler-api \ -e SPRING_DATASOURCE_USERNAME="" \ -e SPRING_DATASOURCE_PASSWORD="" \ -e REGISTRY_ZOOKEEPER_CONNECT_STRING="localhost:2181" \ + --net host \ -d apache/dolphinscheduler-api:"${DOLPHINSCHEDULER_VERSION}" $ docker run -d --name dolphinscheduler-alert-server \ -e DATABASE="postgresql" \ @@ -111,6 +119,7 @@ $ docker run -d --name dolphinscheduler-alert-server \ -e SPRING_DATASOURCE_USERNAME="" \ -e SPRING_DATASOURCE_PASSWORD="" \ -e REGISTRY_ZOOKEEPER_CONNECT_STRING="localhost:2181" \ + --net host \ -d apache/dolphinscheduler-alert-server:"${DOLPHINSCHEDULER_VERSION}" ``` diff --git a/docs/docs/zh/guide/start/docker.md b/docs/docs/zh/guide/start/docker.md index 717d5cf65c..441edda888 100644 --- a/docs/docs/zh/guide/start/docker.md +++ b/docs/docs/zh/guide/start/docker.md @@ -7,7 +7,7 @@ ## 前置条件 - [Docker](https://docs.docker.com/engine/install/) 1.13.1+ -- [Docker Compose](https://docs.docker.com/compose/) 1.11.0+ +- [Docker Compose](https://docs.docker.com/compose/) 1.28.0+ ## 启动服务 @@ -47,9 +47,13 @@ $ DOLPHINSCHEDULER_VERSION= $ tar -zxf apache-dolphinscheduler-"${DOLPHINSCHEDULER_VERSION}"-src.tar.gz # Mac Linux 用户 $ cd apache-dolphinscheduler-"${DOLPHINSCHEDULER_VERSION}"-src/deploy/docker -# Windows 用户 -$ cd apache-dolphinscheduler-"${DOLPHINSCHEDULER_VERSION}"-src\deploy\docker -$ docker-compose up -d +# Windows 用户, `cd apache-dolphinscheduler-"${DOLPHINSCHEDULER_VERSION}"-src\deploy\docker` + +# 如果需要初始化或者升级数据库结构,需要指定profile为schema +$ docker-compose --profile schema up -d + +# 启动dolphinscheduler所有服务,指定profile为all +$ docker-compose --profile all up -d ``` > 提醒:通过 docker-compose 启动服务时,除了会启动 DolphinScheduler 对应的服务外,还会启动必要依赖服务,如数据库 PostgreSQL(用户 @@ -70,6 +74,7 @@ $ docker run -d --name dolphinscheduler-tools \ -e SPRING_DATASOURCE_URL="jdbc:postgresql://localhost:5432/" \ -e SPRING_DATASOURCE_USERNAME="" \ -e SPRING_DATASOURCE_PASSWORD="" \ + --net host \ apache/dolphinscheduler-tools:"${DOLPHINSCHEDULER_VERSION}" bin/create-schema.sh # 启动 DolphinScheduler 对应的服务 $ docker run -d --name dolphinscheduler-master \ @@ -79,6 +84,7 @@ $ docker run -d --name dolphinscheduler-master \ -e SPRING_DATASOURCE_USERNAME="" \ -e SPRING_DATASOURCE_PASSWORD="" \ -e REGISTRY_ZOOKEEPER_CONNECT_STRING="localhost:2181" \ + --net host \ -d apache/dolphinscheduler-master:"${DOLPHINSCHEDULER_VERSION}" $ docker run -d --name dolphinscheduler-worker \ -e DATABASE="postgresql" \ @@ -87,6 +93,7 @@ $ docker run -d --name dolphinscheduler-worker \ -e SPRING_DATASOURCE_USERNAME="" \ -e SPRING_DATASOURCE_PASSWORD="" \ -e REGISTRY_ZOOKEEPER_CONNECT_STRING="localhost:2181" \ + --net host \ -d apache/dolphinscheduler-worker:"${DOLPHINSCHEDULER_VERSION}" $ docker run -d --name dolphinscheduler-api \ -e DATABASE="postgresql" \ @@ -95,6 +102,7 @@ $ docker run -d --name dolphinscheduler-api \ -e SPRING_DATASOURCE_USERNAME="" \ -e SPRING_DATASOURCE_PASSWORD="" \ -e REGISTRY_ZOOKEEPER_CONNECT_STRING="localhost:2181" \ + --net host \ -d apache/dolphinscheduler-api:"${DOLPHINSCHEDULER_VERSION}" $ docker run -d --name dolphinscheduler-alert-server \ -e DATABASE="postgresql" \ @@ -103,6 +111,7 @@ $ docker run -d --name dolphinscheduler-alert-server \ -e SPRING_DATASOURCE_USERNAME="" \ -e SPRING_DATASOURCE_PASSWORD="" \ -e REGISTRY_ZOOKEEPER_CONNECT_STRING="localhost:2181" \ + --net host \ -d apache/dolphinscheduler-alert-server:"${DOLPHINSCHEDULER_VERSION}" ``` diff --git a/dolphinscheduler-tools/src/main/bin/upgrade-schema.sh b/dolphinscheduler-tools/src/main/bin/upgrade-schema.sh index b3df345871..355ebfe379 100755 --- a/dolphinscheduler-tools/src/main/bin/upgrade-schema.sh +++ b/dolphinscheduler-tools/src/main/bin/upgrade-schema.sh @@ -19,7 +19,9 @@ BIN_DIR=$(dirname $0) DOLPHINSCHEDULER_HOME=${DOLPHINSCHEDULER_HOME:-$(cd $BIN_DIR/../..; pwd)} -source "$DOLPHINSCHEDULER_HOME/bin/env/dolphinscheduler_env.sh" +if [ "$DOCKER" != "true" ]; then + source "$DOLPHINSCHEDULER_HOME/bin/env/dolphinscheduler_env.sh" +fi JAVA_OPTS=${JAVA_OPTS:-"-server -Duser.timezone=${SPRING_JACKSON_TIME_ZONE} -Xms1g -Xmx1g -Xmn512m -XX:+PrintGCDetails -Xloggc:gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=dump.hprof"} diff --git a/dolphinscheduler-tools/src/main/docker/Dockerfile b/dolphinscheduler-tools/src/main/docker/Dockerfile index 5c2fb45e45..811a8c2006 100644 --- a/dolphinscheduler-tools/src/main/docker/Dockerfile +++ b/dolphinscheduler-tools/src/main/docker/Dockerfile @@ -27,6 +27,7 @@ RUN apt update ; \ WORKDIR $DOLPHINSCHEDULER_HOME -ADD ./target/tools $DOLPHINSCHEDULER_HOME +# see doc: https://dolphinscheduler.apache.org/en-us/docs/dev/user_doc/guide/upgrade.html +ADD ./target/tools $DOLPHINSCHEDULER_HOME/tools ENTRYPOINT [ "/bin/bash" ]