rsync+inotify一键安装脚本
2012-11-21 08:16
471 查看
一、环境描述
server:192.168.122.54
client:192.168.122.55,192.168.122.56
同步目录:/data/html
server端有任何数据更新,即将同步到client端,实时同步
二、采用方法:rsync+inotify
三、关于inotify原理,请参考https://www.ibm.com/developerworks/cn/linux/l-inotify/
四、操作过程
4.1服务端脚本
4.2 客户端脚本
五、测试过程。
略过测试过程,大家可以自己测试同步效果。
六、附一键安装包
本文出自 “itnihao的运维技术博客” 博客,转载请与作者联系!
server:192.168.122.54
client:192.168.122.55,192.168.122.56
同步目录:/data/html
server端有任何数据更新,即将同步到client端,实时同步
二、采用方法:rsync+inotify
三、关于inotify原理,请参考https://www.ibm.com/developerworks/cn/linux/l-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
五、测试过程。
略过测试过程,大家可以自己测试同步效果。
六、附一键安装包
svn钩子自动更新post-commit for dir in $(svnlook dirs-changed /var/svn/web/) do svn update -N /opt/nginx/web/$dir --username "admin" --password "admin" done
本文出自 “itnihao的运维技术博客” 博客,转载请与作者联系!
相关文章推荐
- flink集群一键安装脚本 -- 消息中间件kafka集群安装
- shell脚本实现ipa一键安装(itms-services协议)
- LNMP下载和LNMP一键安装包脚本
- LAMP一键安装脚本(编译方式)
- lnmp环境一键安装脚本
- nginx--提供一键安装脚本
- ubuntu一键安装vnc脚本
- MySQL系列之一键安装脚本----单实例/多实例 推荐
- oracle安装环境一键部署脚本
- zabbix agentd客户端插件Shell一键自动安装脚本
- LNMP一键安装shell脚本
- CentOS7下pptp ***一键安装脚本
- lnmp一键安装脚本
- 一键安装thrift-0.9.0的脚本
- CentOS下LAMP一键yum安装脚本
- Centos 上面用Shell脚本一键安装LAMP环境