十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
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
成都创新互联科技有限公司专业互联网基础服务商,为您提供达州主机托管,高防物理服务器租用,成都IDC机房托管,成都主机托管等互联网服务。
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服务器上.