• Get In Touch
May 31, 2017

How to Install Jenkins on CentOS 7

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Jenkins is a free and open source CI (Continuous Integration) tool which is written in JAVA. Jenkins is widely used for project development, deployment, and automation. Jenkins allows you to automate the non-human part of the whole software development process. It supports version control tools, including AccuRev, CVS, Subversion, Git, Mercurial, Perforce, ClearCase and RTC, and can execute Apache Ant, Apache Maven and sbt based projects as well as arbitrary shell scripts and Windows batch commands. The creator of Jenkins is Kohsuke Kawaguchi.[3] Released under the MIT License.

Jenkins’ security depends on two factors:
1. access control
2. protection from external threats.

  1. Access control can be customized via two ways, user authentication and authorization.
  2. Protection from external threats such as CSRF attacks and malicious builds is supported as well.

Requirements

It does not require any special kind of hardware, you’ll only need a CentOS 7 server and a root user access over it. You can switch from non root user to root user using sudo -i command.

Update System

It is highly recommended to install Jenkins on a freshly updated server. To upgrade available packages and system run below given command and it’ll do the job for you.

yum -y update

Install Java

Before going through the installation process of Jenkins you’ll need to set up Java Virtual Machine or JDK to your system. Simply run following command to install Java.

yum -y install java-1.8.0-openjdk.x86_64

Once installation is finished you can check the version to confirm the installation, to do run following command.

java -version

The above command will tell you about the installation details of java. By running the above command you should see the following result on your terminal screen.

openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)

Next, you’ll need to setup two environment variables JAVA_HOME and JRE_HOME and to do so run following commands one by one.

cp /etc/profile /etc/profile_backup

echo 'export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk' | sudo tee -a /etc/profile

echo 'export JRE_HOME=/usr/lib/jvm/jre' | sudo tee -a /etc/profile

source /etc/profile

Finally print them for review using following commands.

echo $JAVA_HOME

You should see following output.

/usr/lib/jvm/jre-1.8.0-openjdk

echo $JRE_HOME

Install Jenkins

We have installed all the dependencies required by Jenkins and now we are ready to install Jenkins. Run following commands to install latest stable release of Jenkins.

wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

The above two commands will add the jenkins repository and also import the key. If in case you have previously imported the key from Jenkins then the rpm --import will fail because you already have a key. Please ignore that and move on.

Now run following command to install Jenkins on your server.

yum -y install jenkins

Next, you’ll need to start Jenkins services and set it to run at boot time and to do so use following commands.

systemctl start jenkins.service
systemctl enable jenkins.service

Jenkins runs on port 8080 so you’ll need to change firewall rules to allow traffic on port 8080.

If in case you don’t have firewalld services installed on your server then you can install it using yum -y install firewalld and you can start it using systemctl start firewalld

Next run these below given command to modify the firewalld rules.

firewall-cmd --zone=public --permanent --add-port=8080/tcp
firewall-cmd --reload

Web Access

Open up your favorite web browser and please visit http://YourServerIPaddress:8080 and finish the installation wizard.

HP_NO_IMG/data/uploads/users/87cc1edd-a495-404e-9f7f-6fe80595e855/1743266643.png” alt=” ” />

You’ll see a webpage like this which will ask you for a password and this admin password is created and stored in the log file /var/log/jenkins/jenkins.log.

Run the below command to get the password.

grep -A 5 password /var/log/jenkins/jenkins.log

Copy the password and paste it in above windows and click on Continue button.

Next, you’ll see a setup wizard web page like this and Select the option : Install suggested plugins . It will install required plugins for Jenkins.

HP_NO_IMG/data/uploads/users/87cc1edd-a495-404e-9f7f-6fe80595e855/64465068.png” alt=” ” />

Next, it will ask you to create an Admin User so provide your username and password and email address and then finally click on Save and Finish button.

On the next page click on Start using Jenkins button and you’ll see a Jenkins user dashboard.

Install Nginx

You can install nginx as reverse proxy for Jenkins, so visitors will no longer need to key in the port number 8080 when accessing your Jenkins application. run following command to install nginx.

yum -y install nginx

Next, you’ll need to edit the configuration details using any text editor here we are using nano text editor. you can also install it using yum -y install nano

nano /etc/nginx/nginx.conf

Find these lines in the configuration file:

location / {
}

Add following content into the { } segment in configuration file then save the file and exit from the text editor.

proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

Next, start the nginx services and enable it to run at boot time like we have done before for Jenkins services using following commands.

systemctl start nginx.service
systemctl enable nginx.service

Finally you’ll need to modify firewall rules using following commands.

firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --reload

Now you can access it through a web browser via http://yourServerIP .

Conclusion

In tutorial you learned to how to install and configure Jenkins on your CentOS 7 server. You also learned to install nginx and setting it up with Jenkins. We hope now you have enough knowledge to work with Jenkins.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]