快速搭建开发环境 - Jenkins

快速搭建开发环境 - Jenkins

官网

一、简介

Jenkins是一款开源 持续集成(CI) / 持续交付 (CD) 软件,用于自动化各种任务,包括构建、测试和部署软件。
Jenkins 支持各种运行方式,可通过系统包、Docker 或者通过一个独立的 Java 程序。

二、安装

适用于单个/本地机器上的Jenkins新安装。

Jenkins通常作为一个独立的应用程序在其自己的流程中运行, 内置Java servlet 容器/应用程序服务器(Jetty)。
Jenkins也可以运行在不同的Java servlet容器((如Apache TomcatGlassFish))中作为servlet运行。

系统要求

最低推荐配置:

  • 256MB可用内存
  • 1GB可用磁盘空间(作为一个Docker容器运行jenkins的话推荐10GB)

为小团队推荐的硬件配置:

  • 1GB+可用内存
  • 50 GB+ 可用磁盘空间

软件配置:

  • Java 8—无论是Java运行时环境(JRE)还是Java开发工具包(JDK)都可以。

Linux 平台安装

官网下载地址

选择相应操作系统 Download Jenkins 2.235.5 LTS for:

  • Docker
  • Ubuntu/Debian
  • CentOS/Fedora/Red Hat
  • Windows
  • openSUSE
  • FreeBSD
  • Gentoo
  • macOS
  • OpenBSD

操作步骤

step 1 查看操作系统版本
#查看操作系统版本
cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)
step 2 获取jenkins yum源的配置文件
#从官网获取jenkins 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

查看yum源配置文件

ll /etc/yum.repos.d/ | grep jenkins
-rw-r--r--. 1 root root   85 Nov 29  2016 jenkins.repo # 这里可以看到 jenkins 配置文件已经下载到本地
step 3 使用yum安装jenkins
#使用yum安装jenkins (可能较慢,网络差异)
sudo yum upgrade
sudo yum install jenkins java-1.8.0-openjdk-devel
sudo systemctl daemon-reload
setp 4 启动
#启动 jenkins
sudo systemctl start jenkins
#查看 jenkins运行状态
sudo systemctl status jenkins
step 5 初始化jenkins

浏览器访问 http://yoursip:8080

默认日志文件路径 /var/log/jenkins/jenkins.log

[root@localhost ~]# tail -f -n 500 /var/log/jenkins/jenkins.log
......
......
root of factory hierarchy
2020-09-01 09:39:05.498+0000 [id=27]    INFO    jenkins.install.SetupWizard#init: 

*************************************************************
*************************************************************
*************************************************************

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

ebde3d6742ac422aafd9dc74189f6233

This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************

注:启动服务遇到的错误

1、Starting Jenkins bash: /usr/bin/java: No such file or directory

[root@localhost ~]# systemctl start jenkins
Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for 
details.
[root@localhost ~]# systemctl status jenkins.service
● jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2020-09-01 05:30:45 EDT; 16s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3692 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=1/FAILURE)

Sep 01 05:30:45 localhost.localdomain systemd[1]: Starting LSB: Jenkins Automation Server...
Sep 01 05:30:45 localhost.localdomain runuser[3697]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
Sep 01 05:30:45 localhost.localdomain jenkins[3692]: Starting Jenkins bash: /usr/bin/java: No such file or directory
Sep 01 05:30:45 localhost.localdomain systemd[1]: jenkins.service: control process exited, code=exited status=1
Sep 01 05:30:45 localhost.localdomain jenkins[3692]: [FAILED]
Sep 01 05:30:45 localhost.localdomain systemd[1]: Failed to start LSB: Jenkins Automation Server.
Sep 01 05:30:45 localhost.localdomain systemd[1]: Unit jenkins.service entered failed state.
Sep 01 05:30:45 localhost.localdomain systemd[1]: jenkins.service failed.
[root@localhost ~]# java -version
java version "1.8.0_192"
Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)
[root@localhost ~]# 
原因:

jenkins默认jdk配置路径和自定义安装jdk路径不一致

解决:

修改jenkins启动脚本,添加本地jdk环境路径 /etc/init.d/jenkins

