一、修改Jenkins存储目录,并创建软连接到原目录 1.停止服务器上的Jenkins服务 [root@172 ~]# systemctl stop jenkins 2.保全期间原目录Jenkins存储目录(/var/lib/jenkins)保留,将数据复制到新存储目录(/home/jenkins)后,修改原目录Jenkins存储目录(/var/lib/jenkins)的名字 [root@172 ~]# cp -rf /var/lib/jenkins /home/jenkins #确认复制完成 [root@172 ~]# mv /var/lib/jenkins /var/lib/jenkins.bak #重命名原存储目录 3.创建软链接 [root@172 ~]# ln -s /home/jenkins /var/lib/jenkins 4.启动Jenkins [root@172 ~]# systemctl start jenkins
二、启动jenkins报错问题记录
1、报错信息:Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details. [root@172 ~]# 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@172 ~]# systemctl status jenkins ● jenkins.service - Jenkins Continuous Integration Server Loaded: loaded (/usr/lib/systemd/system/jenkins.service; disabled; vendor preset: disabled) Active: failed (Result: start-limit) since Tue 2023-02-21 18:59:14 CST; 30s ago Process: 9388 ExecStart=/usr/bin/jenkins (code=exited, status=1/FAILURE) Main PID: 9388 (code=exited, status=1/FAILURE) Feb 21 18:59:14 localhost.localdomain systemd[1]: Failed to start Jenkins Continuous Integration Server. Feb 21 18:59:14 localhost.localdomain systemd[1]: Unit jenkins.service entered failed state. Feb 21 18:59:14 localhost.localdomain systemd[1]: jenkins.service failed. Feb 21 18:59:14 localhost.localdomain systemd[1]: jenkins.service holdoff time over, scheduling restart. Feb 21 18:59:14 localhost.localdomain systemd[1]: Stopped Jenkins Continuous Integration Server. Feb 21 18:59:14 localhost.localdomain systemd[1]: start request repeated too quickly for jenkins.service Feb 21 18:59:14 localhost.localdomain systemd[1]: Failed to start Jenkins Continuous Integration Server. Feb 21 18:59:14 localhost.localdomain systemd[1]: Unit jenkins.service entered failed state. Feb 21 18:59:14 localhost.localdomain systemd[1]: jenkins.service failed.
解决方法: 排查jenkins安装所需目录是否存在 [root@172 ~]# vim /etc/sysconfig/jenkins
/var/lib/jenkins /var/log/jenkins /var/cache/jenkins 若不存在,创建后重新执行yum install jenkins 并重新加载服务 systemctl daemon-reload 启动Jenkins systemctl start jenkins
原因分析 可能出现Jenkins目录不全,或问题2权限不同问题需确认
2、报错信息:Jenkins throwing error: jenkins.model.InvalidBuildsDir: ${ITEM_ROOTDIR}/builds does not exist and probably cannot be created
解决方式: 统一修改jenkins相关目录权限(上个问题查看用户为jenkins) [root@172 ~]# chown -R jenkins:jenkins /var/lib/jenkins [root@172 ~]# chown -R jenkins:jenkins /var/log/jenkins [root@172 ~]# chown -R jenkins:jenkins /var/cache/jenkins [root@172 ~]# chown -R jenkins:jenkins /home/jenkins
原因分析 使用不通用户移动Jenkins相关目录造成的用户不同问题,统一用户后正常
3、报错信息:java.lang.IllegalStateException: An attempt to save the global configuration was made before it was loaded
解决方式:
原因分析 升级Jenkins版本后,/var/lib/jenkins/plugins/文件夹中的hpi文件异常,需下载下载hpi文件,并将其放到/var/lib/jenkins/plugins/文件夹.
4、报错信息: [root@172 ~]# 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@172 ~]# systemctl status jenkins
解决方式: 如果通过 systemctl 不能解决Jenkins重启的问题,那就用Jenkins自带的启停来解决 [root@172 ~]# cd /etc/init.d # 一般在这里 [root@172 ~]# ./jenkins stop #停止jenkins服务 [root@172 ~]# ./jenkins status #检查jenkins状态 [root@172 ~]# ./jenkins start #启动jenkins
原因分析 Jenkins 如果使用 Systemd 来管理服务,通常会在 /etc/systemd/system/ 目录中找到 Jenkins 的 Systemd 单元文件 jenkins.service ,但是,我并没有在 /etc/systemd/system/ 下看到 jenkins.service ,说明 Jenkins 并没有使用 Systemd 来管理服务,所以 sudo systemctl restart jenkins命令就无法执行Jenkins 安装目录中的脚本 。
操作 命令 启动 Jenkins 服务 /etc/init.d/jenkins start 停止 Jenkins 服务 /etc/init.d/jenkins stop 重启 Jenkins 服务 /etc/init.d/jenkins restart 检查 Jenkins 服务的 状态 /etc/init.d/jenkins status 强制重新加载 Jenkins 服务配置 /etc/init.d/jenkins force-reload
三、修改Jenkins存储目录,指定新目录为存储目录 1.停止服务器上的Jenkins服务 [root@172 ~]# systemctl stop jenkins 2.保全期间原目录Jenkins存储目录(/var/lib/jenkins)保留,将数据复制到新存储目录(/home/jenkins) [root@172 ~]# cp -rf /var/lib/jenkins /home/jenkins #确认复制完成 3.修改Jenkins配置文件中指定存储目录参数 [root@172 ~]# vim /etc/sysconfig/jenkins 将JENKINS_HOME="/var/lib/jenkins"修改为将JENKINS_HOME="/home/jenkins"
4.修改全局环境变量配置使新存储目录生效 [root@172 ~]# vim /etc/profile export JENKINS_HOME=/home/jenkins #在末尾添加
[root@172 ~]# source /etc/profile #重新加载全局变量生效 [root@172 ~]# systemctl start jenkins #启动jenkins,如出现问题参考二
四、Jenkins迁移至新服务器 1.在新服务器中安装jenkins并首次启动,可访问Jenkins后直接停止jenkins(不用登陆,主要为生成存储目录) 2.备份旧服务器存储目录中config.xml文件,jobs文件夹,users文件夹和plugins文件夹。 config.xml是存放配置信息的 jobs是存放创建的工程项目的 users是存放用户账信息的 plugins是存放插件的 3.将备份的config.xml文件,jobs文件夹,users文件夹和plugins文件夹放到新服务器Jenkins存储目录 4.再次启动新服务器Jenkins,使用与旧服务器相同用户登录