规划
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.conf uid = nobody gid = nobody ignore errors read only = no write only = no list = false use chroot = no max connections =10 strict modes = yes pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log [client1] path = /tongbu comment = client1 tongbu file hosts allow = 192.168.71.133 hosts deny = * uid = root gid = root auth users = user1 secrets file = /etc/client1.pass [client2] path = /tongbu2 comment = client2 tongbu file hosts allow = 192.168.71.132 hosts deny = * uid = root gid = root auth users = user2 secrets file = /etc/client2.pass
(3)测试
[root@localhost ~]#mkdir /tongbu [root@localhost ~]#mkdir /tongbu2 [root@localhost tongbu]# cat /etc/client1.pass user1:123 [root@localhost tongbu]# cat /etc/client2.pass user2: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 NAME rsync 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.pass 123 [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/bash host=192.168.71.133 src=/tongbu/ dst=client1 user=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.pass 321 [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/bash host=192.168.71.132 src=/tongbu2/ dst=client2 user=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的,有啥问题,可留言