简体   繁体   English

使用lsync同步apache webroot文件-遇到权限问题

[英]Using lsync to sync apache webroot files - running into permission issues

I'm distributing load between two web servers, which means all of the Apache settings and vhosts are pretty much identical, and I wanted to make sure they stay that way by using LSync (or if there's another solution that helps with the problem I'm having, let me know) 我正在两台Web服务器之间分配负载,这意味着所有Apache设置和虚拟主机都几乎相同,并且我想通过使用LSync来确保它们保持这种状态(或者是否有另一种解决方案可以帮助解决我的问题,我有,让我知道)

So obviously Apache runs as the apache user, and we cant enable root SSH logins, so I created an lsync user that can SSH between the two servers using RSA keys. 因此,显然Apache以apache用户身份运行,并且我们无法启用root SSH登录,因此我创建了一个lsync用户,该用户可以使用RSA密钥在两台服务器之间进行SSH。

And now I'm running into some permissions errors, which is kinda what I expected to happen really. 现在我遇到了一些权限错误,这真是我期望发生的事情。 What I'm trying now is I added the lsync user to the apache group, and the apache user to the lsync group... and that seems to work ok, as long as the files are chowned 7 for both the user and the group... 我现在要尝试的是将lsync用户添加到apache组中,并将apache用户添加到lsync组中……这似乎可以正常工作,只要用户该组的文件都被更改为7 ...

I thought about setting a cron job to chown apache.apache every so often, and maybe even chmod +rwx for the group and user, but I'm sure that would cause some other issues. 我曾考虑过设置一个cron作业来频繁地对apache.apache进行chown,甚至可能为组和用户使用chmod + rwx,但是我敢肯定这会引起其他问题。

I thought about having lsync run as the apache user, but it looks like the apache home directory needs to actually be owned by root.root .. so that would cause issues with the apache user trying to ssh in and read from the .ssh directory. 我考虑过让lsync以apache用户身份运行,但是看来apache主目录实际上需要归root.root ..所有,因此这会导致apache用户尝试ssh并从.ssh目录中读取时出现问题。

I couldn't find much about this when I looked on Google... Most people just used the root user for lsync, which is out of the question. 当我在Google上浏览时,发现的内容不多。大多数人只是将root用户用于lsync,这是不可能的。

So if anyone has a fix, that would be great! 因此,如果有人有修复程序,那就太好了! thanks 谢谢

PS I know that I can allow the lsync user to execute specific commands via sudo, if I properly configure the sudoers configuration... is there a way to have it sudo chown apache.apache /var/www && sudo chmod -R u+rwx /var/www or something? PS我知道我可以允许lsync用户通过sudo执行特定命令,如果我正确配置了sudoers配置...是否有办法让它sudo chown apache.apache /var/www && sudo chmod -R u+rwx /var/www还是什么?

You might consider having the apache user run an rsync daemon. 您可以考虑让apache用户运行rsync守护程序。 It's little used since tunnelling rsync through ssh is more convenient and more secure, but it might help you side-step this problem. 它很少使用,因为通过ssh隧道传输rsync更方便更安全,但是它可以帮助您避免此问题。

You need to set up a configuration file, and then simply launch it with rsync --daemon using whatever init system your distro has. 您需要设置一个配置文件,然后使用发行版具有的任何初始化系统,通过rsync --daemon简单地启动它。

You can then configure your lsynd with target = "rsync://server/path" . 然后,可以使用target = "rsync://server/path"配置lsynd

If the connection between the servers is local and the network is trusted then you're done, otherwise you should configure the rsync daemon to listen only on 127.0.0.1, and then use an ssh -L port mapping to route the traffic through an encrypted tunnel (the owner of the tunnel is not important). 如果服务器之间的连接是本地的并且网络是可信任的,则说明您已经完成,否则,应将rsync守护程序配置为仅在127.0.0.1上进行侦听,然后使用ssh -L端口映射通过加密的方式路由通信隧道(隧道的所有者并不重要)。

rsync has an option for forcing the permissions of the files it creates on the destination: --chmod=<blah> . rsync有一个选项,用于强制它在目标位置创建的文件的权限:-- --chmod=<blah> lsyncd does not have direct support for this, but can pass-through rsync flags. lsyncd没有直接支持,但是可以传递rsync标志。

Try adding this to your lsyncd configuration: 尝试将其添加到您的lsyncd配置中:

_extra = {"--chmod=Dug+rwx,Fug+rw"}

That should ensure that directories, D , have read/write/execute permissions for owner and group, and files, F , have read/write permissions for owner and group. 那应该确保目录D对所有者和组具有读/写/执行权限,文件F对所有者和组具有读/写权限。 Any other permissions should be set as they are on the source server. 应该设置其他任何权限,就像在源服务器上一样。

If you need the files to be owned by the apache user then you could set up a chown cron job, as you suggest, but you might find that a constantly running script that reads the output from inotifywatch will be more responsive (and mostly idle). 如果您需要将文件归apache用户所有,则可以按照您的建议设置一个choron cron作业,但是您可能会发现一个不断运行的脚本读取了inotifywatch的输出, inotifywatch响应inotifywatch更快(并且大多数情况下是空闲的) 。

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

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