Setting up a Jenkins master-slave (also known as Jenkins master-agent) configuration allows you to distribute build and deployment workloads across multiple machines, improving scalability and resource utilization. The Jenkins master controls and manages the build jobs, while the slave nodes perform the actual build and testing tasks. Here's a step-by-step guide on how to set up a Jenkins master-slave setup:
Prerequisites:
Jenkins: Ensure you have Jenkins installed and running on your master server. You can download Jenkins from the official website and follow their installation instructions.
Slave Nodes: Prepare one or more slave machines (nodes) where you want to distribute your Jenkins builds. These can be physical machines or virtual machines.
Java: Make sure Java is installed on both the master and slave machines. Jenkins requires Java to run.
Setting Up the Jenkins Master:
Install Jenkins Plugins:
Open Jenkins in your web browser.
Click on "Manage Jenkins" in the left-hand sidebar.
Click on "Manage Plugins."
In the "Available" tab, search for and install the "SSH Slaves" and "Node and Label Parameter" plugins. These plugins are essential for setting up slave nodes.
Configure Security:
Go to "Manage Jenkins" "Configure Global Security."
Enable "Enable Security."
Choose your security realm (e.g., "Jenkins's own user database").
Create at least one user with the necessary permissions.
Configure authorization (e.g., "Matrix-based security" or "Project-based Matrix Authorization Strategy") to specify which users can create and configure nodes.
Setting Up Jenkins Slave Nodes:
Install Java:
Ensure Java is installed on the slave machines.
Create a Jenkins User on Slave Nodes:
Create a user account on each slave machine specifically for Jenkins to use for remote connections.
Install the Jenkins Agent (Slave) Software:
You can download the agent (slave) JAR file from your Jenkins master server. Open your Jenkins master in a web browser, navigate to "Manage Jenkins" "Manage Nodes and Clouds," and then click "New Node."
Enter a name for the node and select "Permanent Agent."
Configure the node details, such as the number of executors (build slots), remote root directory, labels (used for job assignment), and usage options.
On the slave machine, download the agent JAR file and run it with the appropriate command, specifying the Jenkins master's URL and the secret provided during node configuration. For example:
ruby
Copy code
java -jar agent.jar -jnlpUrl http://your-jenkins-server/computer/your-node-name/slave-agent.jnlp -secret your-secret
Testing the Jenkins Master-Slave Setup:
Create a Jenkins job.
In the job configuration, specify the label that matches your slave node.
Build the job, and Jenkins will assign it to an available slave node for execution.
Your Jenkins master-slave setup is now complete, and Jenkins will distribute build and deployment tasks across the slave nodes according to your job configurations. You can add more slave nodes as needed to scale your Jenkins infrastructure.