candidates="
/etc/alternatives/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/lib/jvm/java-11.0/bin/java
/usr/lib/jvm/jre-11.0/bin/java
/usr/lib/jvm/java-11-openjdk-amd64
/usr/bin/java
/usr/local/java/bin/java #本地jdk路径
"

Docker 安装

操作步骤

step 1 拉取镜像
#拉取镜像
[root@localhost vagrant]# docker pull jenkinsci/blueocean
Using default tag: latest
Trying to pull repository docker.io/jenkinsci/blueocean ...
latest: Pulling from docker.io/jenkinsci/blueocean
......
#查看镜像
[root@localhost ~]# docker images
REPOSITORY                    TAG       IMAGE ID            CREATED             SIZE
docker.io/jenkins/jenkins    latest     ca03aad4393c        18 hours ago        648 MB
step 2 启动
#启动jenkins
docker run -d -p 80:8080 -p 50000:50000 -v jenkins:/var/jenkins_home -v /etc/localtime:/etc/localtime --name jenkins docker.io/jenkins/jenkins

官方推荐启动方式

#旧版
docker run \
  -u root \
  --rm \
  -d \
  -p 8080:8080 \
  -p 50000:50000 \
  -v jenkins-data:/var/jenkins_home \
  -v /var/run/docker.sock:/var/run/docker.sock \
  jenkinsci/blueocean
 #最新版
 
 #创建 bridge network
 docker network create jenkins
 
 #创建以下卷以共享连接到Docker守护进程所需的Docker客户端TLS证书,并使用以下docker卷CREATE命令持久化Jenkins数据
 docker volume create jenkins-docker-certs
 docker volume create jenkins-data
 
 #拉取docker:dind
 docker image pull docker:dind
 
 #启动docker容器 
 docker container run \
  --name jenkins-docker \
  --rm \
  --detach \
  --privileged \
  --network jenkins \
  --network-alias docker \
  --env DOCKER_TLS_CERTDIR=/certs \
  --volume jenkins-docker-certs:/certs/client \
  --volume jenkins-data:/var/jenkins_home \
  --publish 2376:2376 \
  docker:dind
 
 #启动的docker容器中运行jenkins-blueocean镜像
 docker container run \
  --name jenkins-blueocean \
  --rm \
  --detach \
  --network jenkins \
  --env DOCKER_HOST=tcp://docker:2376 \
  --env DOCKER_CERT_PATH=/certs/client \
  --env DOCKER_TLS_VERIFY=1 \
  --publish 8080:8080 \
  --publish 50000:50000 \
  --volume jenkins-data:/var/jenkins_home \
  --volume jenkins-docker-certs:/certs/client:ro \
  jenkinsci/blueocean 

注:在镜像文档里,我们知道Jenkins访问的端口号是8080,另外还需要暴露一个tcp的端口号50000。我们使用如下命令启动Jenkins镜像。

jenkins正确打开方式 ( 踩坑无数 o(╥﹏╥)o)
docker run --restart=always \
-u root \
-d \
-v /home/jenkins-data:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /usr/local/maven:/usr/local/maven \
-p 8080:8080 \
-p 50000:50000 \
--net="host" \
--name jenkins \
jenkinsci/blueocean

--restart=always 在容器停止运行的时候,重启容器。用于开机自启和容器意外关闭时的自启动
-v /home/jenkins-data:/var/jenkins_home 将宿主机的 /home/jenkins-data 目录挂载到 /var/jenkins_home。这样做是为了把Jenkins文件存放到宿主机上,就算容器被删除了,新建一个新的容器内容也不会丢失。
-v /var/run/docker.sock:/var/run/docker.sock jenkins容器与Docker守护进程通信, 如果jenkins容器需要实例化其他Docker容器,则该守护进程是必需的。
-v /opt/software/apache-maven-3.6.3:/usr/local/maven 挂在Maven目录
--net="host" 容器使用宿主机的网络。jenkins默认是8080端口,用这条参数,不会修改端口,如果要改端口,请使用 -p
-p 80:8080 将容器的8080端口映射到宿主机的80端口
--name jenkins 给容器命名
-d 容器后台运行

解锁jenkins

[root@localhost vagrant]# docker logs 6a618fe7c3ef

日志中查看解锁密码

2020-04-22 00:37:56.156+0000 [id=26]    INFO    jenkins.install.SetupWizard#init:
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
9609e6ab67854880ba629ddd78b50b9c
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************

