1.搭建rsync服务端
systemctl start rsyncd
systemctl enable rsyncd
systemctl status rsyncd
ss -ntl |grep 873
rpm -ql rsync
2.修改配置文件
vi /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 0
ignore errors
exclude = lost+found/
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
reverse lookup = no
hosts allow = 192.168.8.0/24 #客户端IP
[backup]
path = /backup/
comment = backup
read only = no
auth users = rsyncuser
secrets file = /etc/rsync.pass
3.创建rsync备份服务器目录
mkdir /backup
服务器端生成验证文件
echo "rsyncuser:magedu" > /etc/rsync.pass
chmod 600 /etc/rsync.pass
服务器端准备目录
mkdir /backup
服务器端启动rsync服务
rsync --daemon 可加入/etc/rc.d/rc.local实现开机启动
systemctl start rsyncd CentOS 7
客户端配置密码文件
echo "magedu" > /etc/rsync.pass
chmod 600 /etc/rsync.pass
客户端
开启inotify
yum -y install inotify-tools
4.客户端测试同步数据
rsync -avz --password-file=/etc/rsync.pass /data/backup rsyncuser@rsync服务器IP::backup
5.客户端创建inotify_rsync.sh脚本
vim inotify_rsync.sh #!/bin/bash
SRC='/data/backup/'
DEST='rsyncuser@rsync服务器IP::backup'
br/>#!/bin/bash
SRC='/data/backup/'
DEST='rsyncuser@rsync服务器IP::backup'
do
FILEPATH=${DIR}${FILE}
rsync -az --delete --password-file=/etc/rsync.pass $SRC $DEST &&
echo "At ${TIME} on ${DATE}, file $FILEPATH was backuped up via rsync"
/var/log/changelist.log
done
chmod +x inotify_rsync.sh
开启后台监控进程
6.sh inotify_rsync.sh &
ps -ef |grep inotify_rsync
注意:两台主机必须开启ssh免密登录,允许客户端把数据被分到rsync服务器上.
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。