规划
Server:备份端192.168.71. 134
Client1:被备份端192.168.71.133
Client2:被备份端192.168.71. 132
Server:备份端192.168.71. 134
(1)安装rsync
[root@localhost ~]#cd Desktop/[root@localhost Desktop]#tar zxf rsync-3.0.9.tar.gz -C /opt/[root@localhost Desktop]#cd /opt/rsync-3.0.9/[root@localhost inotify-tools-3.13]#./configure;make && make install
(2)配置rsync(/etc/rsyncd.conf,该文件默认不存在,需手动创建,并进行配置)
[root@localhost ~]# vi /etc/rsyncd.confuid = nobodygid = nobodyignore errorsread only = nowrite only = nolist = falseuse chroot = nomax connections =10strict modes = yespid file = /var/run/rsyncd.pidlock file = /var/run/rsync.locklog file = /var/log/rsyncd.log[client1]path = /tongbucomment = client1 tongbu filehosts allow = 192.168.71.133hosts deny = *uid = rootgid = rootauth users = user1secrets file = /etc/client1.pass[client2]path = /tongbu2comment = client2 tongbu filehosts allow = 192.168.71.132hosts deny = *uid = rootgid = rootauth users = user2secrets file = /etc/client2.pass
(3)测试
[root@localhost ~]#mkdir /tongbu [root@localhost ~]#mkdir /tongbu2[root@localhost tongbu]# cat /etc/client1.passuser1:123[root@localhost tongbu]# cat /etc/client2.passuser2:321[root@localhost tongbu]# ll /etc/client*-rw------- 1 root root 10 Apr 5 02:38 /etc/client1.pass-rw------- 1 root root 10 Apr 5 03:24 /etc/client2.pass[root@localhost ~]# /usr/local/bin/rsync –daemon 开启守护进程[root@localhost ~]#echo “/usr/local/bin/rsync –daemon” >> /etc/rc.local 设置开机自动运行
[root@localhost ~]# ps -ef|grep rsync 查看守护进程是否开启root 16592 1 0 00:46 ? 00:00:00 /usr/local/bin/rsync --daemon[root@localhost ~]# lsof -i:873 查看默认端口873是否开启COMMAND PID USER FD TYPE DEVICE SIZE NODE NAMErsync 16592 root 4u IPv6 65197 TCP *:rsync (LISTEN)rsync 16592 root 5u IPv4 65198 TCP *:rsync (LISTEN)
Client1:被备份端192.168.71. 133
(1)安装rsync
[root@localhost ~]#cd Desktop/[root@localhost Desktop]#tar zxf rsync-3.0.9.tar.gz -C /opt/[root@localhost Desktop]#cd /opt/rsync-3.0.9/[root@localhost inotify-tools-3.13]#./configure;make && make install
(2)安装inotify
[root@localhost ~]# cd Desktop/[root@localhost Desktop]# tar xfz inotify-tools-3.13.tar.gz -C /opt/[root@localhost Desktop]# cd /opt/inotify-tools-3.13/[root@localhost inotify-tools-3.13]# ./configure;make && make install
(3)创建测试目录,密码文件以及同步所用脚本
[root@localhost ~]#mkdir /tongbu[root@localhost tongbu]# cat /etc/client1.pass123[root@localhost tongbu]# ll /etc/client1.pass-rw------- 1 root root 4 Apr 5 17:29 /etc/client1.pass[root@localhost tongbu]# cat inotifyrsync.sh#!/bin/bashhost=192.168.71.133src=/tongbu/dst=client1user=user1/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src |while read files do/usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/client1.pass $src $user@$host::$dst echo " was rsynced" >> /tmp/rsync.log 2>&1 done
(4)给inotify脚本添加可执行权限,并在后台运行,以及开机自起
[root@localhost tongbu]# chmod 755 inotifyrsync.sh[root@localhost tongbu]# ./inotifyrsync.sh & 需要备份端以此脚本作为守护进程[root@localhost tongbu]#echo “/web/wwwroot/inotifyrsync.sh &” >> /etc/rc.local 开机自动运行
Client2:被备份端192.168.71.132
(1)安装rsync
[root@localhost ~]#cd Desktop/[root@localhost Desktop]#tar zxf rsync-3.0.9.tar.gz -C /opt/[root@localhost Desktop]#cd /opt/rsync-3.0.9/[root@localhost inotify-tools-3.13]#./configure;make && make install
(2)安装inotify
[root@localhost ~]# cd Desktop/[root@localhost Desktop]# tar xfz inotify-tools-3.13.tar.gz -C /opt/[root@localhost Desktop]# cd /opt/inotify-tools-3.13/[root@localhost inotify-tools-3.13]# ./configure;make && make install
(3)创建测试目录,密码文件以及同步所用脚本
[root@localhost ~]#mkdir /tongbu2[root@localhost tongbu2]# cat /etc/client2.pass321[root@localhost tongbu2]# ll /etc/client2.pass-rw------- 1 root root 4 02-24 00:12 /etc/client2.pass[root@localhost tongbu2]# cat inotifyrsync.sh#!/bin/bashhost=192.168.71.132src=/tongbu2/dst=client2user=user2/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src |while read files do /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/client2.pass $src $user@$host::$dst echo " was rsynced" >> /tmp/rsync.log 2>&1 done
(4)给inotify脚本添加可执行权限,并在后台运行,以及开机自起
[root@localhost tongbu2]# chmod 755 inotifyrsync.sh[root@localhost tongbu2]# ./inotifyrsync.sh & 需要备份端以此脚本作为守护进程
现在,大家就可以测试了:分别在Rsync被备份端的/tongbu,
/tongbu2
目录下创建文件,看是否能实时备份到Rsync Server备份端的/tongbu及
/tongbu2
目录下,本人测试是ok的,有啥问题,可留言