简体   繁体   English

更改JENKINS_HOME时出现“无法创建主目录”错误

[英]“Unable to create home directory” error when changing JENKINS_HOME

Jenkins was running all fine on a RedHat Linux machine (a clean EC2 machine on AWS), until I decided to change the JENKINS_HOME . Jenkins在RedHat Linux机器(AWS上一台干净的EC2机器)上运行良好,直到我决定更换JENKINS_HOME I simply moved the Jenkins directory from /var/lib/jenkins to /home/ec2-user/jenkins and then created a symlink. 我只是将Jenkins目录从/var/lib/jenkins/home/ec2-user/jenkins ,然后创建了一个符号链接。 (I followed the first answer to this question: Change JENKINS_HOME on Red Hat Linux? ). (我跟着这个问题的第一个答案: 在Red Hat Linux上更改JENKINS_HOME? )。

However when I restart Jenkins I get the error: 但是,当我重新启动Jenkins时,我得到错误:

Unable to create the home directory '/var/lib/jenkins'. 无法创建主目录'/ var / lib / jenkins'。 This is most likely a permission problem. 这很可能是一个权限问题。 To change the home directory, use JENKINS_HOME environment variable or set the JENKINS_HOME system property. 要更改主目录,请使用JENKINS_HOME环境变量或设置JENKINS_HOME系统属性。

I tried changing JENKINS_HOME in /etc/sysconfig/jenkins , setting it to the new folder (which I suppose defeats the point of a symlink?) and I still get the same error 我尝试在/etc/sysconfig/jenkins更改JENKINS_HOME ,将其设置为新文件夹(我认为它会破坏符号链接的位置?)并且我仍然得到相同的错误

Unable to create the home directory '/home/ec2-user/jenkins'. 无法创建主目录'/ home / ec2-user / jenkins'。

It is for backup purposes, so that I have all Jenkins data in a mounted external data storage (AWS Elastic File System). 它用于备份目的,因此我将所有Jenkins数据放在已安装的外部数据存储(AWS弹性文件系统)中。

I've figured it out. 我已经明白了。 This error was persisting because the /jenkins/ folder needs to be accessible to user 'jenkins' to run processes, but it couldn't access this folder because it is belongs to the particular logged in user. 此错误是持久的,因为/ jenkins /文件夹需要用户'jenkins'才能访问以运行进程,但它无法访问此文件夹,因为它属于特定的登录用户。 I changed the mounting to /var/ where jenkins can access as global process, and it solved the problem. 我将安装更改为/ var / jenkins可以作为全局进程访问,并解决了问题。

The error seems pretty obvious: " This is most likely a permission problem. " 错误似乎很明显:“ 这很可能是一个权限问题。

I assume /home/jenkins does not exists, and the user jenkins does not have write permissions in /home . 我假设/home/jenkins不存在,用户jenkins/home中没有写权限。 If you moved the Jenkins home, then you probably did it as root and just forgot to update owner permissions. 如果您将Jenkins移动到主页,那么您可能以root用户身份执行此操作并忘记更新所有者权限。

You would need to create the home, something like this: 您需要创建家庭,如下所示:

sudo service jenkins stop
# make the changes in /etc/sysconfig/jenkins
sudo mkdir --parents /home/jenkins  # or mv, in your case
sudo chown --recursive jenkins /home/jenkins
sudo service jenkins start

I ran into the same problem, so sharing my solution here: 我遇到了同样的问题,所以在这里分享我的解决方案:
The user jenkins does not have access to the folder home/ec2-user/jenkins. 用户jenkins无权访问home / ec2-user / jenkins文件夹。 You can modify the access rights of the folder home/ec2-user/home by changing or adding the user jenkins to owner 您可以通过将用户jenkins更改或添加到所有者来修改文件夹home / ec2-user / home的访问权限

sudo chown jenkins /home/ec2-user/jenkins
sudo chmod u+w /home/ec2-user/jenkins

To verify the new ownership, you can do: 要验证新的所有权,您可以执行以下操作:

ls -ld /home/ec2-user/jenkins

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM