在 CentOS 上优化 Jenkins 性能,通常可以从系统层、JVM 层、Jenkins 配置层、插件与任务层四个方面入手。下面给你一套比较实用、可落地的优化方案。
Jenkins 会大量使用文件句柄(构建日志、workspace 等)。
# 查看当前限制
ulimit -n
# 修改限制(永久)
vi /etc/security/limits.conf
添加:
jenkins soft nofile 65535
jenkins hard nofile 65535
vi /etc/sysctl.conf
建议添加:
fs.file-max = 1000000
vm.swappiness = 10
net.core.somaxconn = 1024
执行:
sysctl -p
JENKINS_HOME 建议放在 SSDsystemctl disable firewalld --now # 如果已有外部防火墙
systemctl disable postfix
CentOS 上通常配置文件在:
/etc/sysconfig/jenkins
或(systemd):
/etc/systemd/system/jenkins.service
示例(8G 内存服务器):
JAVA_OPTS="-Xms2g -Xmx4g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -Djenkins.install.runSetupWizard=false"
说明:
-Xms / -Xmx:避免频繁 GCsystemctl daemon-reload
systemctl restart jenkins
Manage Jenkins → Configure System
# of executors:建议 = CPU 核心数 或 核心数 × 1.5插件推荐:
Manage Jenkins → Plugins → Installed
删除:
✅ 推荐:
pipeline {
agent { label 'build-agent' }
options {
timeout(time: 30, unit: 'MINUTES')
disableConcurrentBuilds()
}
}
❌ 避免:
agent {
docker {
image 'maven:3.8'
args '-v /root/.m2:/root/.m2'
}
}
top
htop
iostat -x 1
jstat -gcutil <pid> 1000
| 项目 | 建议 |
|---|---|
| CPU | ≥ 4 核 |
| 内存 | ≥ 8G |
| JVM | 2–4G |
| 构建 | Agent 分离 |
| 磁盘 | SSD |
| GC | G1GC |
如果你愿意,可以告诉我:
我可以给你针对性的调优方案。