vi /etc/rsyncd.conf
/usr/bin/rsync --daemon --config=/etc/rsyncd.conf
mkdir /test
2:配置服务器rsync
yum install rsync —y
服务器的rsync不需要配置,只需要创建一个客户端的密码文件 里面只填写客户端的密码
#!/bin/bash
host1=192.168.5.99
src=/test/
des1=test
user1=testuser
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e close_write,delete,create,attrib ${src} | while read file
do
rsync -vzrtopg --delete --progress ${src} ${user1}@${host1}::${des1} --password-file=/root/www1.pwd
#echo "${files} was rsynced" >> /tmp/rsync.log 2>&1
#echo "---------------------------------------------------------------------------"
done
4:测试同步 在服务器上执行
nohup /root/rsync.sh &
5:
如果报如下错误:
/usr/local/bin/inotifywait: error while loading shared libraries: libinotifytools.so.0: cannot open shared object file: No such file or directory
解决方法:
ln -sv /usr/local/lib/libinotify* /usr/lib/
ln -s /usr/local/lib/libinotifytools.so.0 /usr/lib64/libinotifytools.so.0
6:rsync排除不需要同步的目录
目录是位于${src}下面的,并且只能用相对路劲
排除单个目录data
rsync -vzrtopg --delete --progress --exclude 'data' ${src} ${user1}@${host1}::${des1} --password-file=/root/www1.pwd
要排除多个目录
rsync -vzrtopg --delete --progress --exclude-from '/root/rsyncexclude.txt' ${src} ${user1}@${host1}::${des1} --password-file=/root/www1.pwd
在/root/rsyncexclude.txt里定义要排除的文件夹和文件
data/compile/*
data/dbbackup/*
data/pay_cache/*
data/tmp/index.php