最近公司做了一?分布式,便于管理安装了
server: 192.168.2.29
client: 192.168.2.230
先来配置client
安装就不介绍了[root@ser-tracker-230 rsync]# lltotal 16drwxr-xr-x. 2 root root 4096 Nov 13 04:23 bin-rw-r--r--. 1 root root 405 Nov 14 01:19 rsyncd.conf-rw-------. 1 root root 18 Nov 13 04:24 rsync.passwddrwxr-xr-x. 3 root root 4096 Nov 13 04:23 share[root@ser-tracker-230 rsync]# vim rsyncd.conf
rsyncd.conf uid = rootgid = rootuse chroot = nomax connections =10strict modes = yespid file = /var/run/rsyncd.pidlock file = /var/run/rsync.locklog file = /var/log/rsyncd.log[web] #需要同步的文件 path = /home/rsync/comment = web fileignore errorsread only = nowrite only = nohosts allow = 192.168.2.29hosts deny = *list = falseuid = rootgid = rootauth users = webusersecrets file = /usr/local/rsync/rsync.passwd
vim rsync.passwd 密码webuser:rsync-pwd
/usr/local/rsync/bin/rsync --daemon --config=/usr/local/rsync/rsyncd.conf
[root@ser-tracker-230 rsync]# vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT 防火qiang客户端,就安装完了,注意查看日志
/var/log/rsyncd.log 服务器配置:
[root@localhost test]# ll /proc/sys/fs/inotifytotal 0-rw-r--r-- 1 root root 0 Nov 14 11:37 max_queued_events-rw-r--r-- 1 root root 0 Nov 14 11:37 max_user_instances-rw-r--r-- 1 root root 0 Nov 14 11:35 max_user_watches 安装 安装inotify工具inotify-tools #都安装到 /usr/local/inotify/
主要是sh 文件
[root@localhost rsync]# lltotal 16drwxr-xr-x 2 root root 18 Nov 13 16:57 bin-rw-r--r-- 1 root root 427 Nov 14 14:05 inotifyrsync.sh-rw------- 1 root root 10 Nov 13 16:59 rsync.passwd------------------------------------------------------------------------------------------------vim rsync.passwdrsync-pwd
vim inotifyrsync.sh
#!/bin/bashhost1=192.168.2.230src=/home/rsync/testdst1=webuser1=webuser/usr/local/inotify/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/local/rsync/bin/rsync -vzrtopg --delete --progress --password-file=/usr/local/rsync/rsync.passwd $src $user1@$host1::$dst1 echo "${files} was rsynced" >>/tmp/rsync.log 2>&1 done
echo "/usr/local/rsync/inotifyrsync.sh &" >> /etc/rc.local
这样子,就OK了
参考 http://ixdba.blog.51cto.com/2895551/580280