最近公司做了一??分布式,便于管理安装了
server: 192.168.2.29
client: 192.168.2.230
先来配置client
安装就不介绍了 [[email protected]-tracker-230 rsync]# ll total 16 drwxr-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.passwd drwxr-xr-x. 3 root root 4096 Nov 13 04:23 share [[email protected]-tracker-230 rsync]# vim rsyncd.conf
rsyncd.conf uid = root gid = root 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 [web] #需要同步的文件 path = /home/rsync/ comment = web file ignore errors read only = no write only = no hosts allow = 192.168.2.29 hosts deny = * list = false uid = root gid = root auth users = webuser secrets file = /usr/local/rsync/rsync.passwd
vim rsync.passwd 密码 webuser:rsync-pwd
/usr/local/rsync/bin/rsync --daemon --config=/usr/local/rsync/rsyncd.conf
[[email protected] rsync]# vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT 防火qiang
客户端,就安装完了,注意查看日志
/var/log/rsyncd.log服务器配置:
[[email protected] test]# ll /proc/sys/fs/inotify total 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 文件
[[email protected] rsync]# ll total 16 drwxr-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.passwd rsync-pwd
vim inotifyrsync.sh
#!/bin/bash host1=192.168.2.230 src=/home/rsync/test dst1=web user1=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 [email protected]$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
时间: 2024-10-11 05:26:49