准备条件:安装Java(CentOS下安装Java1.8)

1、Yum安装

yum源导入

#添加Yum源
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 install -y jenkins

2、开放端口

Jenkins站点的默认监听端口是8080(防火墙安装看这)

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

3、安装完成后启动Jenkins:

  • 检查Jenkins服务状态
    sudo systemctl status jenkins
  • 设置为开机自启动
    sudo systemctl enable jenkins
  • 启动Jenkins服务
    sudo systemctl start jenkins
  • 停止Jenkins服务
    sudo service jenkins stop

(查看Jenkins开启成功「Active:active (running)」,就可以在浏览器里面查看:http://服务器IP:Jenkins启动的端口号Port)## 4、相关配置
Jenkins配置文件地址:

/etc/sysconfig/jenkins

这就是Jenkins的配置文件,可以在这里查看Jenkins默认的配置。
cat jenkins
这里介绍下三个比较重要的配置:

JENKINS_HOME

JENKINS_USER

JENKINS_PORT
JENKINS_HOME是Jenkins的主目录,Jenkins工作的目录都放在这里,Jenkins储存文件的地址,Jenkins的插件,生成的文件都在这个目录下。

## Path:        Development/Jenkins
## Description: Jenkins Continuous Integration Server
## Type: string
## Default: "/var/lib/jenkins"
## ServiceRestart: jenkins
#
# Directory where Jenkins store its configuration and working
# files (checkouts, build reports, artifacts, ...).
#
JENKINS_HOME="/var/lib/jenkins"

JENKINS_USER 是Jenkins的用户,拥有$JENKINS_HOME和/var/log/jenkins的权限。

## Type:        string
## Default: "jenkins"
## ServiceRestart: jenkins
#
# Unix user account that runs the Jenkins daemon
# Be careful when you change this, as you need to update
# permissions of $JENKINS_HOME and /var/log/jenkins.
#
JENKINS_USER="jenkins"

JENKINS_PORT 是Jenkins的端口,默认端口是8080。

Default: 8080

ServiceRestart: jenkins

Port Jenkins is listening on.

Set to -1 to disable

JENKINS_PORT=”8080”

## Type:        integer(0:65535)  
## Default: 8080
## ServiceRestart: jenkins
#
# Port Jenkins is listening on.
# Set to -1 to disable
#
JENKINS_PORT="8080"