默认账户/密码 admin 9609e6ab67854880ba629ddd78b50b9c

进入容器内部获取密码

[root@localhost ~]# docker exec jenkins tail /var/jenkins_home/secrets/initialAdminPassword
1bb8cfb0289f4df4bb0ce658941fb02e
[root@localhost ~]#

离线安装

step 1 下载安装包

yum install jenkins --downloadonly --downloaddir=/root

[root@m ~]# yum install jenkins --downloadonly --downloaddir=/root
[root@m ~]# ll
-rw-r--r--. 1 root root 66270257 Aug 17 12:36 jenkins-2.235.5-1.1.noarch.rpm
step 2 安装jenkins

rpm -ivh jenkins-2.235.5-1.1.noarch.rpm

[root@m ~]# rpm -ivh jenkins-2.235.5-1.1.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:jenkins-2.235.5-1.1              ################################# [100%]
[root@m ~]#
step 3 安装jdk

如果已安装jdk可跳过此步骤

yum install java-1.8.0-openjdk-devel --downloadonly --downloaddir=/root

[root@m ~]# yum install java-1.8.0-openjdk-devel --downloadonly --downloaddir=/root
[root@m ~]# rpm -ivh *.rpm --nodeps --force
step 4 离线安装插件

方式一

通过浏览器访问能连接外网的jenkins服务,点击安装自己所需要的jenkins插件,在线安装。安装完毕后,在/var/lib/jenkins/plugins目录下会生成安装的插件目录,以及插件安装文件(.jpi 格式)。

方式二

通过浏览器访问不能连接外网的jenkins服务,点击jenkins --> 系统管理 --> 插件管理 --> 高级 --> 上传插件上传实际所需要的插件。插件文件为jenkins主目录下的plugins目录中(.jpi格式的文件)。

注:安装的时候,如果报错,一般就是缺少依赖插件。此时先安装依赖,再安装目标插件。根据提示,可完成插件的安装。

方式三

直接从官网下载插件离线安装。下载地址

注:不太推荐这种方法,一是下载包麻;二是下载的包版本高了低了可能会引起更大的困扰。

注:jenkins 默认安装路径

/usr/lib/jenkins/jenkins.war war包
/etc/sysconfig/jenkins jenkins配置文件
/var/lib/jenkins/ 默认的JENKINS_HOME目录
/var/log/jenkins/jenkins.log Jenkins日志文件
/etc/init.d/jenkins Jenkins初始化文件

三、jenkins初始化步骤

step 1

浏览器访问 http://localhost:8080/login?from=%2F
在这里插入图片描述

step 2

在这里插入图片描述

step 3 (花费时间较长)

在这里插入图片描述
在这里插入图片描述

step 4 创建用户

在这里插入图片描述

step 5 实例配置

在这里插入图片描述

step 6 安装成功

在这里插入图片描述
在这里插入图片描述


附:完整操作记录

Linux 平台在线安装 完整操作记录

#从官网获取jenkins yum源的配置文件
[root@localhost ~]# sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
--2020-09-01 04:31:40--  https://pkg.jenkins.io/redhat-stable/jenkins.repo
Resolving pkg.jenkins.io (pkg.jenkins.io)... 151.101.194.133, 151.101.2.133, 151.101.66.133, ...
Connecting to pkg.jenkins.io (pkg.jenkins.io)|151.101.194.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 85
Saving to: ‘/etc/yum.repos.d/jenkins.repo’

100%[=========================================================================================================>] 85          --.-K/s   in 0s      

2020-09-01 04:31:42 (8.64 MB/s) - ‘/etc/yum.repos.d/jenkins.repo’ saved [85/85]

#查看下载的yum源文件
[root@localhost /]# ll /etc/yum.repos.d/ | grep jenkins
-rw-r--r--. 1 root root   85 Nov 29  2016 jenkins.repo

#导入秘钥
[root@localhost /]# sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

