一、环境准备
1.1准备四台机器
| 服务器 | IP | 软件 | 描述 |
|---|---|---|---|
| gitlab | 10.0.0.101 | gitlab-ce:19.6.2-ce.0,git:2.56.1 | 代码仓库服务器 |
| jenkins | 10.0.0.100 | jenkins:2.580.3,git:2.56.1 | 持续集成服务器 |
| 测试服务器 web02 | 10.0.0.102 | ubuntu2404 | 测试环境使用 |
| 生产服务器 web03 | 10.0.0.103 | ubuntu2404 | 生产环境使用 |
#改名
[root@ubuntu2404 ~]#hostnamectl set-hostname web02 # 102
[root@ubuntu2404 ~]#exit
[root@web02 ~]#
[root@ubuntu2404 ~]#hostnamectl set-hostname web03 # 103
[root@ubuntu2404 ~]#exit
[root@web03 ~]#
[root@ubuntu2404 ~]#hostnamectl set-hostname jenkins # 100
[root@ubuntu2404 ~]#exit
[root@jenkins ~]#
[root@ubuntu2404 ~]#hostnamectl set-hostname gitlab # 101
[root@ubuntu2404 ~]#exit
[root@gitlab ~]#
#域名解析
[root@gitlab ~]#cat /etc/hosts
10.0.0.101 gitlab.chenchengpei.cn
[root@jenkins ~]#cat /etc/hosts
10.0.0.100 jenkins.chenchengpei.cn
10.0.0.101 gitlab.chenchengpei.cn
10.0.0.102 web02.chenchengpei.cn
10.0.0.103 web03.chenchengpei.cn
#提前把指纹写进 known_hosts
[root@jenkins ~]#vim /etc/ssh/ssh_config
StrictHostKeyChecking no
# 在 Jenkins上预先添加目标主机指纹
# 切到 jenkins 用户执行
[root@jenkins ~]#su - jenkins -s /bin/bash
jenkins@jenkins:~$
jenkins@jenkins:~$ ssh-keyscan -H 10.0.0.102 >> ~/.ssh/known_hosts
jenkins@jenkins:~$ ssh-keyscan -H 10.0.0.103 >> ~/.ssh/known_hosts
jenkins@jenkins:~$ exit
logout
[root@jenkins ~]#
1.2插件与凭据清单(确认已安装)
| 插件 | 用途 |
|---|---|
| Git Parameter | 构建页面动态下拉选择分支/Tag |
| Git plugin | 源码管理拉代码(已有) |
| GitLab Plugin | Webhook触发 + 构建状态回写GitLab |
| SSH Credentials | SSH私钥凭据(已配置) |
系统管理 → 插件管理 → 已安装,确认以上都在。
凭据确认:
gitlab-xiaoming-sshkey(Username =git,Private Key = xiaoming 的私钥)
1.3Gitlab 导入项目
#项目链接:https://gitee.com/lbtooth/spring-boot-helloworld.git
chen用户登录 → 点击主页(左上角小狐狸图标)→ 群组 devops → 新建项目 → 导入项目 → 通过URL导入仓库
Git 仓库 URL:https://gitee.com/lbtooth/spring-boot-helloworld.git
项目名称:Spring Boot Helloworld
群组:devops
项目标识:spring-boot-helloworld
可见性级别:私有
导入完成后,确认 SSH 克隆地址是:git@gitlab.chenchengpei.cn:devops/spring-boot-helloworld.git
1.4在目标主机安装 Java 环境
[root@web02 ~]#apt update && apt -y install openjdk-21-jre-headless
[root@web03 ~]#apt update && apt -y install openjdk-21-jre-headless
# 验证
[root@web02 ~]#java -version
openjdk version "21.0.13.1" 2026-11-17
OpenJDK Runtime Environment (build 21.0.13.1+2-1-24.04.1-Ubuntu)
OpenJDK 64-Bit Server VM (build 21.0.13.1+2-1-24.04.1-Ubuntu, mixed mode, sharing)
[root@web02 ~]#
[root@web03 ~]#java -version
openjdk version "21.0.13.1" 2026-11-17
OpenJDK Runtime Environment (build 21.0.13.1+2-1-24.04.1-Ubuntu)
OpenJDK 64-Bit Server VM (build 21.0.13.1+2-1-24.04.1-Ubuntu, mixed mode, sharing)
[root@web03 ~]#
💡 目标机器只需 JRE(运行 jar),不需要 JDK(编译在 Jenkins 上做)。
1.5Jenkins 服务器安装 Maven 并配置镜像加速
[root@jenkins ~]#apt update && apt -y install openjdk-21-jdk && apt -y install maven
#镜像加速
[root@jenkins ~]#vim /etc/maven/settings.xml
#在 <mirrors> 标签内添加:
</mirrors>
......
<blocked>true</blocked>
</mirror>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>central</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>
<!-- profiles
......
#验证:
[root@jenkins ~]#mvn -v
Apache Maven 3.8.7
Maven home: /usr/share/maven
Java version: 21.0.13.1, vendor: Ubuntu, runtime: /usr/lib/jvm/java-21-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "6.8.0-147-generic", arch: "amd64", family: "unix"
[root@jenkins ~]#
#打印 Maven 最终生效的完整配置
[root@jenkins ~]#mvn help:effective-settings
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd">
<localRepository>/root/.m2/repository</localRepository>
<mirrors>
<mirror>
<mirrorOf>external:http:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0/</url>
<blocked>true</blocked>
<id>maven-default-http-blocker</id>
</mirror>
<mirror>
<mirrorOf>central</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
<id>aliyunmaven</id>
</mirror>
</mirrors>
<pluginGroups>
<pluginGroup>org.apache.maven.plugins</pluginGroup>
<pluginGroup>org.codehaus.mojo</pluginGroup>
</pluginGroups>
</settings>
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.260 s
[INFO] Finished at: 2026-12-03T11:56:31+08:00
[INFO] ------------------------------------------------------------------------
1.6Jenkins 全局工具配置(JDK / Maven / Git)
[root@jenkins ~]#git -v
git version 2.56.1
[root@jenkins ~]#which git
/usr/bin/git
系统管理 → 全局工具配置:
- JDK:别名
JDK-21,JAVA_HOME/usr/lib/jvm/java-21-openjdk-amd64- Maven:别名
Maven-3.8,MAVEN_HOME/usr/share/maven- Git:Name
Git-2.56,Path/usr/bin/git
1.7 Jenkins → 目标服务器 SSH 免密(关键!不做会卡死)
# 以 jenkins 用户生成密钥
[root@jenkins ~]#sudo -iu jenkins
jenkins@jenkins:~$
jenkins@jenkins:~$ ssh-keygen -t ed25519 -N "" -f /var/lib/jenkins/.ssh/id_ed25519
# 分发公钥到两台目标机器
jenkins@jenkins:~$ ssh-copy-id root@10.0.0.102
jenkins@jenkins:~$ ssh-copy-id root@10.0.0.103
# 测试(不输密码能通就对了)
jenkins@jenkins:~$ ssh root@10.0.0.102 "hostname && java -version"
web02
openjdk version "21.0.13.1" 2026-11-17
OpenJDK Runtime Environment (build 21.0.13.1+2-1-24.04.1-Ubuntu)
OpenJDK 64-Bit Server VM (build 21.0.13.1+2-1-24.04.1-Ubuntu, mixed mode, sharing)
jenkins@jenkins:~$
jenkins@jenkins:~$ ssh root@10.0.0.103 "hostname && java -version"
web03
openjdk version "21.0.13.1" 2026-11-17
OpenJDK Runtime Environment (build 21.0.13.1+2-1-24.04.1-Ubuntu)
OpenJDK 64-Bit Server VM (build 21.0.13.1+2-1-24.04.1-Ubuntu, mixed mode, sharing)
jenkins@jenkins:~$
#在目标机器上提前创建部署目录:
jenkins@jenkins:~$ ssh root@10.0.0.102 "mkdir -p /data/spring-boot-helloworld"
jenkins@jenkins:~$ ssh root@10.0.0.103 "mkdir -p /data/spring-boot-helloworld"
jenkins@jenkins:~$ exit
logout
1.8准备部署脚本(支持参数化 + 部署 + 回滚)
[root@jenkins ~]#mkdir -p /data/jenkins/scripts/
[root@jenkins ~]#cat /data/jenkins/scripts/spring-boot-helloworld.sh
#!/bin/bash
#
#********************************************************************
#Author: 陈承沛
#WebSite chenchengpei.cn
#QQ: 2088346053
#Date: 2026-12-03
#FileName: /data/jenkins/scripts/spring-boot-helloworld.sh
#Description: Spring Boot Helloworld 部署/回滚脚本
#Copyright (C): 2026 All Rights Reserved
#********************************************************************
#提前在目标服务器上手动创建下面目录
APP=spring-boot-helloworld
APP_PATH=/data/${APP}
PORT=8888
WORKSPACE_ARCHIVE=${WORKSPACE}/archive
echo "=============================================="
echo " 操作类型 : ${OPERATION}"
echo " 标签 : ${TAG}"
echo " 环境 : ${DEPLOY_ENV}"
echo " 回滚构建号: ${ROLLBACK_BUILD:-(自动=上一版)}"
echo " 当前构建号: ${BUILD_NUMBER}"
echo " 工作目录 : $(pwd)"
echo "=============================================="
# ============ 根据环境选择目标主机 ============
case ${DEPLOY_ENV} in
prod)
HOST_LIST="10.0.0.103"
;;
dev|test)
HOST_LIST="10.0.0.102"
;;
*)
echo "❌ 未知环境: ${DEPLOY_ENV}"
exit 1
;;
esac
# ============ 部署 ============
if [ "${OPERATION}" == "deploy" ]; then
echo ">>> [1/4] Maven 编译打包..."
mvn clean package -Dmaven.test.skip=true
if [ $? -ne 0 ]; then
echo "❌ Maven 编译失败!中止部署"
exit 1
fi
echo "✅ 编译成功"
echo ">>> [2/4] 归档制品(供回滚使用)..."
mkdir -p ${WORKSPACE_ARCHIVE}
cp target/${APP}-*-SNAPSHOT.jar ${WORKSPACE_ARCHIVE}/${APP}.jar
echo "✅ 已归档到 ${WORKSPACE_ARCHIVE}/"
echo ">>> [3/4] 部署到目标服务器..."
for host in ${HOST_LIST}; do
echo " >> 部署到 ${host}..."
ssh root@${host} "mkdir -p ${APP_PATH}"
ssh root@${host} "pkill -f ${APP}.jar 2>/dev/null || true"
sleep 2
scp target/${APP}-*-SNAPSHOT.jar root@${host}:${APP_PATH}/${APP}.jar
ssh root@${host} "nohup java -jar ${APP_PATH}/${APP}.jar --server.port=${PORT} &>/dev/null &"
echo " ✅ ${host} 部署完成"
done
echo ">>> [4/4] 健康检查..."
for host in ${HOST_LIST}; do
sleep 8
echo " >> 检查 ${host}..."
ssh root@${host} "ps -ef | grep ${APP}.jar | grep -v grep && echo ' ✅ 进程正常' || echo ' ⚠️ 进程未检测到'"
ssh root@${host} "ss -tlnp | grep ${PORT} && echo ' ✅ 端口 ${PORT} 监听中' || echo ' ⚠️ 端口未监听'"
done
# ============ 回滚 ============
elif [ "${OPERATION}" == "rollback" ]; then
echo ">>> [1/4] 确定回滚目标..."
if [ -n "${ROLLBACK_BUILD}" ]; then
TARGET=${ROLLBACK_BUILD}
else
TARGET=$((BUILD_NUMBER - 1))
fi
echo " 回滚到构建 #${TARGET}"
# 兼容 Jenkins 归档路径(可能多一层 archive/ 目录)
JOB_BUILD_ARCHIVE="/var/lib/jenkins/jobs/${JOB_NAME}/builds/${TARGET}/archive"
if [ -f "${JOB_BUILD_ARCHIVE}/${APP}.jar" ]; then
ARCHIVE_JAR="${JOB_BUILD_ARCHIVE}/${APP}.jar"
elif [ -f "${JOB_BUILD_ARCHIVE}/archive/${APP}.jar" ]; then
ARCHIVE_JAR="${JOB_BUILD_ARCHIVE}/archive/${APP}.jar"
else
echo "❌ 找不到构建 #${TARGET} 的归档文件!"
echo " 已尝试路径:"
echo " ${JOB_BUILD_ARCHIVE}/${APP}.jar"
echo " ${JOB_BUILD_ARCHIVE}/archive/${APP}.jar"
echo " 请确认该构建存在且编译成功"
exit 1
fi
echo ">>> [2/4] 归档文件确认..."
echo " ${ARCHIVE_JAR}"
ls -lh ${ARCHIVE_JAR}
echo ">>> [3/4] 回滚到目标服务器..."
for host in ${HOST_LIST}; do
echo " >> 回滚 ${host} 到构建 #${TARGET}..."
scp ${ARCHIVE_JAR} root@${host}:${APP_PATH}/${APP}.jar
ssh root@${host} "pkill -f ${APP}.jar 2>/dev/null || true"
sleep 2
ssh root@${host} "nohup java -jar ${APP_PATH}/${APP}.jar --server.port=${PORT} &>/dev/null &"
echo " ✅ ${host} 回滚完成"
done
echo ">>> [4/4] 健康检查..."
for host in ${HOST_LIST}; do
sleep 8
echo " >> 检查 ${host}..."
ssh root@${host} "ps -ef | grep ${APP}.jar | grep -v grep && echo ' ✅ 进程正常' || echo ' ⚠️ 进程未检测到'"
done
else
echo "❌ 未知操作: ${OPERATION}"
exit 1
fi
echo "=============================================="
echo " ✅ 操作完成!"
echo "=============================================="
[root@jenkins ~]#chmod +x /data/jenkins/scripts/spring-boot-helloworld.sh
🔑 脚本要点说明:
${JOB_NAME} 自动适配任务名,换任务名也不用改脚本
pkill -f ${APP}.jar 精确匹配,不会误杀其他 Java 进程
回滚时把归档的 jar scp 到目标机器,而不只是替换 Jenkins 本地
部署和回滚都有健康检查(进程 + 端口)
二、配置步骤
2.1新建任务
首页 → 新建任务 → 名称填 freestyle-spring-boot-helloworld → 选 Freestyle project → 确定
2.2勾选参数化构建
2.2.1参数化构建前置说明
Jenkins 支持参数化构建,类似脚本传参,可实现灵活的构建任务。
启用方式:Job → Configure → 勾选 "This project is parameterized" → Add Parameter 下拉选择类型
所有参数在构建中默认作为环境变量暴露(名称大小写敏感,建议全大写)。
常用的参数类型
- Boolean Parameter 布尔值参数
- Choice Parameter 选项参数
- Credentials Parameter 凭据参数
- File Parameter 文件参数
- Multi-line String Parameter 多行字符串参数
- Password Parameter 密码参数
- Run Parameter 运行参数
- String Parameter 字符串参数
- Git Parameter Git参数
- String Parameter(字符串参数)
是什么:最基础的单行文本输入框
| 配置项 | 说明 |
|---|---|
| Name | 参数名(如 BRANCH_NAME) |
| Default Value | 默认值(如 main) |
| Description | 描述提示 |
适用场景:分支名、版本号、环境名、任意单行文本输入
踩坑:只能单行,不能换行;空格要 URL 转义
构建中使用:
# Shell
echo $BRANCH_NAME
# 或
echo "Building branch: ${BRANCH_NAME}"
- Boolean Parameter(布尔值参数)
是什么:勾选框,返回 true / false
| 配置项 | 说明 |
|---|---|
| Name | 参数名(如 RUN_TESTS) |
| Default Value | 默认勾选/不勾选 |
| Description | 描述 |
适用场景:是否执行测试、是否发送通知、是否部署生产(开关类控制)
构建中使用:
# Shell
if [ "$RUN_TESTS" = "true" ]; then
pytest
else
echo "Skipping tests"
fi
- Choice Parameter(选项参数)
是什么:下拉单选框,从预定义列表选一个
| 配置项 | 说明 |
|---|---|
| Name | 参数名(如 ENV) |
| Choices | 选项列表(每行一个值) |
| Description | 描述 |
Choices 填写示例:
dev
test
staging
prod
适用场景:环境选择、版本选择、操作类型选择(deploy/rollback/restart)
构建中使用:
# Shell
echo "Deploying to $ENV environment"
- Password Parameter(密码参数)
是什么:密码输入框,输入时显示为星号 **,日志中自动脱敏
| 配置项 | 说明 |
|---|---|
| Name | 参数名(如 DB_PASSWORD) |
| Default Value | 可留空(安全起见不留) |
| Description | 描述 |
适用场景:数据库密码、API Token、密钥等敏感值
构建中使用:
# Shell
mysql -u root -p$DB_PASSWORD -e "SHOW DATABASES;"
⚠️ 注意:
- 日志中不会明文打印(Jenkins 自动 mask)
- 但如果你
echo $DB_PASSWORD,Jenkins 会尝试 mask 为**** - 比 String Parameter 安全,因为不会明文显示在构建参数页面
- Credentials Parameter(凭据参数) 推荐
是什么:从 Jenkins Credentials Store 中选择一个已存储的凭据,不直接暴露密钥内容
| 配置项 | 说明 |
|---|---|
| Name | 参数名(如 GIT_CRED) |
| Credential Type | 选择凭据类型(SSH Username with private key / Secret text / Username with password) |
| Default Value | 默认凭据 ID |
| Description | 描述 |
适用场景:SSH 私钥、API Token、Docker Registry 凭据、K8s kubeconfig → 生产环境首选
构建中使用(Pipeline 推荐方式):
withCredentials([sshUserPrivateKey(credentialsId: params.GIT_CRED, keyFileVariable: 'SSH_KEY')]) {
sh 'git clone git@github.com:org/repo.git --config core.sshCommand="ssh -i $SSH_KEY"'
}
⚠️ 关键区别:
| Password Parameter | Credentials Parameter | |
|---|---|---|
| 值是否明文可见 | 构建页面能看到 **** | 完全不可见,只传 ID |
| 是否存储在凭据库 | 否 | 是(集中管理、可轮换) |
| 安全性 | 中 | 高 |
- Multi-line String Parameter(多行字符串参数)
是什么:多行文本输入框(类似 <textarea>)
| 配置项 | 说明 |
|---|---|
| Name | 参数名(如 SQL_SCRIPT) |
| Default Value | 默认多行文本 |
| Description | 描述 |
适用场景:
- 粘贴 SQL 脚本
- 粘贴 YAML/JSON 配置
- 粘贴多行命令
- 批量 IP 列表
踩坑:
- 换行符在 Shell 变量展开时可能出问题,建议写文件再执行
- 内容含
$会被 Shell 二次展开,用'EOF'(单引号)包裹
构建中使用:
# Shell
cat > /tmp/script.sql << 'EOF'
$SQL_SCRIPT
EOF
mysql -u root < /tmp/script.sql
- File Parameter(文件参数)
是什么:构建触发时上传一个文件,文件放到 workspace 指定路径
| 配置项 | 说明 |
|---|---|
| Name | 参数名(如 UPLOAD_FILE) |
| File Location | workspace 中的存放路径(如 config.yaml) |
| Description | 描述 |
适用场景:上传配置文件、上传部署包(zip/tar)、上传证书、上传 CSV 批量数据
构建中使用:
# Shell
ls -lh $UPLOAD_FILE
cat $UPLOAD_FILE
cp $UPLOAD_FILE /opt/app/config.yaml
⚠️ 注意:
- 文件在 checkout/update 之后才放到 workspace
- 每次构建会覆盖同名文件
- 不能通过 URL 触发时传文件(只能页面手动上传或 API multipart)
- Run Parameter(运行参数)
是什么:选择另一个 Job 的某次构建作为参数(引用历史构建)
| 配置项 | 说明 |
|---|---|
| Name | 参数名(如 BASE_BUILD) |
| Project | 选择目标 Job 名称 |
| Description | 描述 |
适用场景:
- 下游 Job 引用上游 Job 的构建产物
- 选择某个已验证通过的构建版本进行部署
- 回滚到某次历史构建
踩坑:URL 传值时格式必须是 jobname%2399(# 转义为 %23)
构建中使用:
# 获取被引用构建的信息
echo "Base build number: ${BASE_BUILD}"
# 实际值是 "jobname#buildNumber" 格式
- **Git Parameter(Git参数) **
是什么:从指定的 Git 仓库实时拉取分支、Tag、Commit、PR 列表,以可视化的方式(下拉框/单选/多选)展示在构建页面上
插件全名:Git Parameter Plug-In
核心价值:避免手敲分支名拼错、不用维护分支列表、和 Git 仓库实时同步。
| 配置项 | 类型 | 说明 | 示例 |
|---|---|---|---|
| Name | 文本 | 参数名,也是环境变量名,Pipeline 中用 params.xxx 引用 | BRANCH、TAG |
| Description | 文本 | 构建页面上的提示文字 | 选择要构建的分支 |
| Parameter Type | 下拉选择 | 决定列出什么内容(见下方类型表) | Branch |
| Default Value | 文本 | 默认选中项,留空则无默认 | main、origin/main、v1.0.0 |
| Branch / Tag Filter | 正则 | 过滤显示的分支或 Tag | origin/(.*)、v.* |
| Sort Mode | 下拉选择 | 排序方式:NONE、ASCENDING、DESCENDING | DESCENDING(新版在前) |
| Maximum Number | 数字 | 最多显示多少条(防过多卡死) | 100 |
| Use Repository | URL | 指定从哪个仓库拉取列表(多仓库场景) | git@gitlab.com:org/repo.git |
| Quick Filter | 勾选 | 启用搜索框,分支多时可模糊搜索 | 勾选 |
| Selected Value | 下拉 | 默认选中逻辑:NONE、TOP、DEFAULT | DEFAULT |
Parameter Type 类型对照
| 类型 | Pipeline 常量 | 列出内容 | 适用场景 |
|---|---|---|---|
| Branch | PT_BRANCH | 所有分支 | 选分支构建 |
| Tag | PT_TAG | 所有 Tag | 选版本发布 |
| Revision | PT_REVISION | Commit Hash | 回滚到指定提交 |
| Pull Request | PT_PULL_REQUEST | PR 编号 | PR 构建验证 |
| Branch + Tag | PT_BRANCH_TAG | 分支和 Tag 混合 | 混合选择 |
适用场景:
| 场景 | 用法 | 示例 |
|---|---|---|
| 多分支构建 | 下拉选分支,不用手敲 | 开发选 feature/login,测试选 develop |
| 版本发布 | 选 Tag 触发发布流水线 | 选 v1.2.0 → 编译 → 打镜像 → 部署 |
| 回滚 | 选 Revision(commit hash)回滚 | 选 a1b2c3d → 部署到指定版本 |
| PR 验证 | 选 PR 编号触发构建 | Code Review 时自动跑测试 |
| 多环境部署 | Git Parameter + Choice 参数组合 | 选分支 + 选环境(dev/test/prod) |
| 手动触发补充 Webhook | Webhook 自动触发 + 手动选分支兜底 | push 自动构建,特殊情况手动选分支 |
构建中使用:
echo "Building branch: $BRANCH"
git checkout $BRANCH
mvn clean package
2.2.2参数化构建配置(共 4 个)
勾选 This project is parameterized,依次添加:
参数①:Git Parameter(选标签)
| 字段 | 值 |
|---|---|
| Name | TAG |
| Description | 选择要部署的标签 |
| Parameter Type | Tag |
| Default Value | main |
| Sort Mode | DESCENDING |
| Quick Filter | 勾选 |
| Use Repository | (留空,用任务里的源码管理仓库) |
参数②:Choice Parameter(操作类型)
| 字段 | 值 |
|---|---|
| Name | OPERATION |
| Choices | deploy 回车 rollback |
| Description | deploy=部署新版本 / rollback=回滚到历史版本 |
参数③:Choice Parameter(部署环境)
| 字段 | 值 |
|---|---|
| Name | DEPLOY_ENV |
| Choices | dev 回车 test 回车 prod |
| Description | dev/test → 10.0.0.102,prod → 10.0.0.103 |
参数④:String Parameter(回滚构建号)
| 字段 | 值 |
|---|---|
| Name | ROLLBACK_BUILD |
| Default Value | (留空) |
| Description | 回滚时填构建号(如 15),留空 = 回滚到上一版 |
2.3源码管理(Git)
| 字段 | 值 |
|---|---|
| Git | 勾选 |
| Repository URL | git@gitlab.chenchengpei.cn:devops/spring-boot-helloworld.git |
| Credentials | gitlab-xiaoming-sshkey |
| Branches to build | refs/tags/${TAG} |
⚠️ 关键:
- 用
refs/tags/${TAG}明确指定 tag 引用,避免 Git Parameter 返回的 tag 值带不带refs/tags/前缀导致 checkout 失败- 回滚时源码管理仍会检出
${TAG}对应的代码,但脚本不会用这份代码(直接用归档 jar),不影响回滚结果
2.4构建步骤(核心)
点 Add build step → Execute shell,粘贴以下内容:
bash -x /data/jenkins/scripts/spring-boot-helloworld.sh
2.5 构建后操作
① 归档制品(回滚依赖这一步,必须配)
Add post-build action → Archive the artifacts
| 字段 | 值 |
|---|---|
| Files to archive | archive/*.jar |
② 丢弃旧构建(防磁盘爆满)
Add post-build action → Discard old builds
| 字段 | 值 |
|---|---|
| Days to keep builds | 7 |
| Max # of builds to keep | 20 |
| Days to keep artifacts | 7 |
| Max # of builds to keep with artifacts | 10 |
2.6 保存
点 Save。
三、使用方式
3.1 打标签(GitLab 上操作)
项目首次部署前需要至少打一个 tag:
[root@gitlab data]#pwd
/data
[root@gitlab data]#ls
myapp
# 本地 clone 后
git tag v1.0
git push origin v1.0
[root@gitlab data]#git clone git@gitlab.chenchengpei.cn:devops/spring-boot-helloworld.git
[root@gitlab data]#cd spring-boot-helloworld/
[root@gitlab spring-boot-helloworld]#ls
[root@gitlab spring-boot-helloworld]#vim src/main/java/com/neo/controller/HelloWorldController.java
return "version v0.6\n";
改为 return "version v1.0\n";
[root@gitlab spring-boot-helloworld]#git tag
v0.1
v0.2
v0.3
v0.4
v0.5
v0.6
[root@gitlab spring-boot-helloworld]#git commit -am “v1.0”
[root@gitlab spring-boot-helloworld]#git push --all
[root@gitlab spring-boot-helloworld]#git tag v1.0
[root@gitlab spring-boot-helloworld]#git push --tags
# 后续版本
git tag v1.1
git push origin v1.1
[root@gitlab spring-boot-helloworld]#vim src/main/java/com/neo/controller/HelloWorldController.java
return "version v1.0\n";
改为 return "version v1.1\n";
[root@gitlab spring-boot-helloworld]#git commit -am “v1.1”
[root@gitlab spring-boot-helloworld]#git tag v1.1
[root@gitlab spring-boot-helloworld]#git push --tags
[root@gitlab spring-boot-helloworld]#git push --all
Git Parameter 首次可能显示为空,先手填 v1.0 跑一次,之后下拉框就有数据了。
3.2 部署
Build with Parameters:
TAG: [v1.0 ▼] ← 下拉选标签
OPERATION: [deploy ▼]
DEPLOY_ENV: [test ▼] ← prod→103, dev/test→102
ROLLBACK_BUILD: (留空)
→ Build
Build with Parameters:
TAG: [v1.0 ▼] ← 下拉选标签
OPERATION: [deploy ▼]
DEPLOY_ENV: [prod ▼] ← prod→103, dev/test→102
ROLLBACK_BUILD: (留空)
→ Build
Build with Parameters:
TAG: [v1.1 ▼] ← 下拉选标签
OPERATION: [deploy ▼]
DEPLOY_ENV: [test ▼] ← prod→103, dev/test→102
ROLLBACK_BUILD: (留空)
→ Build
Build with Parameters:
TAG: [v1.1 ▼] ← 下拉选标签
OPERATION: [deploy ▼]
DEPLOY_ENV: [prod ▼] ← prod→103, dev/test→102
ROLLBACK_BUILD: (留空)
→ Build
部署v1.0到test→102

部署v1.0到prod→103

部署v1.1到test→102

部署v1.1到prod→103

控制台部署输出:
#部署v1.0到test→102控制台输出:
+ echo '✅ 编译成功'
✅ 编译成功
+ echo '>>> [2/4] 归档制品(供回滚使用)...'
>>> [2/4] 归档制品(供回滚使用)...
+ mkdir -p /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive
+ cp target/spring-boot-helloworld-0.6-SNAPSHOT.jar /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive/spring-boot-helloworld.jar
+ echo '✅ 已归档到 /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive/'
✅ 已归档到 /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive/
+ echo '>>> [3/4] 部署到目标服务器...'
>>> [3/4] 部署到目标服务器...
+ for host in ${HOST_LIST}
+ echo ' >> 部署到 10.0.0.102...'
>> 部署到 10.0.0.102...
+ ssh root@10.0.0.102 'mkdir -p /data/spring-boot-helloworld'
+ ssh root@10.0.0.102 'pkill -f spring-boot-helloworld.jar 2>/dev/null || true'
+ sleep 2
+ scp target/spring-boot-helloworld-0.6-SNAPSHOT.jar root@10.0.0.102:/data/spring-boot-helloworld/spring-boot-helloworld.jar
+ ssh root@10.0.0.102 'nohup java -jar /data/spring-boot-helloworld/spring-boot-helloworld.jar --server.port=8888 &>/dev/null &'
+ echo ' ✅ 10.0.0.102 部署完成'
✅ 10.0.0.102 部署完成
+ echo '>>> [4/4] 健康检查...'
>>> [4/4] 健康检查...
+ for host in ${HOST_LIST}
+ sleep 8
+ echo ' >> 检查 10.0.0.102...'
>> 检查 10.0.0.102...
+ ssh root@10.0.0.102 'ps -ef | grep spring-boot-helloworld.jar | grep -v grep && echo '\'' ✅ 进程正常'\'' || echo '\'' ⚠️ 进程未检测到'\'''
root 8792 1 99 12:14 ? 00:00:14 java -jar /data/spring-boot-helloworld/spring-boot-helloworld.jar --server.port=8888
✅ 进程正常
+ ssh root@10.0.0.102 'ss -tlnp | grep 8888 && echo '\'' ✅ 端口 8888 监听中'\'' || echo '\'' ⚠️ 端口未监听'\'''
LISTEN 0 100 *:8888 *:* users:(("java",pid=8792,fd=17))
✅ 端口 8888 监听中
+ echo ==============================================
==============================================
+ echo ' ✅ 操作完成!'
✅ 操作完成!
+ echo ==============================================
==============================================
Archiving artifacts
Finished: SUCCESS
#部署v1.0到prod→103控制台输出:
+ echo '✅ 编译成功'
✅ 编译成功
+ echo '>>> [2/4] 归档制品(供回滚使用)...'
>>> [2/4] 归档制品(供回滚使用)...
+ mkdir -p /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive
+ cp target/spring-boot-helloworld-0.6-SNAPSHOT.jar /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive/spring-boot-helloworld.jar
+ echo '✅ 已归档到 /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive/'
✅ 已归档到 /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive/
+ echo '>>> [3/4] 部署到目标服务器...'
>>> [3/4] 部署到目标服务器...
+ for host in ${HOST_LIST}
+ echo ' >> 部署到 10.0.0.103...'
>> 部署到 10.0.0.103...
+ ssh root@10.0.0.103 'mkdir -p /data/spring-boot-helloworld'
+ ssh root@10.0.0.103 'pkill -f spring-boot-helloworld.jar 2>/dev/null || true'
+ sleep 2
+ scp target/spring-boot-helloworld-0.6-SNAPSHOT.jar root@10.0.0.103:/data/spring-boot-helloworld/spring-boot-helloworld.jar
+ ssh root@10.0.0.103 'nohup java -jar /data/spring-boot-helloworld/spring-boot-helloworld.jar --server.port=8888 &>/dev/null &'
+ echo ' ✅ 10.0.0.103 部署完成'
✅ 10.0.0.103 部署完成
+ echo '>>> [4/4] 健康检查...'
>>> [4/4] 健康检查...
+ for host in ${HOST_LIST}
+ sleep 8
+ echo ' >> 检查 10.0.0.103...'
>> 检查 10.0.0.103...
+ ssh root@10.0.0.103 'ps -ef | grep spring-boot-helloworld.jar | grep -v grep && echo '\'' ✅ 进程正常'\'' || echo '\'' ⚠️ 进程未检测到'\'''
root 15146 1 99 12:41 ? 00:00:10 java -jar /data/spring-boot-helloworld/spring-boot-helloworld.jar --server.port=8888
✅ 进程正常
+ ssh root@10.0.0.103 'ss -tlnp | grep 8888 && echo '\'' ✅ 端口 8888 监听中'\'' || echo '\'' ⚠️ 端口未监听'\'''
LISTEN 0 100 *:8888 *:* users:(("java",pid=15146,fd=17))
✅ 端口 8888 监听中
+ echo ==============================================
==============================================
+ echo ' ✅ 操作完成!'
✅ 操作完成!
+ echo ==============================================
==============================================
Archiving artifacts
Finished: SUCCESS
#部署v1.1到test→102控制台输出:
+ echo '✅ 编译成功'
✅ 编译成功
+ echo '>>> [2/4] 归档制品(供回滚使用)...'
>>> [2/4] 归档制品(供回滚使用)...
+ mkdir -p /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive
+ cp target/spring-boot-helloworld-0.6-SNAPSHOT.jar /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive/spring-boot-helloworld.jar
+ echo '✅ 已归档到 /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive/'
✅ 已归档到 /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive/
+ echo '>>> [3/4] 部署到目标服务器...'
>>> [3/4] 部署到目标服务器...
+ for host in ${HOST_LIST}
+ echo ' >> 部署到 10.0.0.102...'
>> 部署到 10.0.0.102...
+ ssh root@10.0.0.102 'mkdir -p /data/spring-boot-helloworld'
+ ssh root@10.0.0.102 'pkill -f spring-boot-helloworld.jar 2>/dev/null || true'
+ sleep 2
+ scp target/spring-boot-helloworld-0.6-SNAPSHOT.jar root@10.0.0.102:/data/spring-boot-helloworld/spring-boot-helloworld.jar
+ ssh root@10.0.0.102 'nohup java -jar /data/spring-boot-helloworld/spring-boot-helloworld.jar --server.port=8888 &>/dev/null &'
+ echo ' ✅ 10.0.0.102 部署完成'
✅ 10.0.0.102 部署完成
+ echo '>>> [4/4] 健康检查...'
>>> [4/4] 健康检查...
+ for host in ${HOST_LIST}
+ sleep 8
+ echo ' >> 检查 10.0.0.102...'
>> 检查 10.0.0.102...
+ ssh root@10.0.0.102 'ps -ef | grep spring-boot-helloworld.jar | grep -v grep && echo '\'' ✅ 进程正常'\'' || echo '\'' ⚠️ 进程未检测到'\'''
root 9012 1 99 13:20 ? 00:00:11 java -jar /data/spring-boot-helloworld/spring-boot-helloworld.jar --server.port=8888
✅ 进程正常
+ ssh root@10.0.0.102 'ss -tlnp | grep 8888 && echo '\'' ✅ 端口 8888 监听中'\'' || echo '\'' ⚠️ 端口未监听'\'''
LISTEN 0 100 *:8888 *:* users:(("java",pid=9012,fd=17))
✅ 端口 8888 监听中
+ echo ==============================================
==============================================
+ echo ' ✅ 操作完成!'
✅ 操作完成!
+ echo ==============================================
==============================================
Archiving artifacts
Finished: SUCCESS
#部署v1.1到prod→103控制台输出:
+ echo '✅ 编译成功'
✅ 编译成功
+ echo '>>> [2/4] 归档制品(供回滚使用)...'
>>> [2/4] 归档制品(供回滚使用)...
+ mkdir -p /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive
+ cp target/spring-boot-helloworld-0.6-SNAPSHOT.jar /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive/spring-boot-helloworld.jar
+ echo '✅ 已归档到 /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive/'
✅ 已归档到 /var/lib/jenkins/workspace/freestyle-spring-boot-helloworld/archive/
+ echo '>>> [3/4] 部署到目标服务器...'
>>> [3/4] 部署到目标服务器...
+ for host in ${HOST_LIST}
+ echo ' >> 部署到 10.0.0.103...'
>> 部署到 10.0.0.103...
+ ssh root@10.0.0.103 'mkdir -p /data/spring-boot-helloworld'
+ ssh root@10.0.0.103 'pkill -f spring-boot-helloworld.jar 2>/dev/null || true'
+ sleep 2
+ scp target/spring-boot-helloworld-0.6-SNAPSHOT.jar root@10.0.0.103:/data/spring-boot-helloworld/spring-boot-helloworld.jar
+ ssh root@10.0.0.103 'nohup java -jar /data/spring-boot-helloworld/spring-boot-helloworld.jar --server.port=8888 &>/dev/null &'
+ echo ' ✅ 10.0.0.103 部署完成'
✅ 10.0.0.103 部署完成
+ echo '>>> [4/4] 健康检查...'
>>> [4/4] 健康检查...
+ for host in ${HOST_LIST}
+ sleep 8
+ echo ' >> 检查 10.0.0.103...'
>> 检查 10.0.0.103...
+ ssh root@10.0.0.103 'ps -ef | grep spring-boot-helloworld.jar | grep -v grep && echo '\'' ✅ 进程正常'\'' || echo '\'' ⚠️ 进程未检测到'\'''
root 15362 1 99 13:34 ? 00:00:10 java -jar /data/spring-boot-helloworld/spring-boot-helloworld.jar --server.port=8888
✅ 进程正常
+ ssh root@10.0.0.103 'ss -tlnp | grep 8888 && echo '\'' ✅ 端口 8888 监听中'\'' || echo '\'' ⚠️ 端口未监听'\'''
LISTEN 0 100 *:8888 *:* users:(("java",pid=15362,fd=17))
✅ 端口 8888 监听中
+ echo ==============================================
==============================================
+ echo ' ✅ 操作完成!'
✅ 操作完成!
+ echo ==============================================
==============================================
Archiving artifacts
Finished: SUCCESS
验证
#test→102验证
[root@web02 ~]#netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 736/systemd-resolve
tcp 0 0 127.0.0.54:53 0.0.0.0:* LISTEN 736/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1/init
tcp6 0 0 :::8081 :::* LISTEN 8792/java
tcp6 0 0 :::8888 :::* LISTEN 8792/java
tcp6 0 0 :::22 :::* LISTEN 1/init
[root@web02 ~]#curl -I http://10.0.0.102:8888/version
HTTP/1.1 200
Content-Type: text/plain;charset=UTF-8
Content-Length: 13
Date: Thu, 03 Dec 2026 04:30:06 GMT
[root@web02 ~]#curl http://10.0.0.102:8888/version
version v1.0
[root@web02 ~]#curl -I http://10.0.0.102:8888/version
HTTP/1.1 200
Content-Type: text/plain;charset=UTF-8
Content-Length: 13
Date: Thu, 03 Dec 2026 05:26:51 GMT
[root@web02 ~]#curl http://10.0.0.102:8888/version
version v1.1
#prod→103验证
[root@web03 ~]#netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 14568/systemd-resol
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 127.0.0.54:53 0.0.0.0:* LISTEN 14568/systemd-resol
tcp6 0 0 :::22 :::* LISTEN 1/systemd
tcp6 0 0 :::8081 :::* LISTEN 15146/java
tcp6 0 0 :::8888 :::* LISTEN 15146/java
[root@web03 ~]#curl -I http://10.0.0.103:8888/version
HTTP/1.1 200
Content-Type: text/plain;charset=UTF-8
Content-Length: 13
Date: Thu, 03 Dec 2026 04:45:27 GMT
[root@web03 ~]#curl http://10.0.0.103:8888/version
version v1.0
[root@web03 ~]#curl -I http://10.0.0.103:8888/version
HTTP/1.1 200
Content-Type: text/plain;charset=UTF-8
Content-Length: 13
Date: Thu, 03 Dec 2026 05:38:18 GMT
[root@web03 ~]#curl http://10.0.0.103:8888/version
version v1.1
3.3 回滚
Build with Parameters:
TAG: [v1.0 ▼] ← 可任选,回滚不依赖源码
OPERATION: [rollback ▼]
DEPLOY_ENV: [test ▼]
ROLLBACK_BUILD: 2 ← 填要回滚到的构建号
→ Build
Build with Parameters:
TAG: [v1.0 ▼] ← 可任选,回滚不依赖源码
OPERATION: [rollback ▼]
DEPLOY_ENV: [prod ▼]
ROLLBACK_BUILD: 3 ← 填要回滚到的构建号
→ Build
留空则自动回滚到 当前构建号 - 1。
回滚v1.0到test→102

回滚v1.0到prod→103

控制台回滚输出:
#test→102从v1.1回滚到v1.0控制台输出:
+ echo ' ✅ 10.0.0.102 回滚完成'
✅ 10.0.0.102 回滚完成
+ echo '>>> [4/4] 健康检查...'
>>> [4/4] 健康检查...
+ for host in ${HOST_LIST}
+ sleep 8
+ echo ' >> 检查 10.0.0.102...'
>> 检查 10.0.0.102...
+ ssh root@10.0.0.102 'ps -ef | grep spring-boot-helloworld.jar | grep -v grep && echo '\'' ✅ 进程正常'\'' || echo '\'' ⚠️ 进程未检测到'\'''
root 9212 1 99 14:47 ? 00:00:10 java -jar /data/spring-boot-helloworld/spring-boot-helloworld.jar --server.port=8888
✅ 进程正常
+ echo ==============================================
==============================================
+ echo ' ✅ 操作完成!'
✅ 操作完成!
+ echo ==============================================
==============================================
Archiving artifacts
Finished: SUCCESS
#prod→103从v1.1回滚到v1.0控制台输出:
+ echo ' ✅ 10.0.0.103 回滚完成'
✅ 10.0.0.103 回滚完成
+ echo '>>> [4/4] 健康检查...'
>>> [4/4] 健康检查...
+ for host in ${HOST_LIST}
+ sleep 8
+ echo ' >> 检查 10.0.0.103...'
>> 检查 10.0.0.103...
+ ssh root@10.0.0.103 'ps -ef | grep spring-boot-helloworld.jar | grep -v grep && echo '\'' ✅ 进程正常'\'' || echo '\'' ⚠️ 进程未检测到'\'''
root 15563 1 99 15:14 ? 00:00:11 java -jar /data/spring-boot-helloworld/spring-boot-helloworld.jar --server.port=8888
✅ 进程正常
+ echo ==============================================
==============================================
+ echo ' ✅ 操作完成!'
✅ 操作完成!
+ echo ==============================================
==============================================
Archiving artifacts
Finished: SUCCESS
验证
[root@web02 ~]#netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 736/systemd-resolve
tcp 0 0 127.0.0.54:53 0.0.0.0:* LISTEN 736/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1/init
tcp6 0 0 :::8081 :::* LISTEN 9212/java
tcp6 0 0 :::8888 :::* LISTEN 9212/java
tcp6 0 0 :::22 :::* LISTEN 1/init
#test→102从v1.1回滚到v1.0
[root@web02 ~]#curl -I http://10.0.0.102:8888/version
HTTP/1.1 200
Content-Type: text/plain;charset=UTF-8
Content-Length: 13
Date: Thu, 03 Dec 2026 06:53:49 GMT
[root@web02 ~]#curl http://10.0.0.102:8888/version
version v1.0
[root@web03 ~]#netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 14568/systemd-resol
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 127.0.0.54:53 0.0.0.0:* LISTEN 14568/systemd-resol
tcp6 0 0 :::22 :::* LISTEN 1/systemd
tcp6 0 0 :::8081 :::* LISTEN 15563/java
tcp6 0 0 :::8888 :::* LISTEN 15563/java
[root@web03 ~]#
#prod→103从v1.1回滚到v1.0
[root@web03 ~]#curl -I http://10.0.0.103:8888/version
HTTP/1.1 200
Content-Type: text/plain;charset=UTF-8
Content-Length: 13
Date: Thu, 03 Dec 2026 07:20:10 GMT
[root@web03 ~]#curl http://10.0.0.103:8888/version
version v1.0
四、完整流程图
┌──────────────────────────────────────────┐
│ Build with Parameters │
│ │
│ TAG ───────── 下拉选标签 (Git Parameter) │
│ OPERATION ─── deploy / rollback │
│ DEPLOY_ENV ─── dev / test / prod │
│ ROLLBACK_BUILD ── 构建号(回滚用) │
└──────────────────┬───────────────────────┘
│
┌─────────▼──────────┐
│ 选择目标主机 │
│ prod→103 其他→102 │
└─────────┬──────────┘
│
┌─────────▼──────────┐
deploy rollback
┌────┴────┐ ┌────┴─────┐
│ Maven │ │ 从归档取 │
│ 编译 │ │ 历史 jar │
├─────────┤ ├──────────┤
│ 归档jar │ │ scp 到 │
├─────────┤ │ 目标机器 │
│ scp到 │ ├──────────┤
│ 目标机器│ │ 重启 │
├─────────┤ └──────────┘
│ 重启 │
└────┬────┘
│
┌────────▼─────────┐
│ 健康检查 │
│ 进程 + 端口 8888 │
└──────────────────┘
五、踩坑速查
| 问题 | 原因 | 解决 |
|---|---|---|
| Git Parameter 标签下拉为空 | 首次没缓存 | 手填 v1.0 跑一次 |
mvn: not found | PATH 未带 Maven | 脚本里加 export PATH=$PATH:/usr/share/maven/bin(或用绝对路径 /usr/share/maven/bin/mvn) |
| 回滚找不到 jar | 目标构建没成功 / 没归档 | 确认构建号存在且已归档 |
| ssh/scp 卡住不动 | 没配免密 | 回 1.7 重新配 ssh-copy-id |
ssh-keyscan web02 失败 | hosts 没配 | 回 1.1 补 /etc/hosts |
| 端口 8888 没起来 | 应用启动慢 | 看 ssh root@host "tail -50 /data/spring-boot-helloworld/app.log" |
| executors=0 排队 | Controller 不跑构建 | 节点和云管理 → Number of executors→ 设为 1 |
| pkill 没杀干净 | 进程还在退出中 | 脚本已加 sleep 2,可加大到 5 |
六、写在最后
本博客持续分享Linux、云计算运维实战内容,整理大量环境部署、集群搭建、故障排查干货。
如果文章对你工作与学习有所帮助,欢迎点赞、收藏;后续持续更新运维实操内容,点个关注不迷路,一起交流进步。
转载自 CSDN-专业IT技术社区
原文链接:https://blog.csdn.net/weixin_51867896/article/details/171816086



