rsync同步服务的总结(Linux与windows双向)

写在前面

  • 什么是rsync?
    rsync 是一个快速增量文件传输工具,它可以用于在同一主机备份内部的备分,我们还可以把它作为不同主机网络备份工具之用。本文主要讲述的是如何自架rsync服务器,以实现文件传输、备份和镜像。相对tar和wget来说,rsync 也有其自身的优点,比如速度快、安全、高效。
  • rsync的安装
    目前Linux(Ubuntu、Centos等)以及Mac都是自带rysnc的,普通权限模式下输入rsync就可以看到
Linux作为服务端,Windows作为客户端
linux端
  • 基本配置文件
    rsync.conf
    Notice:需要在/etc/rsyncd/目录下创建,其余配置文件同。此文件为核心配置文件,必须要有的。
    下面具体配置,有释义。
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help

#This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid #告诉进程写到 /var/run/rsyncd.pid 文件中
lock file = /var/run/rsyncd.lock
port = 8873   #默认端口873,可以自己配
#address = 10.246.52.176   #指定服务器地址
#uid = nobody
#gid = nobody   
#uid = hzwanghao5  
#gid = hzwanghao5  
use chroot =no
max connections = 200   #客户端最多连接数
#This will give you a separate log file
log file = /var/log/rsync.log   #传输文件的日志

[server]
path = /home/hzwanghao5/outtest    #指定文件目录所在位置,这是必须指定的
charset = GBK
list = no  #list 意思是把rsync 服务器上提供同步数据的目录在服务器上模块是否显示列出来。默认是yes 。如果你不想列出来,就no 
ignore errors
uid = hzwanghao5    #服务器端传输文件时,要发哪个用户和用户组来执行,默认是nobody
gid = hzwanghao5
auth users = hzwanghao5
comment = hzwanghao5 home outtest
read only = yes  #read only 是只读选择,也就是说,不让客户端上传文件到服务器上
syslog facility = local5
secrets file = /etc/rsyncd/rsyncd.secrets
  • 关于防火墙
    一般不需要开,如果需要开通输入以下命令1.iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 8873 -j ACCEPT
    查看防火墙是否打开对应端口iptables -L
  • 启动服务器
    /usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf --daemon让rsync以服务器模式运行
    相关的命令:
netstat -ntpl  #查看端口
ps -ef|grep rsync  #查看进程
kill -s 9 进程号    #杀掉进程
Windows端
  • 下载客户端
    官方免费下载版本:cwRsync
    也可以百度网盘下载:cwRsync v4.1.0
  • 安装客户端
  • 打开Linux上的8873端口
  • 建立.bat文件创立脚本
D:\rsync\cwRsync_5.5.0_x86_Free\cwRsync_5.5.0_x86_Free\bin\rsync.exe -vzrtopgu --progress --port=8873 --delete [email protected]::server /cygdrive/D/test --password-file=/cygdrive/D/rsync/rsync.secrets

Notice:主要端口的指令--port=8873必须要加上让客户端能够识别,其中/cygdrive/D/test指备份到本地的目录,后面的--password-file可选,要注意的是secrets文件要与linux服务器保持一致
关于rsync指令可参考如下链接:rsync指令,大部分下载指令可用上面提供的

常见问题

网上搜就好了,基本上就是重启服务器,检查指令,其他遇到具体的就再对应的搜索就好

Windows作为服务端,Linux作为客户端
Windows端
  • 下载server
    提供百度网盘下载:cwRsyncServer v4.1.0
  • 安装
    下载解压之后要注意的是,创立账号、密码非常关键,要记住。安装的默认位置:C:\Program Files\ICW
  • 配置文件rsyncd.conf
port = 8873
list = no
hosts allow = *
lock file = rsyncd.lock


[rsyncdata]
path = /cygdrive/D/rsync/data
read only = no
#uid = hzwanghao5
#gid = hzwanghao5
use chroot = no
max connection = 200
list = false

可以看到跟linux作为服务端时基本一致,read only = no要注意,这里是从windows同步到linux服务器上,path路径是将要上传的windows路径

  • cmd下启动服务器
    进入包含rsync.exe的目录下,使用如下指令:rsync --daemon --config="D:\Program Files (x86)\ICW\rsyncd.conf" --log-file="D:\Program Files (x86)\ICW\test1.txt"
    Notice:此时可能会遇到重启服务器的情况,cmd下输入如下指令:tskill rsync
  • Linux服务端
    rsync -vzrtopg --no-super --progress --exclude '.svn' --port=8873 [email protected]::rsyncdata outtest
    指令意义参加上文链接,最后的outtest是linux要接受的目录

至此,两端的数据同步全都配完了,rsync还有很多东西,有需要的可自行了解

你可能感兴趣的:(rsync同步服务的总结(Linux与windows双向))