#使用yum安装jenkins 
[root@localhost /]# yum install jenkins
base                                                                                                                        | 3.6 kB  00:00:00     
epel/x86_64/metalink                                                                                                        | 2.7 kB  00:00:00     
epel                                                                                                                        | 4.7 kB  00:00:00     
extras                                                                                                                      | 2.9 kB  00:00:00     
jenkins                                                                                                                     | 2.9 kB  00:00:00     
updates                                                                                                                     | 2.9 kB  00:00:00     
(1/4): updates/7/x86_64/primary_db                                                                                          | 4.5 MB  00:00:01     
(2/4): epel/x86_64/updateinfo                                                                                               | 1.0 MB  00:00:04     
(3/4): jenkins/primary_db                                                                                                   |  34 kB  00:00:04     
(4/4): epel/x86_64/primary_db                                                                                               | 6.9 MB  00:31:25     
Resolving Dependencies
--> Running transaction check
---> Package jenkins.noarch 0:2.235.5-1.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================
 Package                           Arch                             Version                                Repository                         Size
===================================================================================================================================================
Installing:
 jenkins                           noarch                           2.235.5-1.1                            jenkins                            63 M

Transaction Summary
===================================================================================================================================================
Install  1 Package

Total download size: 63 M
Installed size: 63 M
Is this ok [y/d/N]: y
Is this ok [y/d/N]: y
Downloading packages:
jenkins-2.235.5-1.1.noarch.rpm                                                                                              |  63 MB  00:00:16     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : jenkins-2.235.5-1.1.noarch                                                                                                      1/1 
  Verifying  : jenkins-2.235.5-1.1.noarch                                                                                                      1/1 

Installed:
  jenkins.noarch 0:2.235.5-1.1                                                                                                                     

Complete!
[root@localhost /]# 
[root@localhost /]# 
[root@localhost ~]# systemctl daemon-reload

#启动jenkins
[root@localhost ~]# systemctl start jenkins
Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for 
details.

#查看jenkins运行状态
[root@localhost ~]# systemctl status jenkins.service
● jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2020-09-01 05:30:45 EDT; 16s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3692 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=1/FAILURE)

Sep 01 05:30:45 localhost.localdomain systemd[1]: Starting LSB: Jenkins Automation Server...
Sep 01 05:30:45 localhost.localdomain runuser[3697]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
Sep 01 05:30:45 localhost.localdomain jenkins[3692]: Starting Jenkins bash: /usr/bin/java: No such file or directory
Sep 01 05:30:45 localhost.localdomain systemd[1]: jenkins.service: control process exited, code=exited status=1
Sep 01 05:30:45 localhost.localdomain jenkins[3692]: [FAILED]
Sep 01 05:30:45 localhost.localdomain systemd[1]: Failed to start LSB: Jenkins Automation Server.
Sep 01 05:30:45 localhost.localdomain systemd[1]: Unit jenkins.service entered failed state.
Sep 01 05:30:45 localhost.localdomain systemd[1]: jenkins.service failed.

#查看本地java环境
[root@localhost ~]# java -version
java version "1.8.0_192"
Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)

#再次启动jenkins
[root@localhost ~]# systemctl start jenkins

#查看jenkins运行状态
[root@localhost ~]# systemctl status jenkins
● jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
   Active: active (running) since Tue 2020-09-01 05:38:49 EDT; 25s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3787 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=0/SUCCESS)
    Tasks: 38
   Memory: 343.1M
   CGroup: /system.slice/jenkins.service
           └─3806 /usr/local/java/bin/java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -jar /usr/...

Sep 01 05:38:47 localhost.localdomain systemd[1]: Starting LSB: Jenkins Automation Server...
Sep 01 05:38:47 localhost.localdomain runuser[3792]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
Sep 01 05:38:49 localhost.localdomain systemd[1]: Started LSB: Jenkins Automation Server.
Sep 01 05:38:49 localhost.localdomain jenkins[3787]: Starting Jenkins [  OK  ]
[root@localhost ~]# 
[root@localhost ~]# /var/lib/jenkins/secrets/initialAdminPassword
-bash: /var/lib/jenkins/secrets/initialAdminPassword: Permission denied
[root@localhost ~]#

