掌柜
rsync备份服务器安装和配置
09/26
本文最后更新于2023年07月07日,已超过515天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!
0.环境说明
rsync是什么:
rsync是linux系统下的数据镜像备份工具。使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH、rsync主机同步。rsync是典型的CS服务架构,备份机上配置rsync服务端,其他机器作为rsync客户端,向服务端推送备份数据,达到备份目的。
下文,是徒手搭建rsync
备份服务器过程。
服务角色 | IP | 系统版本 |
---|---|---|
rsync服务端 | 192.168.168.5 | CentOS 7.6.1810 (Core) |
rsync客户端 | 192.168.168.3 | CentOS 7.6.1810 (Core) |
2.安装rsync
[root@sy-gmh-sa-vm5:/data]# yum install -y rsync xinetd
3.配置rsync服务端
[root@sy-gmh-sa-vm5:/data]# egrep -v "#|^$" /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 200
strict modes =yes
port = 873
[backup]
path = /data/backup/
read only = no
secrets file = /etc/rsync.d/backup.aus
auth users = root
[root@sy-gmh-sa-vm5:/data]# vim /etc/rsync.d/backup.aus
[root@sy-gmh-sa-vm5:/data]# chmod 600 /etc/rsync.d/backup.aus
[root@sy-gmh-sa-vm5:/data]# cat /etc/rsync.d/backup.aus
root:l84F2YPEhPOCtfcsdfafdok
# 放行端口
[root@sy-gmh-sa-vm5:~]# iptables -I INPUT -s 192.168.168.0/24 -p tcp -m tcp --dport 873 -j ACCEPT
[root@sy-gmh-sa-vm5:~]# service iptables save
4.配置xinetd
[root@sy-gmh-sa-vm5:~]# cat /etc/xinetd.d/rsync
service rsync
{
disable = yes
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
[root@sy-gmh-sa-vm5:~]# systemctl enable xinetd
[root@sy-gmh-sa-vm5:~]# systemctl start xinetd
5.启动服务端并开机自启
[root@sy-gmh-sa-vm5:~]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
[root@sy-gmh-sa-vm5:~]# systemctl start rsyncd
[root@sy-gmh-sa-vm5:~]# systemctl status rsyncd
● rsyncd.service - fast remote file copy program daemon
Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
Active: active (running) since 四 2019-06-27 07:03:04 CST; 8s ago
Main PID: 10361 (rsync)
CGroup: /system.slice/rsyncd.service
└─10361 /usr/bin/rsync --daemon --no-detach
6月 27 07:03:04 sy-gmh-sa-vm5.shaoyan.pro systemd[1]: Started fast remote file copy program daemon.
6月 27 07:03:04 sy-gmh-sa-vm5.shaoyan.pro rsyncd[10361]: rsyncd version 3.1.2 starting, listening on port 873
6.客户端测试上传备份
# 先安装rsync工具
[root@sy-gmh-sa-vm3:~]# yum install rsync -y
# 第3部分的 /etc/rsync.d/backup.aus 里面的密码要搞到客户端
[root@sy-gmh-sa-vm3:~]# mkdir /etc/rsync.d
[root@sy-gmh-sa-vm3:~]# vim /etc/rsync.d/backup.aus
[root@sy-gmh-sa-vm3:~]# cat /etc/rsync.d/backup.aus
l84F2YPEhPOCtfcsdfafdok
[root@sy-gmh-sa-vm3:~]# chown root.root /etc/rsync.d/backup.aus
[root@sy-gmh-sa-vm3:~]# chmod 600 /etc/rsync.d/backup.aus
[root@sy-gmh-sa-vm3:~]#
[root@sy-gmh-sa-vm3:~]# du -h data/
13M data/wal
448K data/01DDMX1BWQ3R2MSVHDBCB2YXPX/chunks
524K data/01DDMX1BWQ3R2MSVHDBCB2YXPX
292K data/01DDVRRKX1PPS0ADSQ496XXTXS/chunks
364K data/01DDVRRKX1PPS0ADSQ496XXTXS
1.4M data/01DDVRRMMQBJXMYXRH44D35K15/chunks
1.5M data/01DDVRRMMQBJXMYXRH44D35K15
15M data/
[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
sending incremental file list
data/
data/lock
0 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=20/22)
data/01DDMX1BWQ3R2MSVHDBCB2YXPX/
data/01DDMX1BWQ3R2MSVHDBCB2YXPX/index
69,483 100% 17.51MB/s 0:00:00 (xfr#2, to-chk=15/22)
data/01DDMX1BWQ3R2MSVHDBCB2YXPX/meta.json
299 100% 146.00kB/s 0:00:00 (xfr#3, to-chk=14/22)
data/01DDMX1BWQ3R2MSVHDBCB2YXPX/tombstones
9 100% 2.93kB/s 0:00:00 (xfr#4, to-chk=13/22)
data/01DDMX1BWQ3R2MSVHDBCB2YXPX/chunks/
data/01DDMX1BWQ3R2MSVHDBCB2YXPX/chunks/000001
456,586 100% 25.61MB/s 0:00:00 (xfr#5, to-chk=11/22)
data/01DDVRRKX1PPS0ADSQ496XXTXS/
data/01DDVRRKX1PPS0ADSQ496XXTXS/index
64,755 100% 2.94MB/s 0:00:00 (xfr#6, to-chk=10/22)
data/01DDVRRKX1PPS0ADSQ496XXTXS/meta.json
299 100% 13.27kB/s 0:00:00 (xfr#7, to-chk=9/22)
data/01DDVRRKX1PPS0ADSQ496XXTXS/tombstones
9 100% 0.40kB/s 0:00:00 (xfr#8, to-chk=8/22)
data/01DDVRRKX1PPS0ADSQ496XXTXS/chunks/
data/01DDVRRKX1PPS0ADSQ496XXTXS/chunks/000001
296,465 100% 9.12MB/s 0:00:00 (xfr#9, to-chk=6/22)
data/01DDVRRMMQBJXMYXRH44D35K15/
data/01DDVRRMMQBJXMYXRH44D35K15/index
95,171 100% 2.59MB/s 0:00:00 (xfr#10, to-chk=5/22)
data/01DDVRRMMQBJXMYXRH44D35K15/meta.json
721 100% 19.56kB/s 0:00:00 (xfr#11, to-chk=4/22)
data/01DDVRRMMQBJXMYXRH44D35K15/tombstones
9 100% 0.24kB/s 0:00:00 (xfr#12, to-chk=3/22)
data/01DDVRRMMQBJXMYXRH44D35K15/chunks/
data/01DDVRRMMQBJXMYXRH44D35K15/chunks/000001
1,431,167 100% 17.28MB/s 0:00:00 (xfr#13, to-chk=1/22)
data/wal/
data/wal/00000000
12,615,680 100% 32.43MB/s 0:00:00 (xfr#14, to-chk=0/22)
sent 975,190 bytes received 346 bytes 1,951,072.00 bytes/sec
total size is 15,030,653 speedup is 15.41
确认文件
[root@sy-gmh-sa-vm5:~]# ls /data/backup/data/ -lh
总用量 0
drwxr-xr-x 3 root root 68 6月 21 08:59 01DDMX1BWQ3R2MSVHDBCB2YXPX
drwxr-xr-x 3 root root 68 6月 21 09:00 01DDVRRKX1PPS0ADSQ496XXTXS
drwxr-xr-x 3 root root 68 6月 21 09:00 01DDVRRMMQBJXMYXRH44D35K15
-rw-r--r-- 1 root root 0 6月 18 08:02 lock
drwxr-xr-x 2 root root 22 6月 18 08:02 wal
[root@sy-gmh-sa-vm5:~]#
确认无误。到此,rsync备份服务器已经可以使用。客户端使用脚本,配合rsync命令就可以备份文件到服务端了。