首页 > 系统相关 >Rsync实现Linux-Windows文件同步

Rsync实现Linux-Windows文件同步

时间:2023-02-17 11:33:25浏览次数:106  
标签:Rsync Windows Linux rsync 192.168 rsyncd test 服务器 root

 

Window客户端同步到Linux服务器的文件夹: 从linux服务器的文件夹里面的内容同步到(复制,覆盖和删除等操作)windows客户端主机.

环境: CentOS 6.8 x64
Linux服务器: 192.168.0.91
window客户机: 192.168.0.92

Linux服务器:
=====================================================
1. 安装软件

    [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   # touch /etc/rsyncd.conf # vi /etc/rsyncd.conf   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. 权限配置创建账户文件   # echo root:root > /etc/rsyncd.server # chown root:root /etc/rsyncd.server # chmod 600 /etc/rsyncd.server     4. 创建文件夹:  
# mkdir /tmp/test # cd /tmp/test # touch a.txt 最后在server端将rsync以守护进程形式启动
命令为: 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 [email protected]::rsyncd /cygdrive/e/rsync 输出: C:\Documents and Settings\Administrator>rsync -vzrtopg --progress --delete --pas sword-file=/cygdrive/e/rsyncd.client [email protected]::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/ [email protected]::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 [email protected]::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客户机)

     

标签:Rsync,Windows,Linux,rsync,192.168,rsyncd,test,服务器,root
From: https://www.cnblogs.com/wuchangsoft/p/17129517.html

相关文章

  • windows字体问题
    windows字体问题(Win7)1.乱码某些Delphi写的软件字体乱码;区域/语言等全改美国/英语,然后再改成中国/中文,3个地方,以上操作完成后正常2.语言标识代码如中文0804#de......
  • lazarus combobox的下拉列表在linux时没有高亮显示选中的item
    lazarusObjectInspector和combobox的下拉列表在linux时没有高亮显示选中的item,在windows是有高亮显示的,按以下方法修改就可以,如果你有更有效的方法也请与我分享。(lazar......
  • 常用Linux命令
    #将dir1文件夹压缩成dir1.tar.gztar-zcvfdir1.tar.gzdir1/#将dir1.tar.gz解压到当前目录(若当前目录中存在目录dir1,会替换覆盖目录中的同名文件)tar-zxvfdir1.tar.gz......
  • Windows 10 无网络的情况下手动升级补丁的流程和方法:
    Windows10无网络的情况下手动升级补丁的流程和方法:从微软官网下载需要的更新补丁;将下载的更新补丁保存到本地;打开“设置”,点击“更新和安全”;点击“查看可用更新”,......
  • Windows远程桌面连接卡死解决办法
    原文地址问题描述连接远程桌面时,能进入到远程主机,但是屏幕显示黑色解决办法这个方法来自微软社区,算是技术人员给出的一个方法,大致意思就是这种问题多是因为UDP连接不畅......
  • hta--Windows运行html的桌面应用程序(HTML应用程序)
    HTA(HTMLApplication)--HTML应用程序作为前端开发,我们能熟练使用html实现各种效果,但是如果要实现一个简单的桌面应用程序那么应该怎么做呢,答案很简单,只需要把html文件后缀......
  • Linux挂载新磁盘
    目录Linux挂载新磁盘前言检查硬盘分区格式化(创建文件系统)挂载临时挂载永久挂载结语参考Linux挂载新磁盘前言当我们在使用Linux服务器或主机的时候,遇到磁盘空间不足的......
  • linux脚本禁止修改排查
    问题描述同事发过来一个脚本,说怎么修改都修改不了保存提示:warning:Changingareaedonlyfile//orOperationnotpermitted提示没权限,不过我都是root了问题......
  • WINDOWS SERVER 2016 设置使用照片查看器查看图片
    1.使用win+R快捷键快速打开运行,输入regedit打开注册表2.在注册表中找到HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsPhotoViewer\Capabilities\FileAssociations3......
  • 安装Linux操作系统,学习Linux基础(必做)
    掌握了Linux命令的学习方法https://www.cnblogs.com/bky20221301/p/16652478.html......