本文将介绍在centos上安装jenkins的方法。
Jenkins通常作为一个独立的应用程序在其自己的流程中运行, 内置Java servlet 容器/应用程序服务器(Jetty)。
安装方法一:
直接去Jenkins官网下载war包,放在tomcat底下。
1.进入https://www.jenkins.io/download/官网,选择war的下载地址
2.在shell中下载到centos服务器
#下载war包到centos里面
[root@VM_21_126_centos ~]# wget https://get.jenkins.io/war-stable/2.249.2/jenkins.war
--2020-10-13 10:25:21-- https://get.jenkins.io/war-stable/2.249.2/jenkins.war
Resolving get.jenkins.io (get.jenkins.io)... 52.167.253.43
Connecting to get.jenkins.io (get.jenkins.io)|52.167.253.43|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://mirrors.tuna.tsinghua.edu.cn/jenkins/war-stable/2.249.2/jenkins.war [following]
--2020-10-13 10:25:22-- https://mirrors.tuna.tsinghua.edu.cn/jenkins/war-stable/2.249.2/jenkins.war
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 67399569 (64M) [application/java-archive]
Saving to: ‘jenkins.war’
100%[============================================================================================================>] 67,399,569 7.47MB/s in 15s
2020-10-13 10:25:38 (4.18 MB/s) - ‘jenkins.war’ saved [67399569/67399569]
3.把war移动到tomcat服务器底下(没有tomcat的话自行安装或者使用docker进行安装)
#把war包移到tomcat底下
[root@VM_21_126_centos ~]# mv jenkins.war /opt/apache-tomcat-9.0.24/webapps/
4.重启tomcat部署好了
#切换到tomcat的bin目录,安装目录具体看你自己的安装位置
[root@VM_21_126_centos ~]# cd /opt/apache-tomcat-9.0.24/bin
#重启tomcat
[root@VM_21_126_centos bin]# ./startup.sh
5.浏览器输入http://localhost:8080/jenkins,可以看到下面界面就说明安装成功了
6.根据提示到/root/.jenkins//secrets/initialAdminPassword
#进入容器
[root@VM_21_126_centos bin]# cat /var/jenkins_home/secrets/initialAdminPassword
b83cf557ad894d0699da5a16726d6779
安装方法二:
通过docker进行Jenkins安装,docker的安装可以看我之前写的教程https://blog.csdn.net/linfen1520/article/details/108725723
1.从docker中查询Jenkins镜像
#搜索Jenkins镜像
[root@VM_21_126_centos bin]# docker search jenkins
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/jenkins Official Jenkins Docker image 4931 [OK]
docker.io docker.io/jenkins/jenkins The leading open source automation server 2251
docker.io docker.io/jenkinsci/blueocean https://jenkins.io/projects/blueocean 570
docker.io docker.io/jenkinsci/jenkins Jenkins Continuous Integration and Deliver... 383
docker.io docker.io/jenkins/jnlp-slave a Jenkins agent which can connect to Jenki... 134 [OK]
docker.io docker.io/jenkinsci/jnlp-slave A Jenkins slave using JNLP to establish co... 127 [OK]
docker.io docker.io/jenkinsci/slave Base Jenkins slave docker image 65 [OK]
docker.io docker.io/jenkins/slave base image for a Jenkins Agent, which incl... 43 [OK]
docker.io docker.io/jenkinsci/ssh-slave A Jenkins SSH Slave docker image 43 [OK]
docker.io docker.io/cloudbees/jenkins-enterprise CloudBees Jenkins Enterprise (Rolling rele... 34 [OK]
docker.io docker.io/jenkins/ssh-slave A Jenkins slave using SSH to establish con... 34 [OK]
docker.io docker.io/bitnami/jenkins Bitnami Docker Image for Jenkins 27 [OK]
docker.io docker.io/h1kkan/jenkins-docker ?? Extended Jenkins docker image, bundled w... 27
docker.io docker.io/xmartlabs/jenkins-android Jenkins image for Android development. 27 [OK]
docker.io docker.io/openshift/jenkins-2-centos7 A Centos7 based Jenkins v2.x image for use... 23
docker.io docker.io/cloudbees/jenkins-operations-center CloudBees Jenkins Operation Center (Rollin... 14 [OK]
docker.io docker.io/openshift/jenkins-slave-maven-centos7 A Jenkins slave image with OpenJDK 1.8 and... 11
docker.io docker.io/openshift/jenkins-slave-base-centos7 A Jenkins slave base image. DEPRECATED: se... 7
docker.io docker.io/trion/jenkins-docker-client Jenkins CI server with docker client 6 [OK]
docker.io docker.io/publicisworldwide/jenkins-slave Jenkins Slave based on Oracle Linux 5 [OK]
docker.io docker.io/openshift/jenkins-1-centos7 DEPRECATED: A Centos7 based Jenkins v1.x i... 4
docker.io docker.io/ansibleplaybookbundle/jenkins-apb An APB which deploys Jenkins CI 1 [OK]
docker.io docker.io/amazeeio/jenkins-slave A jenkins slave that connects to a master ... 0 [OK]
docker.io docker.io/jameseckersall/jenkins docker-jenkins (based on openshift jenkins... 0 [OK]
docker.io docker.io/mashape/jenkins Just a jenkins image with the AWS cli adde... 0 [OK]
2.通过dockers拉取Jenkins系统镜像
#拉取Jenkins镜像
[root@VM_21_126_centos bin]# docker pull jenkinsci/blueocean
Using default tag: latest
Trying to pull repository docker.io/jenkinsci/blueocean ...
latest: Pulling from docker.io/jenkinsci/blueocean
df20fa9351a1: Pull complete
1cb481a13af0: Pull complete
f5efbd400588: Pull complete
f2d0037ca04a: Pull complete
f50c4373c0c3: Pull complete
cfa42149c07e: Pull complete
e6784003bb85: Pull complete
73a1e720e18b: Pull complete
2e41633b95a1: Pull complete
83587819eac3: Pull complete
1389b752912a: Pull complete
feb326d4942c: Pull complete
05fc0701116d: Pull complete
06a6bc155e06: Pull complete
c3226bfea341: Pull complete
bcc24b074067: Pull complete
Digest: sha256:3bf41f535186cbb410452910607b38790357cbef789f3ff19ae8e8cd67a78e04
Status: Downloaded newer image for docker.io/jenkinsci/blueocean:latest
3.启动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
jenkinsci/blueocean
容器的端口8080到主机上的端口8080。 第一个数字代表主机上的端口,而最后一个代表容器的端口。因此,如果您为此选项指定 -p 49000:8080
,您将通过端口49000访问主机上的Jenkins。jenkins-data
卷也可以 docker volume create
命令创建: docker volume create jenkins-data
代替映射 /var/jenkins_home
目录转换为Docker卷,还 可以将此目录映射到计算机本地文件系统上的目录。 例如,指定该选项 -v $HOME/jenkins:/var/jenkins_home
会将容器的 /var/jenkins_home
目录映射 到 本地计算机上目录中的 jenkins
子目录, 该$HOME目录通常是 /Users//jenkins
或`/home/-v /var/run/docker.sock:/var/run/docker.sock: /var/run/docker.sock
表示Docker守护程序通过其监听的基于Unix的套接字。 该映射允许 jenkinsci/blueocean
容器与Docker守护进程通信#按实际挂载jdk、maven、数据包等目录
docker run \
-u root \
--rm \
-d \
-p 8040:8080 \
-p 50000:50000 \
-v /var/jenkins_home:/var/jenkins_home \
-v /usr/lib/jvm/:/usr/lib/jvm/ \
-v /opt/data/:/opt/data/ \
-v /opt/maven/apache-maven-3.6.3:/opt/maven/apache-maven-3.6.3 \
-v /var/run/docker.sock:/var/run/docker.sock \
--name jenkins \
jenkinsci/blueocean
5.查看进程是否运行
#查看进程
[root@VM_21_126_centos bin]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
156316c9206f jenkinsci/blueocean "/sbin/tini -- /us..." 24 seconds ago Up 21 seconds 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp optimistic_dubinsky
看到create时间说明正在运行,如果看到exit(状态码)说明异常退出
6.查看log日志
#查看运行日志 logs后面为容器id,也可以通过定义别名
[root@VM_21_126_centos bin]# docker logs 156316c9206f
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2020-10-13 02:55:45.338+0000 [id=1] INFO org.eclipse.jetty.util.log.Log#initialized: Logging initialized @1530ms to org.eclipse.jetty.util.log.JavaUtilLog
2020-10-13 02:55:45.613+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2020-10-13 02:55:47.627+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2020-10-13 02:55:47.763+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: jetty-9.4.30.v20200611; built: 2020-06-11T12:34:51.929Z; git: 271836e4c1f4612f12b7bb13ef5a92a927634b0d; jvm 1.8.0_262-b10
2020-10-13 02:55:48.379+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2020-10-13 02:55:48.548+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2020-10-13 02:55:48.548+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2020-10-13 02:55:48.555+0000 [id=1] INFO o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 600000ms
2020-10-13 02:55:49.492+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2020-10-13 02:55:50.297+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@55e7a35c{Jenkins v2.249.2,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2020-10-13 02:55:50.731+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@7eecb5b8{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
7.浏览器输入http://localhost:8080,看到下面界面就说明安装成功
8.等待一段时间后就可以看到下面界面
我们根据提示获取密钥:
#进入容器
[root@VM_21_126_centos bin]# docker exec -it 156316c9206f /bin/bash
#查看密钥
bash-5.0# cat /var/jenkins_home/secrets/initialAdminPassword
b83cf557ad894d0699da5a16726d6779
复制上面的b83cf557ad894d0699da5a16726d6779密钥拿到浏览器的编辑框黏贴,点击继续等待一段时间。
9.安装插件,选择安装推荐的插件进行安装
10.自动安装插件,等待安装完成
11.配置管理员账号,点击保存并完成
12.进行实例配置,默认就好了,保存并完成
13.开始使用Jenkins
14.安装完成,输入账号密码进行登录
15.进入Jenkins还有部分菜单没有中文化,需重启一次。
安装完成教程到此结束,接下来将整合docke实现自动化部署Spring Boot项目,请看下一个教程。