使用shell脚本一键安装配置dolphinscheduler
前言:使用此脚本可以帮助您自动下载安装配置dolphinscheduler单机版,包括设置MySQL保存元数据。自动下载、解压dolphinscheduler安装包,自动修改dolphinscheduler的配置,配置MySQL连接,初始化数据库。
使用准备:需要已经安装wget和MySQL5.7,把脚本中的以下配置修改为自己的即可使用:
#dolphinscheduler安装目录
installDir="/opt/module"
#dolphinscheduler安装版本
version="3.1.5"
#MySQL驱动jar包版本,必须8.0.16及其以上
mysql_connector_version="8.0.16"
#MySQL主机ip地址
mysql_ip="192.168.198.101"
#MySQL用户名
mysql_user="root"
#MySQL密码
mysql_password="root"
1. 把下面的脚本复制保存为/tmp/install_dolphinscheduler.sh文件
#!/bin/bash# dolphinscheduler安装目录
installDir="/opt/module"
# dolphinscheduler安装版本
version="3.1.5"
# MySQL驱动jar包版本,必须8.0.16及其以上
mysql_connector_version="8.0.16"
# MySQL主机ip地址
mysql_ip="192.168.198.101"
# MySQL用户名
mysql_user="root"
# MySQL密码
mysql_password="root"
# 要创建的数据库名
db_name="dolphinscheduler"# 数据库设置操作
# 检查数据库是否存在
check_database=$(mysql -h $mysql_ip -u$mysql_user -p$mysql_password -e "SHOW DATABASES LIKE '$db_name';" | grep $db_name)
sleep 1
if [ $? -eq 0 ]; thenecho "检查数据库成功"if [ -n "$check_database" ]; then# 数据库存在,删除数据库mysql -h $mysql_ip -u$mysql_user -p$mysql_password -e "DROP DATABASE $db_name;"echo "数据库已删除"fi
elseecho "检查数据库失败,请检查数据库信息是否正确,即将退出"exit 1
fi# 创建数据库
mysql -h $mysql_ip -u$mysql_user -p$mysql_password -e "CREATE DATABASE $db_name DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;"
if [ $? -eq 0 ]; thenecho "数据库已创建"
elseecho "数据库创建失败,请再次尝试执行此脚本,即将退出"exit 1
fi
mysql -h $mysql_ip -u$mysql_user -p$mysql_password -e "GRANT ALL PRIVILEGES ON $db_name.* TO '$mysql_user'@'%' IDENTIFIED BY '$mysql_password';"
# mysql -h $mysql_ip -u$mysql_user -p$mysql_password -e "GRANT ALL PRIVILEGES ON $db_name.* TO '$mysql_user'@'localhost' IDENTIFIED BY '$mysql_password';"
mysql -h $mysql_ip -u$mysql_user -p$mysql_password -e "flush privileges;"
if [ $? -eq 0 ]; thenecho "数据库已创建"
elseecho "数据库创建失败,请再次尝试执行此脚本,即将退出"exit 1
fi# dolphinscheduler安装操作
if test -f /tmp/apache-dolphinscheduler-"$version"-bin.tar.gz; thenecho "/tmp/apache-dolphinscheduler-$version-bin.tar.gz已存在,即将进行解压"
elsewget https://archive.apache.org/dist/dolphinscheduler/$version/apache-dolphinscheduler-$version-bin.tar.gz -P /tmpif [ $? -eq 0 ]; thenecho "dolphinscheduler下载成功"elseecho "dolphinscheduler下载失败,请手动下载到/tmp目录下再次执行次脚本"echo "下载地址:https://archive.apache.org/dist/dolphinscheduler/3.1.5/apache-dolphinscheduler-3.1.5-bin.tar.gz"exit 1fi
fiif test -d "${installDir}"/apache-dolphinscheduler-"$version"-bin; thenecho "正在删除原来的dolphinscheduler..."sudo rm -rf "${installDir}"/apache-dolphinscheduler-"$version"-bin
fi
tar -zxvf /tmp/apache-dolphinscheduler-"$version"-bin.tar.gz -C "$installDir"
if [ $? -eq 0 ]; thenecho "解压成功"
elseecho "解压失败,请再次尝试执行此脚本,即将退出"exit 1
fiif test -f /tmp/mysql-connector-java-"$mysql_connector_version".jar; thenecho "/tmp/mysql-connector-java-$mysql_connector_version.jar已存在"
elsewget https://repo1.maven.org/maven2/mysql/mysql-connector-java/"$mysql_connector_version"/mysql-connector-java-"$mysql_connector_version".jar -P /tmpif [ $? -eq 0 ]; thenecho "mysql驱动下载成功"elseecho "mysql驱动下载失败,请手动下载到/tmp目录下再次执行次脚本"echo "下载地址:https://repo1.maven.org/maven2/mysql/mysql-connector-java/$mysql_connector_version/mysql-connector-java-$mysql_connector_version.jar"exit 1fi
fi
cp /tmp/mysql-connector-java-"$mysql_connector_version".jar "$installDir"/apache-dolphinscheduler-"$version"-bin/worker-server/libs
cp /tmp/mysql-connector-java-"$mysql_connector_version".jar "$installDir"/apache-dolphinscheduler-"$version"-bin/api-server/libs
cp /tmp/mysql-connector-java-"$mysql_connector_version".jar "$installDir"/apache-dolphinscheduler-"$version"-bin/alert-server/libs
cp /tmp/mysql-connector-java-"$mysql_connector_version".jar "$installDir"/apache-dolphinscheduler-"$version"-bin/master-server/libs
cp /tmp/mysql-connector-java-"$mysql_connector_version".jar "$installDir"/apache-dolphinscheduler-"$version"-bin/tools/libs
cp /tmp/mysql-connector-java-"$mysql_connector_version".jar "$installDir"/apache-dolphinscheduler-"$version"-bin/standalone-server/libs/standalone-server
if [ $? -eq 0 ]; thenecho "mysql驱动复制成功"
elseecho "mysql驱动复制失败,即将退出"exit 1
fidolphinschedulerenv='\
# Database related configuration, set database type, username and password\
export DATABASE=${DATABASE:-mysql}\
export SPRING_PROFILES_ACTIVE=${DATABASE}\
export SPRING_DATASOURCE_URL="jdbc:mysql://'"$mysql_ip"':3306/dolphinscheduler?useUnicode=true&characterEncoding=UTF-8&useSSL=false"\
export SPRING_DATASOURCE_USERNAMEE='"$mysql_user"'\
export SPRING_DATASOURCE_PASSWORD='"\"$mysql_password\""'\
\
# DolphinScheduler server related configuration'applicationyaml='\driver-class-name: com.mysql.cj.jdbc.Driver\url: jdbc:mysql://'"$mysql_ip"':3306/dolphinscheduler?useUnicode=true&characterEncoding=UTF-8\username: '"$mysql_user"'\password: '"\"$mysql_password\""''applicationyaml_tools='\driver-class-name: com.mysql.cj.jdbc.Driver\url: jdbc:mysql://'"$mysql_ip"':3306/dolphinscheduler?useUnicode=true&characterEncoding=UTF-8'applicationyaml2='\schema-locations: classpath:sql/dolphinscheduler_mysql.sql\datasource:\driver-class-name: com.mysql.cj.jdbc.Driver\url: jdbc:mysql://'"$mysql_ip"':3306/dolphinscheduler?useUnicode=true&characterEncoding=UTF-8\username: '"$mysql_user"'\password: '"\"$mysql_password\""''sed -i '/# Database related configuration/,/# DolphinScheduler server related configuration/c '"$dolphinschedulerenv"'' "$installDir/apache-dolphinscheduler-$version-bin/bin/env/dolphinscheduler_env.sh"
if [ $? -eq 0 ]; thenecho "dolphinscheduler_env.sh修改成功"
elseecho "dolphinscheduler_env.sh修改失败,即将退出"exit 1
fi
sed -i '/# Database related configuration/,/# DolphinScheduler server related configuration/c '"$dolphinschedulerenv"'' "$installDir"/apache-dolphinscheduler-"$version"-bin/standalone-server/conf/dolphinscheduler_env.sh
if [ $? -eq 0 ]; thenecho "standalone-server/conf/dolphinscheduler_env.sh修改成功"
elseecho "standalone-server/conf/dolphinscheduler_env.sh修改失败,即将退出"exit 1
fi
sed -i '/# Database related configuration/,/# DolphinScheduler server related configuration/c '"$dolphinschedulerenv"'' "$installDir"/apache-dolphinscheduler-"$version"-bin/alert-server/conf/dolphinscheduler_env.sh
if [ $? -eq 0 ]; thenecho "alert-server/conf/dolphinscheduler_env.sh修改成功"
elseecho "alert-server/conf/dolphinscheduler_env.sh修改失败,即将退出"exit 1
fi
sed -i '/# Database related configuration/,/# DolphinScheduler server related configuration/c '"$dolphinschedulerenv"'' "$installDir"/apache-dolphinscheduler-"$version"-bin/worker-server/conf/dolphinscheduler_env.sh
if [ $? -eq 0 ]; thenecho "worker-server/conf/dolphinscheduler_env.sh修改成功"
elseecho "worker-server/conf/dolphinscheduler_env.sh修改失败,即将退出"exit 1
fi
sed -i '/# Database related configuration/,/# DolphinScheduler server related configuration/c '"$dolphinschedulerenv"'' "$installDir"/apache-dolphinscheduler-"$version"-bin/api-server/conf/dolphinscheduler_env.sh
if [ $? -eq 0 ]; thenecho "api-server/conf/dolphinscheduler_env.sh修改成功"
elseecho "api-server/conf/dolphinscheduler_env.sh修改失败,即将退出"exit 1
fi
sed -i '/# Database related configuration/,/# DolphinScheduler server related configuration/c '"$dolphinschedulerenv"'' "$installDir"/apache-dolphinscheduler-"$version"-bin/master-server/conf/dolphinscheduler_env.sh
if [ $? -eq 0 ]; thenecho "master-server/conf/dolphinscheduler_env.sh修改成功"
elseecho "master-server/conf/dolphinscheduler_env.sh修改失败,即将退出"exit 1
fi
sed -i '/ driver-class-name: com.mysql/,/ password: root/c '"$applicationyaml"'' "$installDir"/apache-dolphinscheduler-"$version"-bin/standalone-server/conf/application.yaml
if [ $? -eq 0 ]; thenecho "conf/application.yaml修改成功"
elseecho "conf/application.yaml修改失败,即将退出"exit 1
fised -i '/ schema-locations: classpath:sql\/dolphinscheduler_h2.sql/,/ password: ""/c '"$applicationyaml2"'' "$installDir"/apache-dolphinscheduler-"$version"-bin/standalone-server/conf/application.yaml
if [ $? -eq 0 ]; thenecho "conf/application.yaml修改成功"
elseecho "conf/application.yaml修改失败,即将退出"exit 1
fi
sed -i '/ driver-class-name: com.mysql/,/ password: root/c '"$applicationyaml"'' "$installDir"/apache-dolphinscheduler-"$version"-bin/worker-server/conf/application.yaml
if [ $? -eq 0 ]; thenecho "worker-server/conf/application.yaml修改成功"
elseecho "worker-server/conf/application.yaml修改失败,即将退出"exit 1
fi
sed -i '/ driver-class-name: com.mysql/,/ password: root/c '"$applicationyaml"'' "$installDir"/apache-dolphinscheduler-"$version"-bin/api-server/conf/application.yaml
if [ $? -eq 0 ]; thenecho "api-server/conf/application.yaml修改成功"
elseecho "api-server/conf/application.yaml修改失败,即将退出"exit 1
fi
sed -i '/ driver-class-name: com.mysql/,/ password: root/c '"$applicationyaml"'' "$installDir"/apache-dolphinscheduler-"$version"-bin/alert-server/conf/application.yaml
if [ $? -eq 0 ]; thenecho "alert-server/conf/application.yaml修改成功"
elseecho "alert-server/conf/application.yaml修改失败,即将退出"exit 1
fi
sed -i '/ driver-class-name: com.mysql/,/ password: root/c '"$applicationyaml"'' "$installDir"/apache-dolphinscheduler-"$version"-bin/master-server/conf/application.yaml
if [ $? -eq 0 ]; thenecho "master-server/conf/application.yaml修改成功"
elseecho "master-server/conf/application.yaml修改失败,即将退出"exit 1
fi
sed -i '/ driver-class-name: com.mysql/,/characterEncoding=UTF-8/c '"$applicationyaml_tools"'' "$installDir"/apache-dolphinscheduler-"$version"-bin/tools/conf/application.yaml
if [ $? -eq 0 ]; thenecho "tools/conf/application.yaml修改成功"
elseecho "tools/conf/application.yaml修改失败,即将退出"exit 1
fibash "$installDir"/apache-dolphinscheduler-"$version"-bin/tools/bin/upgrade-schema.sh
if [ $? -eq 0 ]; thenecho "初始化数据库成功"
elseecho "初始化数据库失败,即将退出"exit 1
fi# 设置dolphinscheduler用户环境变量
if test -n "$(grep '#DOLPHINSCHEDULER_HOME' ~/.bashrc)"; thenecho "DOLPHINSCHEDULER_HOME已存在"
elseecho >> ~/.bashrcecho '#DOLPHINSCHEDULER_HOME' >> ~/.bashrcecho "export DOLPHINSCHEDULER_HOME=$installDir/apache-dolphinscheduler-$version-bin" >> ~/.bashrcecho 'export PATH=$PATH:$DOLPHINSCHEDULER_HOME/bin' >> ~/.bashrc
fi#rm -f /tmp/mysql-connector-java-"$mysql_connector_version".jar
#rm -rf /tmp/apache-dolphinscheduler-"$version"-bin.tar.gz
echo "dolphinscheduler安装完成"
"$installDir"/apache-dolphinscheduler-"$version"-bin/bin/dolphinscheduler-daemon.sh start standalone-server
if [ $? -eq 0 ]; thenecho "dolphinscheduler单机版启动成功"ip_addr=$(ip addr | grep 'inet ' | awk '{print $2}'| tail -n 1 | grep -oP '\d+\.\d+\.\d+\.\d+')echo "浏览器访问地址:http://$ip_addr:12345/dolphinscheduler/ui/login"echo "登录账号:admin"echo "登录密码:dolphinscheduler123"
elseecho "dolphinscheduler单机版启动失败,请查看日志"exit 1
fiexit 0
2. 增加执行权限
chmod a+x /tmp/dolphinscheduler.sh
3. 执行/tmp/dolphinscheduler.sh
/tmp/dolphinscheduler.sh
执行之后等待下载、安装、配置完成,如下图:
浏览器访问dolphinscheduler:http://192.168.198.101:12345/dolphinscheduler
如下图:
登录进入如图:
4. 加载环境变量
source ~/.bashrc
5.启动/停止dolphinscheduler
因为再脚本中已经启动,所以不需要再启动
停止dolphinscheduler
dolphinscheduler-daemon.sh stop standalone-server
启动dolphinscheduler
dolphinscheduler-daemon.sh start standalone-server
本期文章到此结束