Prerequisites
Before configuring multi-node Jenkins on Debian, ensure the following:
- All nodes (master and agents) have Debian OS installed and updated (
sudo apt update && sudo apt upgrade
).
- Java 11+ is installed on all nodes (
sudo apt install openjdk-11-jdk
).
- The master node has a stable internet connection to download Jenkins and plugins.
- Basic familiarity with Jenkins web interface and Linux command line.
Step 1: Install Jenkins on Master and Agent Nodes
- Add Jenkins Repository: On both master and agent nodes, add the official Jenkins APT repository to ensure access to stable builds.
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
- Install Jenkins: Run
sudo apt install jenkins
on both nodes. This installs Jenkins and starts the service automatically.
- Start/Enable Services: Verify Jenkins is running with
sudo systemctl status jenkins
(should show “active (running)”). Enable auto-start on boot: sudo systemctl enable jenkins
.
Step 2: Configure Jenkins Master Node
- Access Web Interface: Open a browser and navigate to
http://<master-node-ip>:8080
. Unlock Jenkins using the initial admin password found in /var/lib/jenkins/secrets/initialAdminPassword
.
- Install Essential Plugins: Go to Manage Jenkins > Manage Plugins. Install critical plugins:
- SSH Build Agents (for secure agent communication).
- Pipeline (if using Declarative/Scripted Pipelines).
- Node and Label Parameter (for dynamic node selection).
- Adjust Master Configuration: Edit
/etc/default/jenkins
to:
- Set
HTTP_PORT=8080
(or a custom port if needed).
- Ensure
JENKINS_HOME=/var/lib/jenkins
(default location for jobs/workspaces).
Restart Jenkins to apply changes: sudo systemctl restart jenkins
.
Step 3: Add Agent Nodes to Master
- Create Agent Node in Master:
- Navigate to Manage Jenkins > Manage Nodes and Clouds > New Node.
- Enter a Node Name (e.g.,
debian-agent-01
).
- Select Permanent Agent and click OK.
- Configure node details:
- Remote Root Directory: Set a unique directory for the agent (e.g.,
/home/jenkins/agent
).
- Labels: Add descriptive labels (e.g.,
linux
, debian
) to group similar agents.
- Usage: Choose “Use this node as much as possible” (default) or restrict to specific jobs.
- Launch Method: Select Launch agents via SSH (recommended for security).
- Configure SSH Credentials:
- In the “Launch agents via SSH” section, click Add under “Credentials”.
- Choose SSH Username with private key, enter the username (e.g.,
jenkins
) for the agent node, and paste the private key (generated in Step 4).
- Save Node Configuration: Click Save to finalize the agent setup.
Step 4: Configure SSH Authentication (Master → Agent)
- Generate SSH Key Pair on Master:
- Log in to the master node and run
ssh-keygen -t rsa -b 4096
. Press Enter to accept defaults (no passphrase for automation).
- The private key is stored in
~/.ssh/id_rsa
, and the public key in ~/.ssh/id_rsa.pub
.
- Copy Public Key to Agent Node:
- Use
ssh-copy-id jenkins@<agent-node-ip>
to copy the master’s public key to the agent’s ~/.ssh/authorized_keys
file.
- Enter the agent node’s password when prompted. This enables password-less SSH login from master to agent.
- Test SSH Connection: Run
ssh jenkins@<agent-node-ip>
. You should log in without a password.
Step 5: Verify Agent Connection
- Check Agent Status in Master: Go to Manage Jenkins > Manage Nodes and Clouds. The agent node (e.g.,
debian-agent-01
) should appear with a Connected status.
- Run a Test Job:
- Create a new Freestyle job in Jenkins.
- Under Restrict where this project can be run, enter the agent’s label (e.g.,
linux
).
- Add a build step (e.g.,
Execute shell
with echo "Hello from agent"
).
- Save and run the job. Check the console output to confirm it executed on the agent node.
Optional: Set Up Load Balancing for High Availability
To distribute traffic across multiple master nodes (for high availability):
- Install HAProxy: On a separate Debian node (or one of the masters), run
sudo apt install haproxy
.
- Configure HAProxy: Edit
/etc/haproxy/haproxy.cfg
to include:frontend jenkins
bind *:8080
default_backend jenkins_servers
backend jenkins_servers
balance roundrobin
server jenkins1 <master1-ip>:8080 check
server jenkins2 <master2-ip>:8080 check
- Restart HAProxy:
sudo systemctl restart haproxy
.
- Access Jenkins via HAProxy: Use the HAProxy node’s IP/hostname (e.g.,
http://<haproxy-ip>:8080
) to access Jenkins. Requests will be load-balanced across the configured masters.
Troubleshooting Tips
- Agent Not Connecting: Verify SSH connectivity (
ssh jenkins@<agent-ip>
), firewall rules (allow port 22), and Jenkins credentials (correct private key).
- Job Not Running on Agent: Check node labels (ensure they match the job restriction), agent status (must be “Connected”), and job configuration (correct “Restrict where this project can be run” setting).
- Java Issues: Ensure all nodes use the same Java version (OpenJDK 11+ recommended).