Jenkins 连接 CentOS 通常指两种情况之一:
1️⃣ Jenkins 安装在 CentOS 上并运行
2️⃣ Jenkins 通过 SSH 连接 CentOS(作为 agent 或执行远程命令)
下面我按最常见场景给你讲清楚,你可以对照自己的需求。
sudo yum install java-11-openjdk -y
java -version
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
sudo yum install jenkins -y
sudo systemctl start jenkins
sudo systemctl enable jenkins
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
http://服务器IP:8080
查看初始密码:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
✅ 到这里,Jenkins 就运行在 CentOS 上了。
这是最常见“如何连接 CentOS”的场景。
sudo yum install java-11-openjdk -y
java -version
sudo useradd jenkins
sudo passwd jenkins
Jenkins → Manage Jenkins → Configure System → SSH remote hosts
或者:
Jenkins → Manage Jenkins → Credentials
SSH Username with private keyjenkinsManage Jenkins → Nodes → New Node
配置示例:
centos-agentPermanent Agent/home/jenkins✅ 保存后 Jenkins 会自动连接 CentOS。
适合简单部署场景。
Publish Over SSH
Manage Jenkins → Configure System → Publish over SSH
/optSend files or execute commands over SSH
sudo systemctl status firewalld
sudo systemctl status sshd
telnet CentOS_IP 22
你可以直接告诉我:
1️⃣ Jenkins 装在哪?(本机 / Docker / Windows)
2️⃣ CentOS 是物理机 / 虚拟机 / 云服务器?
3️⃣ 想做什么?(自动部署 / 构建 / 远程执行命令)
我可以给你一步一步针对你环境的配置方案 ✅