Rsync实现Linux-Windows文件同步 http://blog.sina.com.cn/s/blog_6e68be1f0102uxhr.html
Linux系统与windows系统文件同步 http://www.ilanni.com/?p=8646
Linux系统之间同步参考: http://www.mekau.com/index.php/tool/os/pandy_1184.html
Window客户端同步到Linux服务器的文件夹: 从linux服务器的文件夹里面的内容同步到(复制,覆盖和删除等操作)windows客户端主机.
环境: CentOS 6.8 x64
Linux服务器: 192.168.0.91
window客户机: 192.168.0.92
Linux服务器:
=====================================================
1. 安装软件
1 2 3 4 5 |
[root@localhost ~]# yum -y install rsync [root@localhost ~]# cd /etc/sysconfig [root@localhost ~]# vi iptables #增加: -A INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT [root@localhost ~]# service iptables restart |
2. 配置rsync
1 2 |
# touch /etc/rsyncd.conf # vi /etc/rsyncd.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
secrets file = /etc/rsyncd.server read only = yes list = yes uid = nobody gid = nobody hosts allow = 192.168.0.91 use chroot = no max connections = 100 transfer logging = yes log format = %t %a %m %f %b log file = /var/log/rsyncd.log pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock [rsyncd] comment = my rsync server path = /tmp/test auth users = root secrets file = /etc/rsyncd.server |
3. 权限配置创建账户文件
1 2 3 |
# echo root:root > /etc/rsyncd.server # chown root:root /etc/rsyncd.server # chmod 600 /etc/rsyncd.server |
4. 创建文件夹:
1 2 3 |
# mkdir /tmp/test # cd /tmp/test # touch a.txt |
最后在server端将rsync以守护进程形式启动
命令为:
1 |
rsync --daemon --config /etc/rsyncd.conf |
rsync启动的端口为 873端口
最好用ntsysv或者chkconfig将rsync设置为开机自动启动
window客户机:
=====================================================
1, 安装cwRsync工具,cwRsync_4.1.0_Installer.exe; 拷贝服务端cwRsyncServer_4.1.0_ICW(版本跟上面一致,已经安装后复制备份的文件夹了)的chown.exe 到安装目录的 bin目录中去。
2. 建立认证的密码文件在E:\rsyncd.client , 内容是上面的设置的密码:root. 然后执行:
1 2 |
# chmod -c 600 /cygdrive/e/rsyncd.client # chown administrator /cygdrive/e/rsyncd.client |
3. 建立要备份到本地的目录如: E:\rsync
4.环境变量path追加: C:\Program Files\cwRsync\bin在最前面
测试:
在window客户机执行:
1 2 3 4 5 6 7 8 9 10 11 12 |
rsync -vzrtopg --progress --delete --password-file=/cygdrive/e/rsyncd.client root@192.168.0.55::rsyncd /cygdrive/e/rsync 输出: C:\Documents and Settings\Administrator>rsync -vzrtopg --progress --delete --pas sword-file=/cygdrive/e/rsyncd.client root@192.168.0.55::rsyncd /cygdrive/e/rsync receiving incremental file list ./ a.txt 0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/2) sent 78 bytes received 147 bytes 450.00 bytes/sec total size is 0 speedup is 0.00 |
Linux客户端同步到Window服务器的文件夹:
环境: CentOS 6.8 x64
Linux客户机: 192.168.0.91
window服务器: 192.168.0.92
window服务器
=======================================
1. 安装:
要把Linux系统文件同步奥windows系统,需要我们在windows系统上配置rsync服务端,即安装cwRsyncserver。cwRsyncserver目前网络上的免费版本为4.1.0,
安装的时候设定服务器账号和密码:rsync/rsync
注意: 服务器已经包含了客户端的软件了.
2. 配置:
rsyncserver安装完毕后,我们现在来配置rsyncserver。windows下rsyncserver的配置和Linux下rsync服务配置没有多大的区别。
先创建服务器密码文件:E:\rsyncd.server, 内容是一行:
1 |
rsync:rsync |
修改服务器配置文件C:\Program Files\ICW\rsyncd.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
use chroot = false strict modes = false hosts allow = * log file = rsyncd.log #uid = nobody #gid = nobody gid = 0 uid = 0 # Module definitions # Remember cygwin naming conventions : c:\work becomes /cygwin/c/work # #[test] #path = /cygdrive/c/work #read only = false #transfer logging = yes [rsyncd] path = /cygdrive/e/rsync/ ignore errors read only = no list = no hosts allow = 192.168.0.55/255.255.255.0 auth users = rsync secrets file = /cygdrive/e/rsyncd.server |
3. 设定环境变量, 追加到path最前面:C:\Program Files\ICW\bin; , 如果安装客户端, 注意查看C:\Program Files\cwRsync\bin下面是否存在chown.exe, 存在就删除.
4. 创建文件夹E:\rsync, 修改权限,保证前面安装服务器的时候创建的账户对这个文件夹拥有所有控制权. 同时创建一个a.txt的空文件
5. 修改密码文件权限:
1 2 |
> E: > chmod 600 rsyncd.server |
6. 到管理工具的服务器里面, 启动RsyncServer服务器.
Linux客户机:
1. 安装rsync
1 |
yum -y install rsync |
2. 配置, 创建linux客户端密码文件
[root@localhost ~]# echo rsync > /etc/rsyncd.client #无法使用这个密码文件,为什么?
测试:
进入linux, 测试连接
1 2 3 4 5 6 |
[root@localhost ~]# yum -y install xinetd telnet [root@localhost ~]# telnet 192.168.0.91 873 Trying 192.168.0.91... Connected to 192.168.0.91. Escape character is '^]'. @RSYNCD: 30.0 |
测试:
在linux服务器测试: 双向同步文件
解决不适用密码的方式:
1 2 3 4 5 6 7 8 9 10 |
[root@localhost test]# export RSYNC_PASSWORD="rsync" [root@localhost test]# cd /tmp/test [root@localhost test]# touch c.txt [root@localhost ~]# rsync -avz /tmp/test/ rsync@192.168.0.91::rsyncd Password: # 然后输入密码, 如果使用了export RSYNC_PASSWORD="rsync", 这里可能不需要输入密码 sending incremental file list a.txt sent 72 bytes received 33 bytes 16.15 bytes/sec total size is 0 speedup is 0.00 |
表示传输完成, 传输方向是: 从linux的/tmp/test/复制文件等操作到远程192.168.0.91服务器(window服务器);
1 2 3 4 5 6 7 8 9 |
[root@localhost test]# export RSYNC_PASSWORD="rsync" [root@localhost test]# rsync -avz rsync@192.168.0.91::rsyncd /tmp/test/ Password: # 然后输入密码, 如果使用了export RSYNC_PASSWORD="rsync", 这里可能不需要输入密码 receiving incremental file list ./ c.txt sent 79 bytes received 179 bytes 14.74 bytes/sec total size is 0 speedup is 0.00 |
表示传输完成, 传输方向是: 从远程服务器配置的rsyncd块的位置,复制文件等操作到本地/tmp/test/(Linux客户机)