|
|
数据端:192.168.163.129
镜像端:192.168.163.130
数据端配置:
监测是否系统支持inotify
uname -r
2.6.18-308.el5
ll /proc/sys/fs/inotify
total 0
-rw-r--r-- 1 root root 0 Jul 24 23:14 max_queued_events
-rw-r--r-- 1 root root 0 Jul 24 23:14 max_user_instances
-rw-r--r-- 1 root root 0 Jul 24 23:14 max_user_watches
有以上3个文件,说明支持安装,好了放心的开始装吧~
安装rsync
这里直接yum安装,tar包也可以,安装简单直接./configure && make && make install
yum install rsync -y
安装inotify-tools包
编写同步脚本
#!/bin/bash
src='/var/www/html/'
des='root@192.168.163.130::web'
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' \
-e modify,delete,create,attrib ${src} \
| while read x
do
/usr/bin/rsync -vzrtopg --delete --progress $src $des --password-file=/etc/rsyncd.secrets &&
echo "$x was rsynced" >> /var/log/rsync.log
done
设置密码文件
echo "123456" > /etc/rsyncd.secrets
chmod 0600 /etc/rsyncd.secrets
后台运行同步脚本
echo "脚本.sh &" >> /etc/rc.local
镜像端配置:
vim /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 100
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[web]
path = /var/www/html
ignore errors
read only = no
list = no
hosts allow = *
auth users = root
secrets file = /etc/rsyncd.secrets
echo "root:123456" > /etc/rsyncd.secrets
chmod 0600 /etc/rsyncd.secrets
启动rsync:/usr/local/bin/rsync --daemon
可能出现的问题:
出现错误:/usr/local/bin/inotifywait: error while loading shared libraries: libinotifytools.so.0
解决方法:
ln -sv /usr/local/lib/libinotify* /usr/lib/
ln -s /usr/local/lib/libinotifytools.so.0 /usr/lib64/libinotifytools.so.0
|
|
|
|
|
|
|
|