我选择了一个小项目,其中涉及 Ubuntu 网络服务器,以使用 Rsync 来获取内容(图像和用于导入 mySQL 数据库的 CSV 文件),该项目以 10 分钟的间隔运行以实现平稳更新。
几年来,它一直运行良好,直到最近。由于我怀疑之前的设置可能不是最好的设置和最安全的选项,因此我希望有经验的人就如何重做此操作提供一些意见。
目前,最近停止工作的系统的功能如下 -
在网络服务器上,此行在 crontab 中运行:
*/10 * * * * root /home/a/b/abc/web/rsync.script
rsync.script文件内容如下:
#! /bin/sh
# This script updates the website with the latest CSV by RSYNC and imports the CSV into the MySQL database.
# Now also imports the product images from the office server (added 26/10/2011).
# Step 1 - clearing away the previous data
rm /home/a/b/abc/web/public_html/import/csvdata/*
# Step 2 - getting the new CSV and updating the product image directory
rsync -a office.address.here::abc /home/a/b/abc/web/public_html/import
# Step 3 - chown/chmod what we have imported
chown -R 2022:sites /home/a/b/abc/web/public_html/import
chmod -R 744 /home/a/b/abc/web/public_html/import/*
chmod 0755 /home/a/b/abc/web/public_html/import/csvdata
chmod 0755 /home/a/b/abc/web/public_html/import/images
# Step 4 - run the PHP to import the new CSV into the database
cd /home/a/b/abc/web/public_html
php /home/a/b/abc/web/public_html/csv-import.php
exit 0
我已经确定损坏的部分是上面的第 2 部分。当尝试从网络服务器命令行手动运行时,会出现以下结果:
admin@webserver:/home/a/b/abc/web# sudo rsync -a office.address.here::abc/home/a/b/abc/web/public_html/import @ERROR:无法打开锁定文件 rsync 错误:在 main.c(1522) [receiver=3.0.4] 处启动客户端-服务器协议(protocol)(代码 5)时出错
网络服务器上没有/etc/rsync.conf 或/etc/rsyncd.conf 文件。考虑到本示例中的使用方法,我不确定最初是否存在或者是否需要。
在办公室机器(Debian 机器)上,我们有以下/etc/rsync.conf 文件:
max connections = 2
log file = /var/log/rsync.log
timeout = 500
[abc]
comment = ABC RSync
path = /home/abc/samba_websync/websync/
read only = no
list = yes
uid = abc
gid = abc
#auth users = mongrel
list = yes
#hosts allow = 127.0.0.0/8 192.168.0.0/24
#secrets file = /etc/rsync.secrets
令我担心的是,在整个通信过程中显然没有适当的安全措施。
我花了一天的时间阅读了许多指南和教程,说实话,如果有的话,它会变得更加令人困惑。我确信我不想修复当前的系统。我想实现一个更安全、更好的系统。新系统需要:
1 - 仅同步在办公室计算机上所做的更改,因为有大量产品图像文件,我们不希望每 10 分钟传输一次这些文件! 2 - 通信需要无缝通话,无需手动输入密码。
网络服务器和办公室机器距离较远,并且无论如何都不在 LAN 内。他们通过互联网进行交流。
我愿意采用最佳、有效的方法来实现这一目标!
提前谢谢您。 :)
我对两台机器都有 root 访问权限
最佳答案
你看过Unison吗? ?
我发现它的设置和维护相对容易,并且提供了大量有用的功能。
与 Rsync 不同,Unison 更新两个副本,但您可以使用 -nocreation
和 -noupdate
使其单向。
要将其与 crontab 一起使用,请参阅 -batch
选项。
关于linux - 从 crontab 设置自动 rsync 以通过互联网将内容从一台 Linux 机器同步到另一台 Linux 机器的 final方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25542513/