高效调度新篇章:详解DolphinScheduler 3.2.0生产级集群搭建
转载自tuoluzhe8521
导读:通过简化复杂的任务依赖关系, DolphinScheduler为数据工程师提供了强大的工作流程管理和调度能力。在3.2.0版本中,DolphinScheduler带来了一系列新功能和改进,使其在生产环境中的稳定性和可用性得到了显著提升。
为了帮助读者更好地理解和应用这一版本,我们精心准备了这篇DolphinScheduler 3.2.0生产集群高可用搭建全攻略,深入探讨如何在生产环境中搭建一个高可用的DolphinScheduler集群,包括但不限于环境准备、数据库配置、用户权限设置、SSH免密登陆配置、ZooKeeper启动、以及服务的启动与停止等关键步骤。
1. 环境准备
1.1 集群规划
本次安装环境为contos7.9
1.2 组件下载地址
DolphinScheduler-3.20官网:https://dolphinscheduler.apache.org/zh-cn/download/3.2.0
官网安装文档:https://dolphinscheduler.apache.org/zh-cn/docs/3.2.0/guide/installation/cluster
1.3 前置准备工作
- JDK:下载JDK (1.8+),安装并配置 JAVA_HOME 环境变量,并将其下的 bin 目录追加到 PATH 环境变量中。如果你的环境中已存在,可以跳过这步。
- 二进制包:在下载页面下载 DolphinScheduler 二进制包
- 数据库:PostgreSQL (8.2.15+) 或者 MySQL (5.7+),两者任选其一即可,如 MySQL 则需要 JDBC Driver 8.0.16
- 注册中心:ZooKeeper (3.8.0+),下载地址
- 进程树分析
- macOS 安装pstree
- Fedora/Red/Hat/CentOS/Ubuntu/Debian 安装psmisc
[hadoop@hadoop1 ~]$ sudo yum install -y psmisc
注意: DolphinScheduler 本身不依赖 Hadoop、Hive、Spark,但如果你运行的任务需要依赖他们,就需要有对应的环境支持
2.DolphinScheduler集群安装
2.1 解压安装包
- 上传DolphinScheduler安装包到hadoop1节点的/data/software目录
- 解压安装包到当前目录
注:解压目录并非最终的安装目录
[hadoop@hadoop1 software]$ tar -zxvf apache-dolphinscheduler-3.2.0-bin
2.2 配置数据库
DolphinScheduler 元数据存储在关系型数据库中,故需创建相应的数据库和用户。
mysql -uroot -p
//创建数据库
mysql> CREATE DATABASE dolphinscheduler DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
//创建用户
//修改 {user} 和 {password} 为你希望的用户名和密码
mysql> CREATE USER '{user}'@'%' IDENTIFIED BY '{password}';
mysql> GRANT ALL PRIVILEGES ON dolphinscheduler.* TO '{user}'@'%';
mysql> CREATE USER '{user}'@'localhost' IDENTIFIED BY '{password}';
mysql> GRANT ALL PRIVILEGES ON dolphinscheduler.* TO '{user}'@'localhost';
mysql> FLUSH PRIVILEGES;
注:
若出现以下错误信息,表明新建用户的密码过于简单。
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
可提高密码复杂度或者执行以下命令降低MySQL密码强度级别。
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=4;
赋予用户相应权限
mysql> GRANT ALL PRIVILEGES ON dolphinscheduler.* TO 'dolphinscheduler'@'%';
mysql> flush privileges;
如果使用 MySQL 需要手动下载 mysql-connector-java 驱动 (8.0.31) 并移动到 DolphinScheduler 的每个模块的 libs 目录下,其中包括 api-server/libs 和 alert-server/libs 和 master-server/libs 和 worker-server/libs 和 tools/libs。
注意:如果你只是想要在数据源中心使用 MySQL,则对 MySQL JDBC 驱动的版本没有要求,如果你想要将 MySQL 作为 DolphinScheduler 的元数据库, 则仅支持 8.0.16 及以上的版本。
echo /data/software/dolphinscheduler-3.2.0/master-server/libs/ /data/software/dolphinscheduler-3.2.0/alert-server/libs/ /data/software/dolphinscheduler-3.2.0/api-server/libs/ /data/software/dolphinscheduler-3.2.0/worker-server/libs/ /data/software/dolphinscheduler-3.2.0/tools/libs/ | xargs -n 1 cp -v /data/software/mysql-8.0.31/mysql-connector-j-8.0.31.jar
2.2 准备 DolphinScheduler 启动环境
- 配置用户免密及权限
如果已有haodoop集群的账号,建议直接使用,无需配置
创建部署用户,并且一定要配置 sudo 免密。以创建 hadoop 用户为例
# 创建用户需使用 root 登录
useradd hadoop
# 添加密码
echo "hadoop" | passwd --stdin hadoop
# 配置 sudo 免密
sed -i '$ahadoop ALL=(ALL) NOPASSWD: NOPASSWD: ALL' /etc/sudoers
sed -i 's/Defaults requirett/#Defaults requirett/g' /etc/sudoers
# 修改目录权限,使得部署用户对二进制包解压后的 apache-dolphinscheduler-*-bin 目录有操作权限
chown -R hadoop:hadoop apache-dolphinscheduler-*-bin
chmod -R 755 apache-dolphinscheduler-*-bin
注意:
1.因为任务执行服务是以 sudo -u {linux-user} 切换不同 linux 用户的方式来实现多租户运行作业,所以部署用户需要有 sudo 权限,而且是免密的。初学习者不理解的话,完全可以暂时忽略这一点
2.如果发现 /etc/sudoers 文件中有 “Defaults requirett” 这行,也请注释掉
- 配置机器 SSH 免密登陆
由于安装的时候需要向不同机器发送资源,所以要求各台机器间能实现 SSH 免密登陆。配置免密登陆的步骤如下
su hadoop
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
注意: 配置完成后,可以通过运行命令 ssh localhost 判断是否成功,如果不需要输入密码就能 ssh 登陆则证明成功
2.3 启动 zookeeper(hadoop集群已有无需配置)
进入 zookeeper 的安装目录,将 zoo_sample.cfg 配置文件复制到 conf/zoo.cfg,并将 conf/zoo.cfg 中 dataDir 中的值改成 dataDir=./tmp/zookeeper
# 启动 zookeeper
./bin/zkServer.sh start
2.4 修改install_env.sh 文件
文件 install_env.sh 描述了哪些机器将被安装 DolphinScheduler 以及每台机器对应安装哪些服务。您可以在路径 bin/env/install_env.sh 中找到此文件,可通过以下方式更改 env 变量,export <ENV_NAME>=,配置详情如下。
ips=${ips:-"hadoop1,hadoop2,hadoop3,hadoop4,hadoop5"}
# modify it if you use different ssh port
sshPort=${sshPort:-"xxx"}
# A comma separated list of machine hostname or IP would be installed Master server, it
# must be a subset of configuration `ips`.
# Example for hostnames: masters="ds1,ds2", Example for IPs: masters="192.168.8.1,192.168.8.2"
masters=${masters:-"hadoop1,hadoop2"}
# A comma separated list of machine <hostname>:<workerGroup> or <IP>:<workerGroup>.All hostname or IP must be a
# subset of configuration `ips`, And workerGroup have default value as `default`, but we recommend you declare behind the hosts
# Example for hostnames: workers="ds1:default,ds2:default,ds3:default", Example for IPs: workers="192.168.8.1:default,192.168.8.2:default,192.168.8.3:default"
workers=${workers:-"hadoop3:default,hadoop4:default,hadoop5:default"}
# A comma separated list of machine hostname or IP would be installed Alert server, it
# must be a subset of configuration `ips`.
# Example for hostname: alertServer="ds3", Example for IP: alertServer="192.168.8.3"
alertServer=${alertServer:-"hadoop3"}
# A comma separated list of machine hostname or IP would be installed API server, it
# must be a subset of configuration `ips`.
# Example for hostname: apiServers="ds1", Example for IP: apiServers="192.168.8.1"
apiServers=${apiServers:-"hadoop2"}
# The directory to install DolphinScheduler for all machine we config above. It will automatically be created by `install.sh` script if not exists.
# Do not set this configuration same as the current path (pwd). Do not add quotes to it if you using related path.
installPath=${installPath:-"/data/module/dolphinscheduler-3.2.0"}
# The user to deploy DolphinScheduler for all machine we config above. For now user must create by yourself before running `install.sh`
# script. The user needs to have sudo privileges and permissions to operate hdfs. If hdfs is enabled than the root directory needs
# to be created by this user
deployUser=${deployUser:-"hadoop"}
# The root of zookeeper, for now DolphinScheduler default registry server is zookeeper.
# It will delete ${zkRoot} in the zookeeper when you run install.sh, so please keep it same as registry.zookeeper.namespace in yml files.
# Similarly, if you want to modify the value, please modify registry.zookeeper.namespace in yml files as well.
zkRoot=${zkRoot:-"/dolphinscheduler"}
2.5 修改 dolphinscheduler_env.sh 文件
文件 ./bin/env/dolphinscheduler_env.sh 描述了下列配置:
DolphinScheduler 的数据库配置,详细配置方法见[初始化数据库],一些任务类型外部依赖路径或库文件,如 JAVA_HOME 和 SPARK_HOME都是在这里定义的。
如果您不使用某些任务类型,可以忽略任务外部依赖项,但必须根据您的环境更改 JAVA_HOME、注册中心和数据库相关配置。
export JAVA_HOME=${JAVA_HOME:-/data/module/jdk1.8.0_212}
# Database related configuration, set database type, username and password
export DATABASE=${DATABASE:-mysql}
export SPRING_PROFILES_ACTIVE=${DATABASE}
export SPRING_DATASOURCE_URL="jdbc:mysql://xxxx:3306/dolphinscheduler?useUnicode=true&characterEncoding=UTF-8"
export SPRING_DATASOURCE_USERNAME=xxx
export SPRING_DATASOURCE_PASSWORD=xxx
# Registry center configuration, determines the type and link of the registry center
export REGISTRY_TYPE=${REGISTRY_TYPE:-zookeeper}
export REGISTRY_ZOOKEEPER_CONNECT_STRING=${REGISTRY_ZOOKEEPER_CONNECT_STRING:-xxxx:2181,xxx:2181,xxx:2181}
export HADOOP_HOME=${HADOOP_HOME:-/data/module/hadoop-3.3.4}
export HADOOP_CONF_DIR=${HADOOP_CONF_DIR:-/data/module/hadoop-3.3.4/etc/hadoop}
export SPARK_HOME1=${SPARK_HOME1:-/data/module/spark-3.3.1}
#export SPARK_HOME2=${SPARK_HOME2:-/opt/soft/spark2}
#export PYTHON_HOME=${PYTHON_HOME:-/opt/soft/python}
export HIVE_HOME=${HIVE_HOME:-/data/module/hive-3.1.3}
export FLINK_HOME=${FLINK_HOME:-/data/module/flink-1.16.2}
export DATAX_HOME=${DATAX_HOME:-/data/module/datax}
#export SEATUNNEL_HOME=${SEATUNNEL_HOME:-/opt/soft/seatunnel}
#export CHUNJUN_HOME=${CHUNJUN_HOME:-/opt/soft/chunjun}
export PATH=$HADOOP_HOME/bin:$SPARK_HOME1/bin:$JAVA_HOME/bin:$HIVE_HOME/bin:$FLINK_HOME/bin:$DATAX_HOME/bin:$PATH
2.6 初始化数据库
完成上述步骤后,您已经为 DolphinScheduler 创建一个新数据库,并在DolphinScheduler配置好,现在你可以通过快速的 Shell 脚本来初始化数据库
bash tools/bin/upgrade-schema.sh
2.7 修改application.yaml文件
共5个文件,需要修改的部分相同,但里面其他的配置不相同,需要单独改写分别为:
- master-server/conf/application.yaml
- api-server/conf/application.yaml
- worker-server/conf/application.yaml
- alert-server/conf/application.yaml
- tools/conf/application.yaml
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://xxxx:3306/dolphinscheduler?useUnicode=true&characterEncoding=UTF-8
username: xxx
password: xxx
registry:
type: zookeeper
zookeeper:
namespace: dolphinscheduler
connect-string: xxxx
retry-policy:
base-sleep-time: 60ms
max-sleep: 300ms
max-retries: 5
session-timeout: 30s
connection-timeout: 9s
block-until-connected: 600ms
digest: ~
spring:
config:
activate:
on-profile: mysql
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql:/xxxx:3306/dolphinscheduler?useUnicode=true&characterEncoding=UTF-8
username: xxxx
password: xxxx
quartz:
properties:
org.quartz.jobStore.driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
2.8 修改common.properties文件
共5个文件,需要修改的部分相同,但里面其他的配置不相同,需要单独改写分别为:
- master-server/conf/common.properties
- api-server/conf/common.properties
- worker-server/conf/common.properties
- alert-server/conf/common.properties
- tools/conf/common.properties
data.basedir.path=自定义本地文件存储位置
resource.storage.type=HDFS
# resource store on HDFS/S3 path, resource file will store to this base path, self configuration, please make sure the directory exists on hdfs and have read write permissions. "/dolphinscheduler" is recommended
resource.storage.upload.base.path=自定义hdfs的存储位置
resource.hdfs.root.user=自定义用户名称,和本文档之前做的配置要一致
# if resource.storage.type=S3, the value like: s3a://dolphinscheduler; if resource.storage.type=HDFS and namenode HA is enabled, you need to copy core-site.xml and hdfs-site.xml to conf dir
resource.hdfs.fs.defaultFS=hdfs://xxx:8020
#高可用ip地址
yarn.resourcemanager.ha.rm.ids=xxxx,xxx
# if resourcemanager HA is enabled or not use resourcemanager, please keep the default value; If resourcemanager is single, you only need to replace ds1 to actual resourcemanager hostname
yarn.application.status.address=http://ds1:%s/ws/v1/cluster/apps/%s
# job history status url when application number threshold is reached(default 10000, maybe it was set to 1000)
yarn.job.history.status.address=http:/xxx:19888/jobhistory/logs/%s
注:本次dolphinscheduler分布式存储采用的hdfs,如需其他配置,根据官网介绍配置即可
2.9 分布式存储hdfs依赖分发
echo /data/software/dolphinscheduler-3.2.0/master-server/conf/ /data/software/dolphinscheduler-3.2.0/alert-server/conf/ /data/software/dolphinscheduler-3.2.0/api-server/conf/ /data/software/dolphinscheduler-3.2.0/worker-server/conf/ | xargs -n 1 cp -v /data/module/hadoop-3.3.4/etc/hadoop/core-site.xml /data/module/hadoop-3.3.4/etc/hadoop/hdfs-site.xml
2.10 启动 DolphinScheduler
使用上面创建的部署用户运行以下命令完成部署,部署后的运行日志将存放在 logs 文件夹内
bash ./bin/install.sh
注意: 第一次部署的话,可能出现 5 次sh: bin/dolphinscheduler-daemon.sh: No such file or directory相关信息,此为非重要信息直接忽略即可
2.11 登录 DolphinScheduler
浏览器访问地址 http://localhost:12345/dolphinscheduler/ui 即可登录系统 UI。默认的用户名和密码是 admin/dolphinscheduler123
3.起停服务
# 一键停止集群所有服务
bash ./bin/stop-all.sh
# 一键开启集群所有服务
bash ./bin/start-all.sh
# 启停 Master
bash ./bin/dolphinscheduler-daemon.sh stop master-server
bash ./bin/dolphinscheduler-daemon.sh start master-server
# 启停 Worker
bash ./bin/dolphinscheduler-daemon.sh start worker-server
bash ./bin/dolphinscheduler-daemon.sh stop worker-server
# 启停 Api
bash ./bin/dolphinscheduler-daemon.sh start api-server
bash ./bin/dolphinscheduler-daemon.sh stop api-server
# 启停 Alert
bash ./bin/dolphinscheduler-daemon.sh start alert-server
bash ./bin/dolphinscheduler-daemon.sh stop alert-server
原文链接:https://blog.csdn.net/Brother_ning/article/details/135149045
本文由 白鲸开源 提供发布支持!