频道栏目
首页 > 资讯 > 其他 > 正文

linux系统中Rsync文件同步方案-丿十年-51CTO博客

20-05-14        来源:[db:作者]  
收藏   我要投稿
linux服务器下Rsync文件同步配置
Rsync(remote synchronize) 远程数据同步工具,可以使用“Rsync算法”同步本地和远程主机之间的文件、Rsync的好处是只同步两个文件不同的部分,相同的部分不在传递、类似于增量备份,这使的在服务器传递备份文件或者同步文件。 crontab配合rsync 使用可达到定时备份同步任务。

Rsync部署环境1、服务器准备| Host | IP | ----------|| Server | 192.168.60.110 | ----------|| client | 192.168.60.80 | ----------|

2、Server
        2.1、ubuntu ?16.04默认已安装rsync,直接修改它的配置文件即可。
        sudo vim /etc/default/rsync
        RSYNC_ENABLE=true   #false改true
3、修改配置文件3.1、 rsync佩在文件默认在/usr/share/doc/rsync/examples/下,需要手动将配置文件拷贝到/etc目录下,sudo cp /usr/share/doc/rsync/examples/rsyncd.conf /etc 3.2、修改conf配置文件。sudo vim /etc/rsyncd.conf
            #motd file=/etc/motd
            log file=/var/log/rsyncd
            #for pid file, do not use /var/run/rsync.pid if
            #you are going to run rsync out of the init.d script.
            #The init.d script does its own pid file handling,
            #so omit the "pid file" line completely in that case.
            pid file=/var/run/rsyncd.pid
            syslog facility=daemon
            #socket options=
            #MODULE OPTIONS
            [ftp]
    comment = public archive
    path = /home/zy/ftp
    use chroot = no
            #max connections=10
    lock file = /var/lock/rsyncd
            #the default for read only is yes...
    read only = yes
    list = yes
    uid = nobody
    gid = nogroup
            #exclude = 
            #exclude from = 
            #include =
            #include from =
    auth users = liu_rsync
    secrets file = /etc/rsyncd.secrets
    strict modes = yes
    hosts allow = 192.168.60.110
            #hosts deny =
    ignore errors = no
    ignore nonreadable = yes
    transfer logging = no
            #log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.
    timeout = 600
    refuse options = checksum dry-run
    dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz

4、创建一个密码文件vim /etc/rsyncd.pwd内容为:rsync:123sudo chmod 0600 /etc/rsyncd.pwd5、启动rsyncsudo /etc/init.d/rsync start如果启动成功,那么server端酒配置成功了。

Client

1、客户端不需要进行特殊的配置,直接同步即可rsync -vzrtopg --progress rsync@192.168.60.80::my_rsync_bk . 1.1、此时rsync只能将Server端现有的数据同步下来,如果Server新添加数据却不能同步下来,这有点难受。1.2、所以需要创建一个密码文件(和server端做免密钥也可以的)sudo vim /etc/rsync.pwd输入123 #密码要一致sudo chmod 0600 /etc/rsync.pwdsudo chown 普通用户:普通用户组 /etc/rsync.pwd1.3、自动执行:命令行终端输入:crontab -e 添加以下内容,/1 rsync -a --password-file=/etc/rsync.pwd rsync@192.168.60.80::my_rsync_bk /data//1 为一分钟同步一次 只要Server端添加了新文件、1分钟内就会自动同步到客户端。1.5、删除文件需要同步 需要添加 --delete 参数 /1 * rsync -a --password-file=/etc/rsync.pwd --delete rsync@192.168.60.80::my_rsync_bk /data/rsync同步配置完成


案例:

一、从本地同步文件到远程服务器rsync -avz /home/ftp root@192.168.6.8:home/ftp 二、将远程服务器的文件同步到本地crontab -ersync -avz root@192.168.6.8:home/ftp /home/ftp


我的同步参数:

远程PC同步到本地PC.每十分钟执行一次

rsync-a --delete root@192.168.6.8:/home/ftp /home/s*2/4/zy sleep 10; rsync-a --delete root@192.168.6.8:/home/ftp /home/s*2/4/zy sleep 20; rsync-a --delete root@192.168.6.8:/home/ftp home/s*2/4/zy sleep 40; rsync-a --delete root@192.168.6.8:/home/ftp home/s*2/4/zy sleep 50; rsync-a --delete root@192.168.6.8:/home/ftp /home/s*2/4/zy
相关TAG标签
上一篇:Linux学习笔记六-在成长1的博客-51CTO博客
下一篇:ansible快速掌握-zxhk的博客-51CTO博客
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站