[root@localhost ~]# tail -f -n 500 /var/log/jenkins/jenkins.log
Running from: /usr/lib/jenkins/jenkins.war
2020-09-01 09:38:50.155+0000 [id=1]     WARNING winstone.Logger#logInternal: Parameter handlerCountMax is now deprecated
2020-09-01 09:38:50.205+0000 [id=1]     WARNING winstone.Logger#logInternal: Parameter handlerCountMaxIdle is now deprecated
2020-09-01 09:38:50.231+0000 [id=1]     INFO    org.eclipse.jetty.util.log.Log#initialized: Logging initialized @1303ms to org.eclipse.jetty.util.l
og.JavaUtilLog
2020-09-01 09:38:50.321+0000 [id=1]     INFO    winstone.Logger#logInternal: Beginning extraction from war file
2020-09-01 09:38:51.982+0000 [id=1]     WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2020-09-01 09:38:52.094+0000 [id=1]     INFO    org.eclipse.jetty.server.Server#doStart: jetty-9.4.30.v20200611; built: 2020-06-11T12:34:51.929Z; g
it: 271836e4c1f4612f12b7bb13ef5a92a927634b0d; jvm 1.8.0_192-b12
2020-09-01 09:38:52.834+0000 [id=1]     INFO    o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.je
tty.jsp.JettyJspServlet
2020-09-01 09:38:52.950+0000 [id=1]     INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2020-09-01 09:38:52.951+0000 [id=1]     INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2020-09-01 09:38:52.952+0000 [id=1]     INFO    o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 600000ms
2020-09-01 09:38:53.769+0000 [id=1]     INFO    hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/lib/jenkins found at: SystemProp
erties.getProperty("JENKINS_HOME")
2020-09-01 09:38:54.416+0000 [id=1]     INFO    o.e.j.s.handler.ContextHandler#doStart: Started w.@50305a{Jenkins v2.235.5,/,file:///var/cache/jenk
ins/war/,AVAILABLE}{/var/cache/jenkins/war}
2020-09-01 09:38:54.502+0000 [id=1]     INFO    o.e.j.server.AbstractConnector#doStart: Started ServerConnector@4b8729ff{HTTP/1.1, (http/1.1)}{0.0.
0.0:8080}
2020-09-01 09:38:54.503+0000 [id=1]     INFO    org.eclipse.jetty.server.Server#doStart: Started @5575ms
2020-09-01 09:38:54.520+0000 [id=21]    INFO    winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2020-09-01 09:38:57.441+0000 [id=27]    INFO    jenkins.InitReactorRunner$1#onAttained: Started initialization
2020-09-01 09:38:57.535+0000 [id=26]    INFO    jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2020-09-01 09:39:00.297+0000 [id=27]    INFO    jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2020-09-01 09:39:00.314+0000 [id=27]    INFO    jenkins.InitReactorRunner$1#onAttained: Started all plugins
2020-09-01 09:39:00.333+0000 [id=26]    INFO    jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2020-09-01 09:39:02.524+0000 [id=26]    INFO    jenkins.InitReactorRunner$1#onAttained: System config loaded
2020-09-01 09:39:02.525+0000 [id=26]    INFO    jenkins.InitReactorRunner$1#onAttained: System config adapted
2020-09-01 09:39:02.525+0000 [id=26]    INFO    jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2020-09-01 09:39:02.543+0000 [id=26]    INFO    jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2020-09-01 09:39:03.556+0000 [id=40]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Download metadata
2020-09-01 09:39:03.564+0000 [id=40]    INFO    hudson.util.Retrier#start: Attempt #1 to do the action check updates server
2020-09-01 09:39:04.635+0000 [id=27]    INFO    o.s.c.s.AbstractApplicationContext#prepareRefresh: Refreshing org.springframework.web.context.suppo
rt.StaticWebApplicationContext@23de1542: display name [Root WebApplicationContext]; startup date [Tue Sep 01 05:39:04 EDT 2020]; root of context hi
erarchy
2020-09-01 09:39:04.635+0000 [id=27]    INFO    o.s.c.s.AbstractApplicationContext#obtainFreshBeanFactory: Bean factory for application context [or
g.springframework.web.context.support.StaticWebApplicationContext@23de1542]: org.springframework.beans.factory.support.DefaultListableBeanFactory@6
b5862fe
2020-09-01 09:39:04.667+0000 [id=27]    INFO    o.s.b.f.s.DefaultListableBeanFactory#preInstantiateSingletons: Pre-instantiating singletons in org.
springframework.beans.factory.support.DefaultListableBeanFactory@6b5862fe: defining beans [authenticationManager]; root of factory hierarchy
2020-09-01 09:39:05.042+0000 [id=27]    INFO    o.s.c.s.AbstractApplicationContext#prepareRefresh: Refreshing org.springframework.web.context.suppo
rt.StaticWebApplicationContext@2c402855: display name [Root WebApplicationContext]; startup date [Tue Sep 01 05:39:05 EDT 2020]; root of context hi
erarchy
2020-09-01 09:39:05.042+0000 [id=27]    INFO    o.s.c.s.AbstractApplicationContext#obtainFreshBeanFactory: Bean factory for application context [or
g.springframework.web.context.support.StaticWebApplicationContext@2c402855]: org.springframework.beans.factory.support.DefaultListableBeanFactory@2
6dbfc68
2020-09-01 09:39:05.043+0000 [id=27]    INFO    o.s.b.f.s.DefaultListableBeanFactory#preInstantiateSingletons: Pre-instantiating singletons in org.
springframework.beans.factory.support.DefaultListableBeanFactory@26dbfc68: defining beans [filter,legacy]; root of factory hierarchy
2020-09-01 09:39:05.498+0000 [id=27]    INFO    jenkins.install.SetupWizard#init: 

