rsync+inotify一键安装脚本
一、环境描述
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
本文转自it你好 51CTO博客,原文链接:http://blog.51cto.com/itnihao/1065426,如需转载请自行联系原作者
rsync+inotify一键安装脚本相关推荐
- nginx一键安装脚本
nginx一键安装脚本 [root@cc nginx]# cat nginx_install.sh #!/bin/bash # > File Name: nginx_install.sh # & ...
- CentOS7下pptp ***一键安装脚本
CentOS 6.7下pptp ***一键安装脚本,安装如下: wget http://mirrors.linuxeye.com/scripts/***_centos.sh chmod +x ./** ...
- mysql脚本简书,mysql一键安装脚本
#!/bin/bash #MySQL一键安装脚本 #脚本运行前请确认本机没有安装其他版本的MySQL #运行脚本前请详细阅读my.cnf文件 PASSWORD=`cat my.cnf | grep p ...
- *** Python版一键安装脚本
本脚本适用环境: 系统支持:CentOS 6,7,Debian,Ubuntu 内存要求:≥128M 日期:2018 年 02 月 07 日 关于本脚本: 一键安装 Python 版 *** 的最新版. ...
- linux安装yum的脚本,lnmp一键安装脚本yum方式快速安装
自己编写的yum安装方式的LNMP一键安装脚本,yum方式安装,速度非常快,目前只有centos版本,其他系统没有弄. Centos5 chmod +x lnmp.sh sh lnmp.sh Cent ...
- NPS内网穿透服务端一键安装脚本
NPS内网穿透服务端一键安装脚本,支持安装,更新,卸载以及重新生成配置文件,基于官方GitHub制作,自动安装最新版本 作者博客链接 脚本概览 安装 wget https://content.928w ...
- Frps一键安装脚本,带Frpc Windows便捷启动脚本
说明:Frp估计很多人都用过,一个高性能的内网穿透工具,支持tcp.udp.http.https协议,安装和使用教程可以直接查看官方中文文档→传送门,写的超详细.这里博主分享个某大佬写的Frps一键脚 ...
- [转] *** 一键安装脚本(四合一)
[from] https://teddysun.com/486.html 本脚本适用环境 系统支持:CentOS 6+,Debian 7+,Ubuntu 12+ 内存要求:≥128M 日期 :2017 ...
- Linux安装lamp脚本,CentOS LAMP一键安装脚本
LAMP简单介绍 LAMP指的Linux(操作系统).Apache(HTTP 服务器),MySQL(有时也指MariaDB,数据库软件) 和PHP(有时也是指Perl或Python)的第一个字母缩写, ...
最新文章
- java notify视频_一个很好的小例子来演示java中的wait()和notify()方法
- 从源码分析RocketMQ系列-Consumer消息接收逻辑
- 转:PHP程序里的敏感信息处理方法
- Unity 手机的旋转控制
- 2019.2.4时GitHub超过15个粉丝就可以领取3000元啦!
- 年度重磅!2020年度中国计算机视觉人才调研报告正式发布
- Linux 以form表单形式上传文件
- HTTP状态码及对应原因
- SCM供应链管理系统的优点
- 从“H1N1病毒”看危机意识的重要性
- python中heapq的库是什么_详解Python中heapq模块的用法
- 【Educoder作业】※ 数值信息——除二取余
- MySQL的基本用法
- 震屏效果java_CocosCreator 实现手机震动效果
- 悲观锁和乐观锁的区别及使用场景
- 业务逻辑层,表示层,会话层及层间关系
- PGP应用——如何使用PGP软件?
- 隐藏浏览器滚动条但内容可以滚动的3种解决方式(简单清晰)
- java项目经理工资_java项目经理工资待遇及月薪是多少?
- webpack 效率及性能提升