Jenkins安装和配置-Linux篇

本文详细介绍了在Linux上安装Jenkins的过程,包括Tomcat的安装、Jenkins的部署以及配置步骤,如系统配置、全局工具设置、Maven、JDK和Git的配置。同时,针对在配置过程中可能遇到的无法访问、多实例报错和nohup后台启动失败等问题,给出了相应的解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


本文主要介绍在Linux服务器上安装jenkins,采用在Tomcat上部署Jenkins.war包的方式进行安装。服务器上之前已安装JDK等基础环境,此处不再赘述。

安装包下载

Tomcat:本文使用的Tomcat9
Jenkins:点击下载

Tomcat安装

将下载的Tomcat的软件包解压,然后执行bin目录下的startup.sh脚本,启动Tomcat。通过浏览器访问Tomcat,看是否正常启动。

Jenkins安装

将下载的Jenkins的软件包拷贝到Tomcat的webapps目录下,重启Tomcat,访问jenkins。

Jenkins配置

系统配置

  1. 全局工具配置
    • 配置maven的setting.xml文件 在这里插入图片描述
    • 配置JDK
      在这里插入图片描述
    • 配置Git
      在这里插入图片描述
    • 配置Maven
      在这里插入图片描述
  2. 创建任务
    • 新建任务,输入任务名,选择构建一个自由风格的软件项目,确定
      在这里插入图片描述
    • 源码管理,配置代码仓库的地址,选择鉴权信息。 在这里插入图片描述
      如果是第一次配置,可点击 添加 - Jenkins 添加鉴权信息
      在这里插入图片描述
    • 构建触发器:根据需要配置触发构建的规则,可以不配置通过手动触发构建。
      在这里插入图片描述
    • 构建环境:配置构建环境信息,可不配置。在这里插入图片描述
    • 构建:选择全局工具配置中配置的maven,填写构建目标。如果构建完成需要执行别的操作可以点击 增加构建步骤选择后续操作。在这里插入图片描述
    • 构建后动作:配置构建完成后的操作在这里插入图片描述
      配置完成后点击保存按钮,任务创建完成。

遇到的问题

1. jenkins无法访问

现象:Tomcat可以正常访问,jenkins无法访问。查看Tomcat的运行日志catalina.out有如下报错:
18-May-2020 15:52:02.008 WARNING [http-nio-8080-exec-1] org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/scripts/yui/yahoo/yahoo-debug.js] to the cache for web application [/jenkins] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache 18-May-2020 15:52:02.009 WARNING [http-nio-8080-exec-1] org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/scripts/yui/element/element-debug.js] to the cache for web application [/jenkins] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache 18-May-2020 15:52:02.010 WARNING [http-nio-8080-exec-1] org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/META-INF/MANIFEST.MF] to the cache for web application [/jenkins] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache

18-May-2020 15:52:06.344 WARNING [Handling GET /jenkins/login from 111.18.96.18 : http-nio-8080-exec-3] org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/WEB-INF/side-files/hudson/util/HudsonIsLoading/index.html] to the cache for web application [/jenkins] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache 18-May-2020 15:52:06.347 WARNING [Handling GET /jenkins/login from 111.18.96.18 : http-nio-8080-exec-3] org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/WEB-INF/classes/hudson/util/HudsonIsLoading/login.groovy] to the cache for web application [/jenkins] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache 18-May-2020 15:52:06.348 WARNING [Handling GET /jenkins/login from 111.18.96.18 : http-nio-8080-exec-3] org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/WEB-INF/classes/hudson/util/HudsonIsLoading/login.default.groovy] to the cache for web application [/jenkins] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache

解决方法:
修改Tomcat的 conf/context.xml ,在之前添加如下代码:

<Resources cachingAllowed="true" cacheMaxSize="102400" />

2.访问jenkins报错有多个jenkins实例

Jenkins detected that you appear to be running more than one instance of Jenkins
解决方法:
使用ps命令查看Tomcat是否启动了两个,如果是杀掉Tomcat进程后重新启动。

3.nohup启动后台进程失败

问题现象:
使用nohup命令启动后台进程,显示命令执行成功,但是后台进程未启动
问题原因:
jenkins在执行完一次构建后会杀死这次build的所有子进程
解决方法:
在脚本中加入如下代码,修改buildId

BUILD_ID=DONTKILLME
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值