下面从 系统层、JVM 层、Jenkins 自身、插件与任务设计 四个维度,系统讲一下 Jenkins 在 Debian 上的调优思路(以长期运行的生产环境为目标)。
Debian 通常用 systemd 启动 Jenkins:
systemctl status jenkins
调优建议:
编辑:
systemctl edit jenkins
示例:
[Service]
Restart=always
RestartSec=5
MemoryMax=6G
TasksMax=4096
Jenkins 并发构建会消耗大量 fd。
ulimit -n
建议:
* soft nofile 65536
* hard nofile 65536
在 systemd 中:
[Service]
LimitNOFILE=65536
LimitNPROC=4096
Jenkins 非常依赖磁盘:
JENKINS_HOME建议:
JENKINS_HOME查看 IO:
iostat -x 1
避免日志和构建异常:
dpkg-reconfigure tzdata
Jenkins 是 Java 应用,JVM 参数直接决定稳定性。
编辑:
/etc/default/jenkins
或(新版 systemd):
systemctl edit jenkins
示例(8G 内存服务器):
JAVA_OPTS="-Xms4g -Xmx4g \
-XX:+UseG1GC \
-XX:MaxGCPauseMillis=200 \
-XX:+ParallelRefProcEnabled \
-Djava.awt.headless=true \
-Dfile.encoding=UTF-8"
说明:
-Xms == -Xmx:避免动态扩容抖动-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-Xloggc:/var/log/jenkins/gc.log
路径:
Jenkins → 系统管理 → 系统配置
# of executors:建议 = CPU 核数 或 核数 - 1不要让 Master 跑构建
架构建议:
Jenkins Master (Debian)
├── Agent (Docker)
├── Agent (VM)
└── Agent (K8s)
Agent 配置:
防止 JENKINS_HOME 爆炸:
全局策略也可用:
System → Build History
常见影响性能插件:
✅ 推荐:
pipeline {
agent { label 'docker' }
options {
timeout(time: 30, unit: 'MINUTES')
disableConcurrentBuilds()
}
}
❌ 避免:
cleanWs()
或 Agent 自动销毁(Docker/K8s)
/metricshtop
iostat
journalctl -u jenkins
| 现象 | 原因 |
|---|---|
| UI 卡 | Master 跑构建 |
| OOM | JVM 过大 |
| 磁盘满 | 历史构建 |
| CPU 高 | 插件/并发 |
Xms6g Xmx6g
executors=0 (Master)
Agent: 4
SSD
Docker Agent
如果你愿意,可以告诉我:
我可以直接给你 一套可落地的配置。