0.环境说明

服务角色 主机名 IP 系统版本
rsync服务端 sy-gmh-sa-vm5.shaoyan.pro 192.168.168.5 CentOS Linux release 7.6.1810 (Core)
rsync客户端 sy-gmh-sa-vm3.shaoyan.pro 192.168.168.3 CentOS Linux release 7.6.1810 (Core)

2.安装rsync

  1. [root@sy-gmh-sa-vm5:/data]# yum install -y rsync xinetd

3.配置rsync服务端

  1. [root@sy-gmh-sa-vm5:/data]# egrep -v "#|^$" /etc/rsyncd.conf
  2. uid = root
  3. gid = root
  4. use chroot = no
  5. max connections = 200
  6. strict modes =yes
  7. port = 873
  8. [backup]
  9. path = /data/backup/
  10. read only = no
  11. secrets file = /etc/rsync.d/backup.aus
  12. auth users = root
  13. [root@sy-gmh-sa-vm5:/data]# vim /etc/rsync.d/backup.aus
  14. [root@sy-gmh-sa-vm5:/data]# cat /etc/rsync.d/backup.aus
  15. root:l84F2YPEhPOCtfcsdfafdok
  16. # 放行端口
  17. [root@sy-gmh-sa-vm5:~]# iptables -I INPUT -s 192.168.168.0/24 -p tcp -m tcp --dport 873 -j ACCEPT

4.配置xinetd

  1. [root@sy-gmh-sa-vm5:~]# cat /etc/xinetd.d/rsync
  2. service rsync
  3. {
  4. disable = yes
  5. flags = IPv6
  6. socket_type = stream
  7. wait = no
  8. user = root
  9. server = /usr/bin/rsync
  10. server_args = --daemon
  11. log_on_failure += USERID
  12. }
  13. [root@sy-gmh-sa-vm5:~]# systemctl enable xinetd
  14. [root@sy-gmh-sa-vm5:~]# systemctl start xinetd

5.启动服务端并开机自启

  1. [root@sy-gmh-sa-vm5:~]# systemctl enable rsyncd
  2. Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
  3. [root@sy-gmh-sa-vm5:~]# systemctl start rsyncd
  4. [root@sy-gmh-sa-vm5:~]# systemctl status rsyncd
  5. rsyncd.service - fast remote file copy program daemon
  6. Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
  7. Active: active (running) since 2019-06-27 07:03:04 CST; 8s ago
  8. Main PID: 10361 (rsync)
  9. CGroup: /system.slice/rsyncd.service
  10. └─10361 /usr/bin/rsync --daemon --no-detach
  11. 6 27 07:03:04 sy-gmh-sa-vm5.shaoyan.pro systemd[1]: Started fast remote file copy program daemon.
  12. 6 27 07:03:04 sy-gmh-sa-vm5.shaoyan.pro rsyncd[10361]: rsyncd version 3.1.2 starting, listening on port 873

