Jenkins Installation Steps with WAR file in Linux
Version — 2.289.2 LTS Installation Type — Deployment of WAR File Mounting of /opt partition
We will be creating a new Volume group from the newly attached 500 Gb disk and then Create a new Logical Volume out of it
sudo vgcreate vg01 /dev/xvdb
sudo lvcreate -l 100%FREE — name lvol01 vg01
Once Logical Volume is created, we assign File System type to it which is ext4 in our case
sudo mkfs -t ext4 /dev/vg01/lvol01
After that, we create a directory /opt and assign our 500Gb Volume to the /opt folder
sudo mkdir -p /opt
sudo echo ‘/dev/vg01/lvol01 /opt ext4 defaults 1 2’ >> /etc/fstab
Then we run the mount command which will now mount the /opt as a new partition
sudo mount -a
You can verify by running the df -h command
cd /opt/
Next, we will be installing Jenkins and other requirements in /opt partition
Summary
· Install Java Version 8 — Jenkins is a Java-based application, hence Java is a must.
· Install Apache Tomcat Version 9 — Tomcat is required to deploy Jenkins war file.
· Download Jenkins war File — This war is required to install Jenkins.
· Deploy Jenkins war File — Jenkins war file needs to be deployed using Tomcat to run Jenkins.
· Install Suggested Plugins — Install a list of plugins suggested by Jenkins.
Installing prerequisites
Run the below commands as the root user,
yum install java-1.8.0-openjdk git
yum install wget
cd /opt/
wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.50/bin/apache-tomcat-9.0.50.tar.gz
tar –xvzf apache-tomcat-9.0.50.tar.gz
Configuring Tomcat server
We have to create an Admin user and assign roles to him to proceed
vi /opt/apache-tomcat-9.0.50/conf/tomcat-users.xml
Add the below line into that file
<user username=”<some-tomacat-user>” password=”<some-tomacat-pwd>” roles=”manager-gui,admin-gui,manager-script,standard”/>
We can try running the Tomcat Apache server without any application by
cd /opt/apache-tomcat-9.0.50/bin
./ catalina.sh start
You can get the hostname of the Server using ifconfig command and try accessing the below URL
http://< your hostname>:8080
You will be redirected to the Tomcat Apache Manager page
Here try selecting the Manager Tool button
You will face an error like access denied, this is because by default Tomcat will allow the only browser from the machine which hosts the Apache Server
So we need to make a change in context.xml
cd /opt/apache-tomcat-9.0.50/webapps/manager/META-INF
Open the file context.xml and comment on the Valve configuration line alone, check below
<! — <Valve className=”org.apache.catalina.valves.RemoteAddrValve”
allow=”127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> →
Restart Tomcat server by going to bin path again,
./ catalina.sh stop
./ catalina.sh start
Deploying the Jenkins WAR file into Tomcat Server
You can find the Latest Jenkins LTS version in this page — https://www.jenkins.io/download/
Download the Generic Java package and move it to server using WinSCP (or)
Use this command to download it directly to the server
wget https://get.jenkins.io/war-stable/2.289.2/jenkins.war
Once downloaded move the WAR file to the path — /opt/apache-tomcat-9.0.50/webapps/
Moving to this path will directly deploy the Application into Tomcat
We have to perform a restart to load the Application in Tomcat
But very important before, restarting you have to mention the JENKINS_HOME variable otherwise it will automatically set to the user home directory (i.e root in our case)
Open .bash_profile file of Root user and Jenkins home variable
vi ~/.bash_profile
Add this line inside the file — export JENKINS_HOME=/opt/JenkinsHome
Perform restart again
Now if you open the Manage Tool page of Tomcat Apache, You could see the Jenkins under the Application Table
Now Try accessing this — http://< your hostname>:8080/Jenkins
You will land on Unlock Jenkins Page, this means that our Jenkins is up and running.
Configuring in Jenkins UI
Once you hit the URL, you will be prompted to unlock Jenkins using the Initial Admin password placed at this path
{ JENKINS_HOME_PATH}secrets/initialAdminPassword
Enter the Password
Install the Suggested Plugins
Create your First Admin User
Then there you Jenkins is ready
Validate the Jenkins home path once by checking under
Manage Jenkins à Configure System
Adding Agent/Slave Nodes to Jenkins
We need Java and GIT installed in Agent Nodes to perform Jenkins Operations
yum –y install java-1.8.0-openjdk git
It is advisable to use the same user across all the Jenkins Master and Agent nodes
In our case since we ran Tomcat and deployed Jenkins WAR files as the root users, we are going to use root everywhere
We need to connect Master to Agent nodes to Integrate them
Go into the Master server and run the ssh-keygen command as the root user
Command — ssh-keygen
Example screenshot
It will ask you for the location to store the id_rsa (Private key) and id_rsa.pub (Public key) by default it is the home directory so proceed by giving enter
It is better to provide a passphrase, so note it down somewhere safe
Once done, you can find the files under the folder .ssh in the Root home directory
Creating Passwordless SSH between Master and Agent Node
We need to copy the id_rsa.pub key and paste it in the authorized_keys file of the Agent nodes which Master Jenkins will be accessing
Authorized_keys file will be present inside user home directory (In our case it is root) under .ssh folder
If not present create a file and paste the public key in it
cd ~/.ssh
vi authorized_keys
Once this is done, try to ssh from Master Server to the Slave Node (Both users are root)
ssh root@<your agent node host>
It will prompt you to confirm that this is a Verified Host, proceed by giving yes
This will add it in the known_host file, which will be useful for selecting strategy as Known Host Verification in Jenkins UI while adding the Agent Node
Adding the Agent Node from Jenkins UI
Once done go to Jenkins UI and under
Manage Jenkins à Mange Nodes and Clouds
Select New Node, Enter the Node name and select the Radio button Permanent Agent and give next
Proceed by entering the Name, Description. No. of executors you require and Remote Directory
It is advisable to use the same Home directory structure in the Master in Agent node as well, so create the Remote directory (Eg /opt/JenkinsHome) in the Agent server first and then enter the same path in the Remote Directory section
Select the Usage as Use the Node as much as possible
And Launch Method as Launch Agent via SSH
Enter the Hostname details
Under Credentials, Select Add and choose Jenkins
Select the Kind as SSH username with Private key and Scope as Jenkins
Enter the ID (Eg Master-To-Node-Key), Username and select the checkbox Treat Username as Secret
Choose Enter Directly and Enter the id_rsa (Private key) content of the Master Jenkins server in that section
(Those who have the Private key can access any machine which contains respective public key in their authorized_keys file)
Finish by giving Add
Now Select the Credentials which you just now created
Select the Host Key Verification Strategy as Know Host file Verification Strategy which we previously discussed
Leave others to default and Finish by giving Save.
Master Jenkins will now try to launch the Agent node, which will come online in few minutes.
You can confirm the node is up by checking under the build Executor Tab on the Jenkins Home page, you can see the Node name with the number of Executors which you entered while creating the Node.
So we have brought up the Jenkins and have Integrated the Node Agents as well, follow the same steps if you want another Node to be added.
END