*************************************************************
*************************************************************
*************************************************************

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

ebde3d6742ac422aafd9dc74189f6233

This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************

2020-09-01 09:39:28.478+0000 [id=27]    INFO    jenkins.InitReactorRunner$1#onAttained: Completed initialization
2020-09-01 09:39:28.509+0000 [id=20]    INFO    hudson.WebAppMain$3#run: Jenkins is fully up and running
2020-09-01 09:39:28.879+0000 [id=40]    INFO    h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenI
nstaller
2020-09-01 09:39:28.880+0000 [id=40]    INFO    hudson.util.Retrier#start: Performed the action check updates server successfully at the attempt #1
2020-09-01 09:39:28.881+0000 [id=40]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Download metadata. 25,324 ms
2020-09-01 09:40:57.174+0000 [id=62]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Periodic background build discarder
2020-09-01 09:40:57.175+0000 [id=62]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Periodic background build discarder. 0 ms

Linux 平台离线安装 完整操作记录

找一台可以访问外网的服务器下载jenkins.rpm安装包

[root@m ~]# sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
--2020-09-02 00:49:35--  https://pkg.jenkins.io/redhat-stable/jenkins.repo
Resolving pkg.jenkins.io (pkg.jenkins.io)... 151.101.110.133, 2a04:4e42:400::645, 2a04:4e42:600::645, ...
Connecting to pkg.jenkins.io (pkg.jenkins.io)|151.101.110.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 85
Saving to: ‘/etc/yum.repos.d/jenkins.repo’

100%[====================================================================================================================>] 85          --.-K/s   in 0s

2020-09-02 00:49:35 (5.82 MB/s) - ‘/etc/yum.repos.d/jenkins.repo’ saved [85/85]

[root@m ~]# sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

#下载并保存
[root@m ~]# yum install jenkins --downloadonly --downloaddir=/root
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.bfsu.edu.cn
 * updates: mirror.lzu.edu.cn
base                                                                                                                                   | 3.6 kB  00:00:00
docker-ce-stable                                                                                                                       | 3.5 kB  00:00:00
extras                                                                                                                                 | 2.9 kB  00:00:00
jenkins                                                                                                                                | 2.9 kB  00:00:00
kubernetes                                                                                                                             | 1.4 kB  00:00:00
updates                                                                                                                                | 2.9 kB  00:00:00
(1/2): updates/7/x86_64/primary_db                                                                                                     | 4.5 MB  00:00:00
(2/2): jenkins/primary_db                                                                                                              |  34 kB  00:00:02
Resolving Dependencies
--> Running transaction check
---> Package jenkins.noarch 0:2.235.5-1.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================== Package                              Arch                                Version                                  Repository                            Size
==============================================================================================================================================================Installing:
 jenkins                              noarch                              2.235.5-1.1                              jenkins                               63 M

Transaction Summary
==============================================================================================================================================================Install  1 Package

Total download size: 63 M
Installed size: 63 M
Background downloading packages, then exiting:
jenkins-2.235.5-1.1.noarch.rpm                                                                                                         |  63 MB  00:00:08
exiting because "Download Only" specified

