backup-server
安装软件
yum install rsync -y
查看版本
[root@ks-allinone ~]# rpm -qa rsync
rsync-3.1.2-10.el7.x86_64
[root@ks-allinone ~]# rsync --version
rsync version 3.1.2 protocol version 31
Copyright (C) 1996-2015 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
append, ACLs, xattrs, iconv, symtimes, prealloc
rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you
are welcome to redistribute it under certain conditions. See the GNU
General Public Licence for details.
[root@ks-allinone ~]#
添加用户和同步密钥
useradd rsync -M -s /bin/nologin
vim /etc/rsyncd.password
[root@ks-allinone ~]# cat /etc/rsyncd.password
rsync_bakup:4297f44b13955235245b2497399d7a93 ###服务端账户+密码 客户端只需密码即可
[root@ks-allinone ~]#
chmod 600 /etc/rsyncd.password
修改配置文件**
[root@ks-allinone ~]# cat /etc/rsyncd.conf
uid = rsync
gid = rsync
port = 873
use chroot = true
max connections = 200
timeout = 120
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[bakup]
path = /data/bakup
read only = false
list = false
hosts allow = 192.168.11.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_bakup
secrets file = /etc/rsyncd.password
[root@ks-allinone ~]#
重启查看服务**
[root@ks-allinone ~]# systemctl enable rsyncd.service
[root@ks-allinone ~]#
[root@ks-allinone ~]# systemctl restart rsyncd.service
[root@ks-allinone ~]#
[root@ks-allinone ~]# systemctl status rsyncd.service
● rsyncd.service - fast remote file copy program daemon
Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2020-07-14 20:19:57 CST; 1min 4s ago
Main PID: 29450 (rsync)
Tasks: 1
Memory: 192.0K
CGroup: /system.slice/rsyncd.service
└─29450 /usr/bin/rsync --daemon --no-detach
Jul 14 20:19:57 ks-allinone systemd[1]: Started fast remote file copy program daemon.
[root@ks-allinone ~]# netstat -lntup |grep rsync
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 29450/rsync
tcp6 0 0 :::873 :::* LISTEN 29450/rsync
[root@ks-allinone ~]# ps -ef |grep rsync
root 29450 1 0 20:19 ? 00:00:00 /usr/bin/rsync --daemon --no-detach
root 31248 21305 0 20:21 pts/0 00:00:00 grep --color=auto rsync
[root@ks-allinone ~]#
[root@ks-allinone ~]# netstat -lntup |grep rsync
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 128418/rsync
tcp6 0 0 :::873 :::* LISTEN 128418/rsync
[root@ks-allinone ~]#
[root@ks-allinone ~]# ps -ef |grep rsync
root 128418 1 0 19:53 ? 00:00:00 /usr/bin/rsync --daemon --no-detach
root 130698 126463 0 19:55 pts/0 00:00:00 grep --color=auto rsync
[root@ks-allinone ~]#
设置备份目录和权限
[root@ks-allinone ~]# mkdir -p /data/bakup/
[root@ks-allinone ~]# chown rsync.rsync /data/bakup
备份客服端设置
backup-client
安装软件
yum install rsync -y
systemctl enable rsyncd
[root@riyimei ~]# systemctl restart rsyncd.service
[root@riyimei ~]# systemctl status rsyncd.service
● rsyncd.service - fast remote file copy program daemon
Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2020-07-14 19:59:00 CST; 11s ago
Main PID: 3472 (rsync)
CGroup: /system.slice/rsyncd.service
└─3472 /usr/bin/rsync --daemon --no-detach
Jul 14 19:59:00 riyimei systemd[1]: Started fast remote file copy program daemon.
[root@riyimei ~]#
配置文件目录
[root@ks-allinone ~]# rpm -ql rsync
/etc/rsyncd.conf
/etc/sysconfig/rsyncd
/usr/bin/rsync
/usr/lib/systemd/system/rsyncd.service
/usr/lib/systemd/system/rsyncd.socket
/usr/lib/systemd/system/rsyncd@.service
/usr/share/doc/rsync-3.1.2
/usr/share/doc/rsync-3.1.2/COPYING
/usr/share/doc/rsync-3.1.2/NEWS
/usr/share/doc/rsync-3.1.2/OLDNEWS
/usr/share/doc/rsync-3.1.2/README
/usr/share/doc/rsync-3.1.2/support
/usr/share/doc/rsync-3.1.2/support/Makefile
/usr/share/doc/rsync-3.1.2/support/atomic-rsync
/usr/share/doc/rsync-3.1.2/support/cvs2includes
/usr/share/doc/rsync-3.1.2/support/deny-rsync
/usr/share/doc/rsync-3.1.2/support/file-attr-restore
/usr/share/doc/rsync-3.1.2/support/files-to-excludes
/usr/share/doc/rsync-3.1.2/support/git-set-file-times
/usr/share/doc/rsync-3.1.2/support/instant-rsyncd
/usr/share/doc/rsync-3.1.2/support/logfilter
/usr/share/doc/rsync-3.1.2/support/lsh
/usr/share/doc/rsync-3.1.2/support/lsh.sh
/usr/share/doc/rsync-3.1.2/support/mapfrom
/usr/share/doc/rsync-3.1.2/support/mapto
/usr/share/doc/rsync-3.1.2/support/mnt-excl
/usr/share/doc/rsync-3.1.2/support/munge-symlinks
/usr/share/doc/rsync-3.1.2/support/rrsync
/usr/share/doc/rsync-3.1.2/support/rsync-no-vanished
/usr/share/doc/rsync-3.1.2/support/rsync-slash-strip
/usr/share/doc/rsync-3.1.2/support/rsyncstats
/usr/share/doc/rsync-3.1.2/support/savetransfer.c
/usr/share/doc/rsync-3.1.2/tech_report.tex
/usr/share/man/man1/rsync.1.gz
/usr/share/man/man5/rsyncd.conf.5.gz
[root@ks-allinone ~]#
配置backup模块
[root@ks-allinone ~]# cat /etc/rsyncd.conf
uid = rsync
gid = rsync
port = 873
use chroot = on
max connections = 200
timeout = 120
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[bakup]
path = /data/bakup
read only = false
list = false
hosts allow = 192.168.11.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_bakup
secrets file = /etc/rsyncd.password
[root@ks-allinone ~]#
添加服务启动用户
useradd rsync -M -s /bin/nologin
配置同步虚拟用户rsync_bakup密钥
vim /etc/rsyncd.password
[root@ks-allinone ~]# cat /etc/rsyncd.password
4297f44b13955235245b2497399d7a93
[root@ks-allinone ~]#
设置密钥文件权限
chmod 600 /etc/rsyncd.password
本地手动推送
[root@riyimei ~]# rsync -vlzrtopg --progress --delete /data/bakup/ rsync_bakup@192.168.11.190::bakup --password-file=/etc/rsyncd.password
sending incremental file list
rsync: chgrp "/." (in bakup) failed: Operation not permitted (1)
./
liweiming
0 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/2)
rsync: chgrp "/.liweiming.4HaDr1" (in bakup) failed: Operation not permitted (1)
sent 118 bytes received 200 bytes 636.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1179) [sender=3.1.2]
[root@riyimei ~]#
设置定时任务-每天做一次全量备份推送到备份服务器
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 免密钥配置
[root@riyimei ~]# rpm -ql lsyncd
/etc/logrotate.d/lsyncd
/etc/lsyncd.conf
/etc/sysconfig/lsyncd
/usr/bin/lsyncd
/usr/lib/systemd/system/lsyncd.service
/usr/share/doc/lsyncd-2.2.2
/usr/share/doc/lsyncd-2.2.2/ChangeLog
/usr/share/doc/lsyncd-2.2.2/examples
/usr/share/doc/lsyncd-2.2.2/examples/lalarm.lua
/usr/share/doc/lsyncd-2.2.2/examples/lbash.lua
/usr/share/doc/lsyncd-2.2.2/examples/lecho.lua
/usr/share/doc/lsyncd-2.2.2/examples/lftp.lua
/usr/share/doc/lsyncd-2.2.2/examples/lgforce.lua
/usr/share/doc/lsyncd-2.2.2/examples/limagemagic.lua
/usr/share/doc/lsyncd-2.2.2/examples/lpostcmd.lua
/usr/share/doc/lsyncd-2.2.2/examples/lrsync.lua
/usr/share/doc/lsyncd-2.2.2/examples/lrsyncssh.lua
/usr/share/doc/lsyncd-2.2.2/examples/lsayirc.lua
/usr/share/licenses/lsyncd-2.2.2
/usr/share/licenses/lsyncd-2.2.2/COPYING
/usr/share/man/man1/lsyncd.1.gz
/var/log/lsyncd
[root@riyimei ~]#
[root@riyimei ~]# cat /etc/lsyncd.conf
----
-- User configuration file for lsyncd.
--
-- Simple example for default rsync, but executing moves through on the target.
--
-- For more examples, see /usr/share/doc/lsyncd*/examples/
--
sync{default.rsyncssh, source="/data/bakup", host="192.168.11.80", targetdir="/data/bakup/"}
[root@riyimei ~]#