6.客户端测试上传备份

  1. # 先安装rsync工具
  2. [root@sy-gmh-sa-vm3:~]# yum install rsync -y
  3. # 第3部分的 /etc/rsync.d/backup.aus 里面的密码要搞到客户端
  4. [root@sy-gmh-sa-vm3:~]# mkdir /etc/rsync.d
  5. [root@sy-gmh-sa-vm3:~]# vim /etc/rsync.d/backup.aus
  6. [root@sy-gmh-sa-vm3:~]# cat /etc/rsync.d/backup.aus
  7. l84F2YPEhPOCtfcsdfafdok
  8. [root@sy-gmh-sa-vm3:~]# chown root.root /etc/rsync.d/backup.aus
  9. [root@sy-gmh-sa-vm3:~]# chmod 600 /etc/rsync.d/backup.aus
  10. [root@sy-gmh-sa-vm3:~]#
  11. [root@sy-gmh-sa-vm3:~]# du -h data/
  12. 13M data/wal
  13. 448K data/01DDMX1BWQ3R2MSVHDBCB2YXPX/chunks
  14. 524K data/01DDMX1BWQ3R2MSVHDBCB2YXPX
  15. 292K data/01DDVRRKX1PPS0ADSQ496XXTXS/chunks
  16. 364K data/01DDVRRKX1PPS0ADSQ496XXTXS
  17. 1.4M data/01DDVRRMMQBJXMYXRH44D35K15/chunks
  18. 1.5M data/01DDVRRMMQBJXMYXRH44D35K15
  19. 15M data/
  20. [root@sy-gmh-sa-vm3:~]# /usr/bin/rsync -vzrtopg --progress --password-file=/etc/rsync.d/backup.aus /root/data root@192.168.168.5::backup
  21. sending incremental file list
  22. data/
  23. data/lock
  24. 0 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=20/22)
  25. data/01DDMX1BWQ3R2MSVHDBCB2YXPX/
  26. data/01DDMX1BWQ3R2MSVHDBCB2YXPX/index
  27. 69,483 100% 17.51MB/s 0:00:00 (xfr#2, to-chk=15/22)
  28. data/01DDMX1BWQ3R2MSVHDBCB2YXPX/meta.json
  29. 299 100% 146.00kB/s 0:00:00 (xfr#3, to-chk=14/22)
  30. data/01DDMX1BWQ3R2MSVHDBCB2YXPX/tombstones
  31. 9 100% 2.93kB/s 0:00:00 (xfr#4, to-chk=13/22)
  32. data/01DDMX1BWQ3R2MSVHDBCB2YXPX/chunks/
  33. data/01DDMX1BWQ3R2MSVHDBCB2YXPX/chunks/000001
  34. 456,586 100% 25.61MB/s 0:00:00 (xfr#5, to-chk=11/22)
  35. data/01DDVRRKX1PPS0ADSQ496XXTXS/
  36. data/01DDVRRKX1PPS0ADSQ496XXTXS/index
  37. 64,755 100% 2.94MB/s 0:00:00 (xfr#6, to-chk=10/22)
  38. data/01DDVRRKX1PPS0ADSQ496XXTXS/meta.json
  39. 299 100% 13.27kB/s 0:00:00 (xfr#7, to-chk=9/22)
  40. data/01DDVRRKX1PPS0ADSQ496XXTXS/tombstones
  41. 9 100% 0.40kB/s 0:00:00 (xfr#8, to-chk=8/22)
  42. data/01DDVRRKX1PPS0ADSQ496XXTXS/chunks/
  43. data/01DDVRRKX1PPS0ADSQ496XXTXS/chunks/000001
  44. 296,465 100% 9.12MB/s 0:00:00 (xfr#9, to-chk=6/22)
  45. data/01DDVRRMMQBJXMYXRH44D35K15/
  46. data/01DDVRRMMQBJXMYXRH44D35K15/index
  47. 95,171 100% 2.59MB/s 0:00:00 (xfr#10, to-chk=5/22)
  48. data/01DDVRRMMQBJXMYXRH44D35K15/meta.json
  49. 721 100% 19.56kB/s 0:00:00 (xfr#11, to-chk=4/22)
  50. data/01DDVRRMMQBJXMYXRH44D35K15/tombstones
  51. 9 100% 0.24kB/s 0:00:00 (xfr#12, to-chk=3/22)
  52. data/01DDVRRMMQBJXMYXRH44D35K15/chunks/
  53. data/01DDVRRMMQBJXMYXRH44D35K15/chunks/000001
  54. 1,431,167 100% 17.28MB/s 0:00:00 (xfr#13, to-chk=1/22)
  55. data/wal/
  56. data/wal/00000000
  57. 12,615,680 100% 32.43MB/s 0:00:00 (xfr#14, to-chk=0/22)
  58. sent 975,190 bytes received 346 bytes 1,951,072.00 bytes/sec
  59. total size is 15,030,653 speedup is 15.41

确认文件

  1. [root@sy-gmh-sa-vm5:~]# ls /data/backup/data/ -lh
  2. 总用量 0
  3. drwxr-xr-x 3 root root 68 6 21 08:59 01DDMX1BWQ3R2MSVHDBCB2YXPX
  4. drwxr-xr-x 3 root root 68 6 21 09:00 01DDVRRKX1PPS0ADSQ496XXTXS
  5. drwxr-xr-x 3 root root 68 6 21 09:00 01DDVRRMMQBJXMYXRH44D35K15
  6. -rw-r--r-- 1 root root 0 6 18 08:02 lock
  7. drwxr-xr-x 2 root root 22 6 18 08:02 wal
  8. [root@sy-gmh-sa-vm5:~]#

确认无误。到此,rsync备份服务器已经可以使用。客户端使用脚本,配合rsync命令就可以备份文件到服务端了。