[root@m ~]# ll
total 122172
-rw-------. 1 root root     5570 Jun  1  2019 anaconda-ks.cfg
-rw-r--r--. 1 root root 66270257 Aug 17 12:36 jenkins-2.235.5-1.1.noarch.rpm
-rw-------. 1 root root     5300 Jun  1  2019 original-ks.cfg

找另一台不能访问外网的服务器,使用工具将下载好的rpm上传至服务器

#安装jenkins
[root@m ~]# rpm -ivh jenkins-2.235.5-1.1.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:jenkins-2.235.5-1.1              ################################# [100%]
[root@m ~]#

附:配置文件

/etc/sysconfig/jenkins

## Path:        Development/Jenkins
## Description: Jenkins Automation 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"

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Java executable to run Jenkins
# When left empty, we'll try to find the suitable Java.
#
JENKINS_JAVA_CMD=""

## 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"

## Type:        string
## Default: "false"
## ServiceRestart: jenkins
#
# Whether to skip potentially long-running chown at the
# $JENKINS_HOME location. Do not enable this, "true", unless
# you know what you're doing. See JENKINS-23273.
#
#JENKINS_INSTALL_SKIP_CHOWN="false"

## Type: string
## Default:     "-Djava.awt.headless=true"
## ServiceRestart: jenkins
#
# Options to pass to java when running Jenkins.
#
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true"

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

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# IP address Jenkins listens on for HTTP requests.
# Default is all interfaces (0.0.0.0).
#
JENKINS_LISTEN_ADDRESS=""

## Type:        integer(0:65535)
## Default:     ""
## ServiceRestart: jenkins
#
# HTTPS port Jenkins is listening on.
# Default is disabled.
#
JENKINS_HTTPS_PORT=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Path to the keystore in JKS format (as created by the JDK 'keytool').
# Default is disabled.
#
JENKINS_HTTPS_KEYSTORE=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Password to access the keystore defined in JENKINS_HTTPS_KEYSTORE.
# Default is disabled.
#
JENKINS_HTTPS_KEYSTORE_PASSWORD=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# IP address Jenkins listens on for HTTPS requests.
# Default is disabled.
#
JENKINS_HTTPS_LISTEN_ADDRESS=""

## Type:        integer(0:65535)
## Default:     ""
## ServiceRestart: jenkins
#
# HTTP2 port Jenkins is listening on.
# Default is disabled.
#
# Notice: HTTP2 support may require additional configuration, see Winstone
# documentation for more information.
#
JENKINS_HTTP2_PORT=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# IP address Jenkins listens on for HTTP2 requests.
# Default is disabled.
#
# Notice: HTTP2 support may require additional configuration, see Winstone
# documentation for more information.
#
JENKINS_HTTP2_LISTEN_ADDRESS=""

## Type:        integer(1:9)
## Default:     5
## ServiceRestart: jenkins
#
# Debug level for logs -- the higher the value, the more verbose.
# 5 is INFO.
#
JENKINS_DEBUG_LEVEL="5"

## Type:        yesno
## Default:     no
## ServiceRestart: jenkins
#
# Whether to enable access logging or not.
#
JENKINS_ENABLE_ACCESS_LOG="no"

## Type:        integer
## Default:     100
## ServiceRestart: jenkins
#
# Maximum number of HTTP worker threads.
#
JENKINS_HANDLER_MAX="100"

## Type:        integer
## Default:     20
## ServiceRestart: jenkins
#
# Maximum number of idle HTTP worker threads.
#
JENKINS_HANDLER_IDLE="20"

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Folder for additional jar files to add to the Jetty class loader.
# See Winstone documentation for more information.
# Default is disabled.
#
JENKINS_EXTRA_LIB_FOLDER=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Pass arbitrary arguments to Jenkins.
# Full option list: java -jar jenkins.war --help
#
JENKINS_ARGS=""

参考文章

参考博客 https://www.jianshu.com/p/0391e225e4a6

参考博客 https://www.cnblogs.com/jakaBlog/p/11284451.html

参考博客 https://blog.csdn.net/qq_38252039/article/details/89791247

参考博客 https://www.reinforce.cn/t/658.html

参考博客 https://blog.csdn.net/ck3207/article/details/93900440

官方文档 https://jenkins.io/zh/doc/book/installing/

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值