注意:本机ip 地址为192.168.1.103
docker 命令
docker run -d -p 8080:8080 -p 50000:50000 -v jenkins_data:/var/jenkins_home jenkins/jenkins:lts
访问地址:http://192.168.1.103:8080/login?from=%2F
首次登录需要密码,查看启动日记就可以了,密码在最下面
[root@localhost /]# docker logs b83c93f390bd
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2021-03-20 03:11:44.849+0000 [id=1] INFO org.eclipse.jetty.util.log.Log#initialized: Logging initialized @200ms to org.eclipse.jetty.util.log.JavaUtilLog
2021-03-20 03:11:44.922+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2021-03-20 03:11:46.039+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2021-03-20 03:11:46.093+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: jetty-9.4.33.v20201020; built: 2020-10-20T23:39:24.803Z; git: 1be68755656cef678b79a2ef1c2ebbca99e25420; jvm 1.8.0_242-b08
2021-03-20 03:11:46.402+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2021-03-20 03:11:46.433+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2021-03-20 03:11:46.433+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2021-03-20 03:11:46.434+0000 [id=1] INFO o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 660000ms
2021-03-20 03:11:46.776+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2021-03-20 03:11:46.850+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@1b58ff9e{Jenkins v2.263.2,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2021-03-20 03:11:46.866+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@126253fd{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2021-03-20 03:11:46.866+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: Started @2217ms
2021-03-20 03:11:46.867+0000 [id=23] INFO winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2021-03-20 03:11:47.893+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: Started initialization
2021-03-20 03:11:47.906+0000 [id=33] INFO jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2021-03-20 03:11:48.936+0000 [id=33] INFO jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2021-03-20 03:11:48.939+0000 [id=37] INFO jenkins.InitReactorRunner$1#onAttained: Started all plugins
2021-03-20 03:11:48.944+0000 [id=40] INFO jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2021-03-20 03:11:49.564+0000 [id=34] INFO jenkins.InitReactorRunner$1#onAttained: System config loaded
2021-03-20 03:11:49.564+0000 [id=34] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted
2021-03-20 03:11:49.576+0000 [id=41] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2021-03-20 03:11:49.585+0000 [id=37] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2021-03-20 03:11:49.596+0000 [id=56] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Download metadata
2021-03-20 03:11:49.610+0000 [id=56] INFO hudson.util.Retrier#start: Attempt #1 to do the action check updates server
2021-03-20 03:11:50.289+0000 [id=34] INFO o.s.c.s.AbstractApplicationContext#prepareRefresh: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@48e7c5a6: display name [Root WebApplicationContext]; startup date [Sat Mar 20 03:11:50 UTC 2021]; root of context hierarchy
2021-03-20 03:11:50.289+0000 [id=34] INFO o.s.c.s.AbstractApplicationContext#obtainFreshBeanFactory: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@48e7c5a6]: org.springframework.beans.factory.support.DefaultListableBeanFactory@b156311
2021-03-20 03:11:50.297+0000 [id=34] INFO o.s.b.f.s.DefaultListableBeanFactory#preInstantiateSingletons: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@b156311: defining beans [authenticationManager]; root of factory hierarchy
2021-03-20 03:11:50.411+0000 [id=34] INFO o.s.c.s.AbstractApplicationContext#prepareRefresh: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@76cb2d70: display name [Root WebApplicationContext]; startup date [Sat Mar 20 03:11:50 UTC 2021]; root of context hierarchy
2021-03-20 03:11:50.411+0000 [id=34] INFO o.s.c.s.AbstractApplicationContext#obtainFreshBeanFactory: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@76cb2d70]: org.springframework.beans.factory.support.DefaultListableBeanFactory@72c3778b
2021-03-20 03:11:50.412+0000 [id=34] INFO o.s.b.f.s.DefaultListableBeanFactory#preInstantiateSingletons: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@72c3778b: defining beans [filter,legacy]; root of factory hierarchy
2021-03-20 03:11:50.620+0000 [id=34] 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:
f3701025a2d54ef981978b4c7f6e19b4 #密码
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
2 选择插件来安装
保持默认插件不动并务必勾选 Publish Over SSH 插件
等待安装完成,存在可能存在的插件安装不成功,登录进去后看哪些没有安装的再重新安装过
到此我们Jenkins 安装已完成
3.安装必备插件
Deploy to container:自动化部署插件件
Delivery pipeline:用于查看构建状态和时间的视图插件
Multijob:多项目构建插件
NodeJS:构建前端应用
注意:这里因为要安装多个插件,可以对每个插件都进行查询勾选上之后再统一安装,勾选之后就会选上不会说查询其他插件之后会不见
点击直接安装即可
运气好就是一次就安装成功
然后重启Jenkins ,直接使用docker 命令重启就好了
[root@localhost /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b83c93f390bd jenkins/jenkins:lts "/sbin/tini -- /usr/…" 7 minutes ago Up About a minute 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp clever_nightingale
[root@localhost /]# docker restart b83c93f390bd
b83c93f390bd
[root@localhost /]#
4.全局配置
我们要配置jdk,maven, nodejs这三个环境
进入容器中,并创建envs
[root@localhost jenkins_data]# docker exec -it b83c93f390bd /bin/bash
jenkins@b83c93f390bd:/$ cd /var/jenkins_home/
jenkins@b83c93f390bd:~$ ls
config.xml jenkins.install.UpgradeWizard.state plugins userContent
copy_reference_file.log jenkins.model.JenkinsLocationConfiguration.xml queue.xml.bak users
hudson.model.UpdateCenter.xml jenkins.telemetry.Correlator.xml secret.key war
hudson.plugins.deploy.DeployPublisher.Migrator jobs secret.key.not-so-secret workflow-libs
hudson.plugins.git.GitTool.xml logs secrets
identity.key.enc nodeMonitors.xml tini_pub.gpg
jenkins.install.InstallUtil.lastExecVersion nodes updates
jenkins@b83c93f390bd:~$ mkdir envs
退出容器,进入当前服务器路路径[root@localhost /]# cd /var/lib/docker/volumes/jenkins_data/_data
[root@localhost /]# cd /var/lib/docker/volumes/jenkins_data/_data
[root@localhost _data]# ls
config.xml jenkins.install.InstallUtil.lastExecVersion nodes updates
copy_reference_file.log jenkins.install.UpgradeWizard.state plugins userContent
envs #为映射容器中的文件 jenkins.model.JenkinsLocationConfiguration.xml queue.xml.bak users
hudson.model.UpdateCenter.xml jenkins.telemetry.Correlator.xml secret.key war
hudson.plugins.deploy.DeployPublisher.Migrator jobs secret.key.not-so-secret workflow-libs
hudson.plugins.git.GitTool.xml logs secrets
identity.key.enc nodeMonitors.xml tini_pub.gpg
[root@localhost _data]#
测试是否映射成功,我们再envs 下创建一个文件夹再进入容器中查看
[root@localhost envs]# vi test.txt
[root@localhost envs]# ls
test.txt
容器中,说明映射成功
jenkins@b83c93f390bd:/$ cd var/jenkins_home/
jenkins@b83c93f390bd:~$ ls
config.xml hudson.plugins.deploy.DeployPublisher.Migrator jenkins.install.UpgradeWizard.state logs queue.xml.bak tini_pub.gpg war
copy_reference_file.log hudson.plugins.git.GitTool.xml jenkins.model.JenkinsLocationConfiguration.xml nodeMonitors.xml secret.key updates workflow-libs
envs identity.key.enc jenkins.telemetry.Correlator.xml nodes secret.key.not-so-secret userContent
hudson.model.UpdateCenter.xml jenkins.install.InstallUtil.lastExecVersion jobs plugins secrets users
jenkins@b83c93f390bd:~$ cd envs/
jenkins@b83c93f390bd:~/envs$ ls
test.txt
jenkins@b83c93f390bd:~/envs$
上传文件到映射文件中
容器中
由于我们当前的用户为root 用户
需要修改为Jenkins
修改服务器下文件角色权限
创建用户
[root@localhost ~]# adduser tone
[root@localhost ~]# passwd tone
更改用户 tone 的密码 。
新的 密码:
无效的密码: 密码未通过字典检查 - 过于简单化/系统化
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]#
密码过于简单直接就一直输入12345678 就好了
重新切换文件权限,已经更改为tone
[root@localhost envs]# chown tone:tone *.*
[root@localhost envs]# ll
总用量 215516
-rw-r--r--. 1 tone tone 9506321 3月 20 12:33 apache-maven-3.6.3-bin.tar.gz
-rw-r--r--. 1 tone tone 189784266 3月 20 12:34 jdk-8u152-linux-x64.tar.gz
-rw-r--r--. 1 tone tone 21385948 3月 20 12:34 node-v14.16.0-linux-x64.tar.xz
-rw-r--r--. 1 tone tone 5 3月 20 12:31 test.txt
[root@localhost envs]#
再看回容器中文件的权限,已经进行了更改
解压文件
# jdk解压
tar -zxvf jdk-8u152-linux-x64.tar.gz
# maven 解压
tar -zxvf apache-maven-3.6.3-bin.tar.gz
# node.js 解压
xz -d node-v14.16.0-linux-x64.tar.xz
# xz 命令把 tar.xz 解压为了node-v14.16.0-linux-x64.tar
tar -xvf node-v14.16.0-linux-x64.tar
最终解压后的文件
5. 回到Jenkins 进行配置
系统管理 ==》全局工具配置
保存即可
6.配置maven setting.xml 文件,主要配置仓库路径和中央仓库下载地址
<localRepository>/var/jenkins_home/envs/apache-maven-3.6.3/repo</localRepository>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
再容器中 /var/jenkins_home 下 创建 .npmrc
配置 加速地址
registry=https://registry.npm.taobao.org
7 .配置远程服务器地址
open SSH
新开一台服务器
IP 192.168.1.102
并创建文件夹 mydata
8 新建项目
集群多项目需创建文件夹来进行管理
创建maven 组视图
开始创建任务
配置gitee 项目地址 及账户名密码
注意:构建过程出现权限出错,主要是maven 中的文件还是root 更改过来就可以执行了
更改后可以看到可以执行了就很容易构建成功了
9 发布到目标服务器
本地执行成功后我们需要发布到目标服务器上去
重新配置工程,添加构建步骤
再看一下102 服务器的文件夹
传输成功后之后的执行部署之类的就非常简单了,就是基本的shell 命令了