1、准备工作

安装Java,确保Java版本在1.6及以上

[root@xa-dev-ci-1 ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@xa-dev-ci-1 ~]# java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

2、安装jenkins

sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
sudo yum install jenkins

3、安装jenkins稳定版本

sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
sudo rpm --import http://pkg.jenkins-ci.org/redhat-stable/jenkins-ci.org.key
sudo yum install jenkins

4、配置

Jenkins安装目录:/var/lib/jenkins/

Jenkins配置文件地址:/etc/sysconfig/jenkins,这就是Jenkins的配置文件,可以在这里查看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。

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

5、防火墙设置

firewall-cmd --zone=public --add-port=8081/tcp --permanent
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload
firewall-cmd --list-all

6、权限

要确保jenkins用户对/var/lib/jenkins/和/var/log/jenkins/目录有读写权限。

[root@xa-dev-ci-1 plugins]# groups jenkins
jenkins : jenkins
[root@xa-dev-ci-1 plugins]# chown -R jenkins:jenkins /var/lib/jenkins/
[root@xa-dev-ci-1 plugins]# chown -R jenkins:jenkins /var/log/jenkins/

7、启动

sudo service jenkins restart
sudo chkconfig jenkins on

8、使用浏览器访问,根据提示操作

9、参考

https://blog.csdn.net/zhiaini06/article/details/45287671

https://www.jianshu.com/p/8a77010dafc6

05-06 11:23