# How to Install Jenkins on CentOS 7How to Install Jenkins on CentOS 7

How to Install Jenkins on CentOS 7

Published on: Thu, May 19, 2016 at 4:54 am EST

CentOS DevOps Linux Guides Server Apps

Jenkins is a popular open source CI (Continuous Integration) tool which is widely used for project development, deployment, and automation.

This article will guide you through the process of installing Jenkins on a Vultr CentOS 7 server instance. In order to facilitate visitors' access, Nginx will also be installed as the reverse proxy for Jenkins.

Prerequisites

Before proceeding, you must have:

  • Deployed a Vultr CentOS 7 server instance from scratch.
  • Logged into your machine as a non-root user with sudo privileges.

Step 1: Update your CentOS 7 system

One of the Linux system administrator's best practices is keeping a system up to date. Install the latest stable packages, then reboot.

sudo yum install epel-release
sudo yum update
sudo reboot

When the reboot finishes, login with the same sudo user.

Step 2: Install Java

Before you can install Jenkins, you need to setup a Java virtual machine on your system. Here, let's install the latest OpenJDK Runtime Environment 1.8.0 using YUM:

sudo yum install java-1.8.0-openjdk.x86_64

After the installation, you can confirm it by running the following command:

java -version

This command will tell you about the Java runtime environment that you have installed:

openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

In order to help Java-based applications locate the Java virtual machine properly, you need to set two environment variables: "JAVA_HOME" and "JRE_HOME".

sudo 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, you can print them for review:

echo $JAVA_HOME
echo $JRE_HOME

Step 3: Install Jenkins

Use the official YUM repo to install the latest stable version of Jenkins, which is 1.651.2 at the time of writing:

cd ~ 
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
yum install jenkins

Start the Jenkins service and set it to run at boot time:

sudo systemctl start jenkins.service
sudo systemctl enable jenkins.service

In order to allow visitors access to Jenkins, you need to allow inbound traffic on port 8080:

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

Now, test Jenkins by visiting the following address from your web browser:

http://<your-Vultr-server-IP>:8080

Step 4: Install Nginx (optional)

In order to facilitate visitors' access to Jenkins, you can setup an Nginx reverse proxy for Jenkins, so visitors will no longer need to key in the port number 8080 when accessing your Jenkins application.

Install Nginx using YUM:

sudo yum install nginx

Modify the configuration of Nginx:

sudo vi /etc/nginx/nginx.conf

Find the two lines below:

location / {
}

Insert the six lines below into the { } segment:

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;

The final result should be:

location / {
    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;
}

Save and quit:

:wq

Start and enable the Nginx service:

sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Allow traffic on port 80:

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

Finally, visit the following address from your web browser to confirm your installation:

http://<your-Vultr-server-IP>
/var/log/jenkins
/var/tmp/yum-kiro-4iNJpf/x86_64/7/jenkins
/var/cache/jenkins
/var/cache/yum/x86_64/7/jenkins
/var/lib/jenkins
/var/lib/yum/repos/x86_64/7/jenkins
/etc/logrotate.d/jenkins
/etc/rc.d/init.d/jenkins
/etc/sysconfig/jenkins  // change port here
/usr/lib/jenkins

我的博客即将搬运同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=2rfs0iqwa3r

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏web编程技术分享

用SpringBoot搭建简单电商项目 01

8658
来自专栏Kubernetes

kube-scheduler最佳配置

version: kubernetes 1.6.2 ##kube-scheduler Configuration 下面是我梳理的kube-scheduler的完...

3238
来自专栏不想当开发的产品不是好测试

spring boot 登录注册 demo (一)

Welcome to Spring Boot 代码结构 ? src/main/java 下 controller层,路由功能 dao层,数据库的访问 domai...

3185
来自专栏james大数据架构

常见的几种Flume日志收集场景实战

  这里主要介绍几种常见的日志的source来源,包括监控文件型,监控文件内容增量,TCP和HTTP。 Spool类型   用于监控指定目录内数据变更,若有新文...

3445
来自专栏颇忒脱的技术博客

Nginx反向代理WebSocket响应403的解决办法

在Nginx反向代理一个带有WebSocket功能的Spring Web程序(源代码地址)时,发现访问WebSocket接口时总是出现403响应,Nginx的配...

2595
来自专栏10km的专栏

Caffe: Could not find PROTOBUF Compiler(Profobuf 3.0 above)

在用cmake生成Caffe工程文件的时候,如果你使用Protobuf 3.0以上的版本,cmake可能会产生如下的报错: CMake Error at cm...

1K6
来自专栏增长技术

Maven部署Web项目到Tomcat的配置

Maven自动部署实际上调的是Tomcat安装目录下的manager功能。而为了能正常访问http://localhost:8080/manager页面,我们需...

8293
来自专栏Google Dart

AOP切面编程一 原

903
来自专栏电光石火

Spring Cloud与Spring Boot版本匹配关系

Spring Cloud版本 在写本篇文章时,Spring Cloud版本演进情况如下: 版本名称 版本 ...

7258
来自专栏北京马哥教育

性能测试与持续集成(JMeter+Jenkins)

目的 将性能测试与持续集成挂接起来 性能测试: JMeter 持续集成: Jenkins JMeter 下载JMeter,官网: http://jmeter.a...

4805

扫码关注云+社区

领取腾讯云代金券