backup-server
    安装软件

    1. yum install rsync -y

    查看版本

    1. [root@ks-allinone ~]# rpm -qa rsync
    2. rsync-3.1.2-10.el7.x86_64
    3. [root@ks-allinone ~]# rsync --version
    4. rsync version 3.1.2 protocol version 31
    5. Copyright (C) 1996-2015 by Andrew Tridgell, Wayne Davison, and others.
    6. Web site: http://rsync.samba.org/
    7. Capabilities:
    8. 64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    9. socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
    10. append, ACLs, xattrs, iconv, symtimes, prealloc
    11. rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you
    12. are welcome to redistribute it under certain conditions. See the GNU
    13. General Public Licence for details.
    14. [root@ks-allinone ~]#

    添加用户和同步密钥

    1. useradd rsync -M -s /bin/nologin
    1. vim /etc/rsyncd.password
    2. [root@ks-allinone ~]# cat /etc/rsyncd.password
    3. rsync_bakup:4297f44b13955235245b2497399d7a93 ###服务端账户+密码 客户端只需密码即可
    4. [root@ks-allinone ~]#
    1. chmod 600 /etc/rsyncd.password


    修改配置文件**

    1. [root@ks-allinone ~]# cat /etc/rsyncd.conf
    2. uid = rsync
    3. gid = rsync
    4. port = 873
    5. use chroot = true
    6. max connections = 200
    7. timeout = 120
    8. pid file = /var/run/rsyncd.pid
    9. lock file = /var/run/rsyncd.lock
    10. log file = /var/log/rsyncd.log
    11. [bakup]
    12. path = /data/bakup
    13. read only = false
    14. list = false
    15. hosts allow = 192.168.11.0/24
    16. hosts deny = 0.0.0.0/32
    17. auth users = rsync_bakup
    18. secrets file = /etc/rsyncd.password
    19. [root@ks-allinone ~]#


    重启查看服务**

    1. [root@ks-allinone ~]# systemctl enable rsyncd.service
    2. [root@ks-allinone ~]#
    3. [root@ks-allinone ~]# systemctl restart rsyncd.service
    4. [root@ks-allinone ~]#
    5. [root@ks-allinone ~]# systemctl status rsyncd.service
    6. rsyncd.service - fast remote file copy program daemon
    7. Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
    8. Active: active (running) since Tue 2020-07-14 20:19:57 CST; 1min 4s ago
    9. Main PID: 29450 (rsync)
    10. Tasks: 1
    11. Memory: 192.0K
    12. CGroup: /system.slice/rsyncd.service
    13. └─29450 /usr/bin/rsync --daemon --no-detach
    14. Jul 14 20:19:57 ks-allinone systemd[1]: Started fast remote file copy program daemon.
    15. [root@ks-allinone ~]# netstat -lntup |grep rsync
    16. tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 29450/rsync
    17. tcp6 0 0 :::873 :::* LISTEN 29450/rsync
    18. [root@ks-allinone ~]# ps -ef |grep rsync
    19. root 29450 1 0 20:19 ? 00:00:00 /usr/bin/rsync --daemon --no-detach
    20. root 31248 21305 0 20:21 pts/0 00:00:00 grep --color=auto rsync
    21. [root@ks-allinone ~]#
    1. [root@ks-allinone ~]# netstat -lntup |grep rsync
    2. tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 128418/rsync
    3. tcp6 0 0 :::873 :::* LISTEN 128418/rsync
    4. [root@ks-allinone ~]#
    5. [root@ks-allinone ~]# ps -ef |grep rsync
    6. root 128418 1 0 19:53 ? 00:00:00 /usr/bin/rsync --daemon --no-detach
    7. root 130698 126463 0 19:55 pts/0 00:00:00 grep --color=auto rsync
    8. [root@ks-allinone ~]#

    设置备份目录和权限

    1. [root@ks-allinone ~]# mkdir -p /data/bakup/
    2. [root@ks-allinone ~]# chown rsync.rsync /data/bakup

    备份客服端设置

    backup-client
    安装软件

    1. yum install rsync -y
    1. systemctl enable rsyncd
    2. [root@riyimei ~]# systemctl restart rsyncd.service
    3. [root@riyimei ~]# systemctl status rsyncd.service
    4. rsyncd.service - fast remote file copy program daemon
    5. Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
    6. Active: active (running) since Tue 2020-07-14 19:59:00 CST; 11s ago
    7. Main PID: 3472 (rsync)
    8. CGroup: /system.slice/rsyncd.service
    9. └─3472 /usr/bin/rsync --daemon --no-detach
    10. Jul 14 19:59:00 riyimei systemd[1]: Started fast remote file copy program daemon.
    11. [root@riyimei ~]#

    配置文件目录

    1. [root@ks-allinone ~]# rpm -ql rsync
    2. /etc/rsyncd.conf
    3. /etc/sysconfig/rsyncd
    4. /usr/bin/rsync
    5. /usr/lib/systemd/system/rsyncd.service
    6. /usr/lib/systemd/system/rsyncd.socket
    7. /usr/lib/systemd/system/rsyncd@.service
    8. /usr/share/doc/rsync-3.1.2
    9. /usr/share/doc/rsync-3.1.2/COPYING
    10. /usr/share/doc/rsync-3.1.2/NEWS
    11. /usr/share/doc/rsync-3.1.2/OLDNEWS
    12. /usr/share/doc/rsync-3.1.2/README
    13. /usr/share/doc/rsync-3.1.2/support
    14. /usr/share/doc/rsync-3.1.2/support/Makefile
    15. /usr/share/doc/rsync-3.1.2/support/atomic-rsync
    16. /usr/share/doc/rsync-3.1.2/support/cvs2includes
    17. /usr/share/doc/rsync-3.1.2/support/deny-rsync
    18. /usr/share/doc/rsync-3.1.2/support/file-attr-restore
    19. /usr/share/doc/rsync-3.1.2/support/files-to-excludes
    20. /usr/share/doc/rsync-3.1.2/support/git-set-file-times
    21. /usr/share/doc/rsync-3.1.2/support/instant-rsyncd
    22. /usr/share/doc/rsync-3.1.2/support/logfilter
    23. /usr/share/doc/rsync-3.1.2/support/lsh
    24. /usr/share/doc/rsync-3.1.2/support/lsh.sh
    25. /usr/share/doc/rsync-3.1.2/support/mapfrom
    26. /usr/share/doc/rsync-3.1.2/support/mapto
    27. /usr/share/doc/rsync-3.1.2/support/mnt-excl
    28. /usr/share/doc/rsync-3.1.2/support/munge-symlinks
    29. /usr/share/doc/rsync-3.1.2/support/rrsync
    30. /usr/share/doc/rsync-3.1.2/support/rsync-no-vanished
    31. /usr/share/doc/rsync-3.1.2/support/rsync-slash-strip
    32. /usr/share/doc/rsync-3.1.2/support/rsyncstats
    33. /usr/share/doc/rsync-3.1.2/support/savetransfer.c
    34. /usr/share/doc/rsync-3.1.2/tech_report.tex
    35. /usr/share/man/man1/rsync.1.gz
    36. /usr/share/man/man5/rsyncd.conf.5.gz
    37. [root@ks-allinone ~]#

    配置backup模块

    1. [root@ks-allinone ~]# cat /etc/rsyncd.conf
    2. uid = rsync
    3. gid = rsync
    4. port = 873
    5. use chroot = on
    6. max connections = 200
    7. timeout = 120
    8. pid file = /var/run/rsyncd.pid
    9. lock file = /var/run/rsyncd.lock
    10. log file = /var/log/rsyncd.log
    11. [bakup]
    12. path = /data/bakup
    13. read only = false
    14. list = false
    15. hosts allow = 192.168.11.0/24
    16. hosts deny = 0.0.0.0/32
    17. auth users = rsync_bakup
    18. secrets file = /etc/rsyncd.password
    19. [root@ks-allinone ~]#

    添加服务启动用户

    1. useradd rsync -M -s /bin/nologin

    配置同步虚拟用户rsync_bakup密钥

    1. vim /etc/rsyncd.password
    2. [root@ks-allinone ~]# cat /etc/rsyncd.password
    3. 4297f44b13955235245b2497399d7a93
    4. [root@ks-allinone ~]#

    设置密钥文件权限

    1. chmod 600 /etc/rsyncd.password

    本地手动推送

    1. [root@riyimei ~]# rsync -vlzrtopg --progress --delete /data/bakup/ rsync_bakup@192.168.11.190::bakup --password-file=/etc/rsyncd.password
    2. sending incremental file list
    3. rsync: chgrp "/." (in bakup) failed: Operation not permitted (1)
    4. ./
    5. liweiming
    6. 0 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/2)
    7. rsync: chgrp "/.liweiming.4HaDr1" (in bakup) failed: Operation not permitted (1)
    8. sent 118 bytes received 200 bytes 636.00 bytes/sec
    9. total size is 0 speedup is 0.00
    10. rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1179) [sender=3.1.2]
    11. [root@riyimei ~]#

    设置定时任务-每天做一次全量备份推送到备份服务器

    1. rsync -avz --progress --delete /data/bakup/ --password-file=/etc/rsyncd.password rsync_bakup@192.168.11.80::bakup

    其中-a 代表rlptgoD,其实就是保证目录及文件的权限,修改时间,属主,组等一致
    —progress 查看进程
    —delete 客户端内容和服务的一致,当服务端有删除时,客户端也要删除

    配置自动同步
    yum install lsyncd.x86_64 -y

    ssh 免密钥配置

    1. [root@riyimei ~]# rpm -ql lsyncd
    2. /etc/logrotate.d/lsyncd
    3. /etc/lsyncd.conf
    4. /etc/sysconfig/lsyncd
    5. /usr/bin/lsyncd
    6. /usr/lib/systemd/system/lsyncd.service
    7. /usr/share/doc/lsyncd-2.2.2
    8. /usr/share/doc/lsyncd-2.2.2/ChangeLog
    9. /usr/share/doc/lsyncd-2.2.2/examples
    10. /usr/share/doc/lsyncd-2.2.2/examples/lalarm.lua
    11. /usr/share/doc/lsyncd-2.2.2/examples/lbash.lua
    12. /usr/share/doc/lsyncd-2.2.2/examples/lecho.lua
    13. /usr/share/doc/lsyncd-2.2.2/examples/lftp.lua
    14. /usr/share/doc/lsyncd-2.2.2/examples/lgforce.lua
    15. /usr/share/doc/lsyncd-2.2.2/examples/limagemagic.lua
    16. /usr/share/doc/lsyncd-2.2.2/examples/lpostcmd.lua
    17. /usr/share/doc/lsyncd-2.2.2/examples/lrsync.lua
    18. /usr/share/doc/lsyncd-2.2.2/examples/lrsyncssh.lua
    19. /usr/share/doc/lsyncd-2.2.2/examples/lsayirc.lua
    20. /usr/share/licenses/lsyncd-2.2.2
    21. /usr/share/licenses/lsyncd-2.2.2/COPYING
    22. /usr/share/man/man1/lsyncd.1.gz
    23. /var/log/lsyncd
    24. [root@riyimei ~]#
    1. [root@riyimei ~]# cat /etc/lsyncd.conf
    2. ----
    3. -- User configuration file for lsyncd.
    4. --
    5. -- Simple example for default rsync, but executing moves through on the target.
    6. --
    7. -- For more examples, see /usr/share/doc/lsyncd*/examples/
    8. --
    9. sync{default.rsyncssh, source="/data/bakup", host="192.168.11.80", targetdir="/data/bakup/"}
    10. [root@riyimei ~]#