一、环境描述server:192.168.122.54client:192.168.122.55,192.168.122.56同步目录:/data/htmlserver端有任何数据更新,即将同步到client端,实时同步二、采用方法:rsync+inotify三、关于inotify原理(略)四、操作过程4.1服务端脚本
- #!/bin/bash
- yum install rsync -y
- mkdir -p /data/html #如果要同步的不是此目录,可以根据实际需要添加目录
- #wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
- tar xzvf inotify-tools-3.14.tar.gz
- cd inotify-tools-3.14
- ./configure
- make
- make install
- #cponfigure inotify
- cat >>/home/rsync.sh <<EOF
- #!/bin/bash
- src=/data/html/ #同步的源目录
- des=www
- host="192.168.122.55 192.168.122.56"
- /usr/local/bin/inotifywait -mrq --timefmt "%d/%m/%y %H:%M" --format "%T %w%f" -e modify,delete,create,attrib $src | while read files
- do
- for hostip in $host
- do
- rsync -vzrtopg --delete --progress --password-file=/etc/rsyncd.secrets $src root@$hostip::$des
- done
- echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
- done
- EOF
- #confiugre secret
- cat >> /etc/rsyncd.secrets <<EOF
- 123456
- root:123456
- EOF
- chmod 0600 /etc/rsyncd.secrets
- #setting running onboot
- echo "nohup /bin/bash /home/rsync.sh &" >> /etc/rc.local
- nohup /bin/bash /home/rsync.sh &
4.2 客户端脚本
- #!/bin/bash
- yum install rsync -y
- mkdir -p /data/html
- #configure rsyncd daemon
- cat >> /etc/rsyncd.conf<<EOF
- uid = root
- gid = root
- use chroot = no
- max connections = 5
- pid file = /var/run/rsyncd.pid
- lock file = /var/run/rsync.lock
- log file = /var/log/rsyncd.log
- [www]
- path=/data/html/
- comment = update
- ignore errors
- read only = no
- list = no
- hosts allow = 192.168.122.0/24
- auth users = root
- uid = root
- gid = root
- secrets file = /etc/rsyncd.secrets
- EOF
- #configure secret
- cat >> /etc/rsyncd.secrets <<EOF
- 123456
- root:123456
- EOF
- chmod 0600 /etc/rsyncd.secrets
- echo "rsync --daemon" >> /etc/rc.local
- rsync --daemon
五、测试过程。
略过测试过程,大家可以自己测试同步效果。
六、附一键安装包免费下载地址在 http://linux.linuxidc.com/用户名与密码都是www.linuxidc.com具体下载目录在 /2012年资料/11月/21日/rsync+inotify一键安装脚本RHEL6.0下C-kermit的安装及配置Linux虚拟文件系统--文件路径名的解析(2)--回退父目录相关资讯 rsync inotify inotify安装 rsync安装
- Linux下rsync 安装与配置 (今 07:40)
- 使用rsync实现客户端与服务器端的 (08月25日)
- rsync+inotify实现数据同步及常见 (08月08日)
| - Rsync企业实战之自动异地备份 (08月25日)
- rsync+inotify实现实时数据同步案 (08月08日)
- CentOS 下 Rsync安装配置详解 (07月30日)
|
本文评论 查看全部评论 (0)