人偶3文件递归速度非常慢 [英] Puppet 3 file recurse terribly slow
问题描述
我在Amazon Linux 2012.09上使用Puppet 3,我的清单之一是设置并重新配置一些目录.任务之一只是将文件夹所有者和组递归更改为另一个用户-但是,这需要60秒钟才能完成,并且目录中几乎没有任何内容-终端中的chown myuser:myuser/var/lib/jenkins不到一秒钟.
我的问题是:在Puppet中是否有更好/更快的方法来递归更改目录所有权?
谢谢
file {'/var/lib/jenkins':
ensure => 'directory',
owner => myuser,
group => myuser,
recurse => true,
require => Package['jenkins'],
}
我也看到了这种缓慢现象,这似乎是由于Puppet单独检查了/var/lib/jenkins
下的每个文件以确保其具有正确的所有者权限,这需要时间,因为$JENKINS_HOME
下有很多文件.
我在Jenkins服务器上解决了这个问题,而是在顶级目录不属于所需用户的情况下,运行一个简单的chown -R
命令(使用exec
):
define modify_owner() {
exec { "modify_owner_${title}" :
command => "/bin/chown -R ${user}:${user} '${title}'",
onlyif => "/usr/bin/stat -c %U '${title}' | grep '^${default_user}$'"
}
}
modify_owner { ['/var/lib/jenkins', '/var/log/jenkins', '/var/cache/jenkins']: }
$user
/$user
是我要归其所有的目录的所有者/组组合.这使我的木偶时间恢复到正常水平.
(注意:我使用了stat -c %U
,但您可能需要根据操作系统来调整确切的格式设置选项.此命令打印所有者的文本名称,并在Linux上为我工作.)>
I'm using Puppet 3 on Amazon Linux 2012.09, one of my manifests sets up and reconfigs some directories. One of the tasks is just changing the folder owner and group recursivelt to another user - however, this takes over a 60 seconds to complete and there is barely anything in the directory - the chown myuser:myuser /var/lib/jenkins in the terminal take less than a second.
My question is: Is there a better/faster way to change directory ownership recursively in Puppet?
Thanks
file {'/var/lib/jenkins':
ensure => 'directory',
owner => myuser,
group => myuser,
recurse => true,
require => Package['jenkins'],
}
I see this slowness too, and it appears to be due to Puppet checking each file under /var/lib/jenkins
individually to ensure it has the correct owner permissions, which takes time since there's a lot of files under $JENKINS_HOME
.
I worked around it on our Jenkins server by instead running a simple chown -R
command (with exec
) whenever the top-level directory is not owned by the desired user:
define modify_owner() {
exec { "modify_owner_${title}" :
command => "/bin/chown -R ${user}:${user} '${title}'",
onlyif => "/usr/bin/stat -c %U '${title}' | grep '^${default_user}$'"
}
}
modify_owner { ['/var/lib/jenkins', '/var/log/jenkins', '/var/cache/jenkins']: }
$user
/$user
is the owner/group combo I want these directories to be owned by. This brought my Puppet times back down to normal levels.
(Note: I used stat -c %U
but you may need to tweak the exact formatting options depending on your OS. This command printed the owner's textual name and worked for me on Linux.)
这篇关于人偶3文件递归速度非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!