👤 Shivansh Thapliyal
Script to install jenkins:
#!/bin/bash
sudo yum install java-1.8.0-openjdk-devel -y #Jenkins is a Java application, so the first step is to install Java.
yum install wget -y
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.key
sudo yum upgrade -y
sudo yum install jenkins java-1.8.0-openjdk-devel -y
sudo systemctl daemon-reload
sudo systemctl start jenkins
sudo systemctl status jenkins
Jenkins requires Java 1.8. However, Amazon Linux comes preinstalled with Java 1.7. Let’s replace 1.7 with 1.8. We’re going to install Java 1.8 first to prevent any of our AWS CLI tools from being uninstalled due to the Java dependancy breaking.
sudo yum install java-1.8.0
sudo yum remove java-1.7.0-openjdk
We need to add the Jenkins repository so that yum knows where to install Jenkins from.
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
Next, we’re adding the Jenkins GPG key to our trusted keys so that we’re able to install Jenkins, verifying that the files are being sourced from a trusted location.
sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
We can now install Jenkins:
sudo yum install jenkins
Start the Jenkins service:
sudo service jenkins start
If you want Jenkins to automatically start when your instance is started, we can use chkconfig to add Jenkins to our startup services.
sudo chkconfig --add jenkins
You can now access your Jenkins server using the public DNS on port 8080.
http://{ec2-public-dns}:8080
To solve this issue, you will have to do two changes:
-
Add Jenkins user to root group: sudo usermod -a -G root jenkins
-
Make Jenkins listen to all external IPs by editing file /etc/sysconfig/jenkins and changing the JENKINS_LISTEN_ADDRESS="0.0.0.0"