inotify slave部署  

   把master上指定文件下载到本地的主机指定目录

 yum install rsync –y
[root@localhost ~]# useradd rsync -s /sbin/nologin -M
[root@localhost ~]# mkdir -p /home/yxh/back
[root@localhost ~]# chown rsync.rsync /home/yxh/back/ echo rsync_backup:yxh >>/etc/rsync.password
rsync_backup 为用户名
yxh 为密码 [root@localhost ~]# chmod /etc/rsync.password
[root@localhost ~]# rsync --daemon
[root@localhost ~]# ss -tunlp | grep rsync
tcp LISTEN *: *:* users:(("rsync",pid=,fd=))
tcp LISTEN ::: :::* users:(("rsync",pid=,fd=)) 重启rsync
[root@localhost back]# ps -ef | grep rsync
root : ? :: rsync --daemon
root : pts/ :: grep --color=auto rsync
[root@localhost back]# kill -
[root@localhost back]# ps -ef | grep rsync
root : pts/ :: grep --color=auto rsync
[root@localhost back]# rsync --daemon
failed to create pid file /var/run/rsyncd.pid: File exists
[root@localhost back]# rm -fr /var/run/rsyncd.pid
[root@localhost back]# ls
[root@localhost back]# rsync --daemon

安装流程

[root@localhost etc]# vi rsyncd.conf

# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

uid = rsync
gid = rsync
use chroot = no
max connections =
pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
timeout =
# ignore nonreadable = yes
# dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 [backup]
path = /home/yxh/back/
ignore errors
read only = no
write only = no
list = false
fake super = yes
auth users = rsync_backup
secrets file = /etc/rsync.password

rsyncd.conf

inotify master部署

      master主机上的文件发生变化的时候     slave主机会自动进行同步变化的文件

[root@node2 ~]# yum install rsync –y
[root@node2 ~]# wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
[root@node2 ~]# tar zxf inotify-tools-3.14.tar.gz
[root@node2 ~]# cd inotify-tools-3.14
[root@node2 inotify-tools-3.14]# ./configure --prefix=/usr/local/inotify
[root@node2 inotify-tools-3.14]# mkdir -p /home/yxh/back/
[root@node2 inotify-tools-3.14]# echo "yxh" >/etc/rsync.password
[root@node2 inotify-tools-3.14]# chmod /etc/rsync.password 测试同步
[root@node2 back]# ls
test.txt
[root@node2 back]# rsync -avz /home/yxh/back/test.txt rsync_backup@192.168.11.175::backup --password-file=/etc/rsync.password sending incremental file list
test.txt sent bytes received bytes 286.00 bytes/sec
total size is speedup is 0.05

安装步骤

[root@node2 local]# vi inotify.sh

#!/bin/bash

host01=192.168.11.175
user=rsync_backup
rsync_passfile=/etc/rsync.password
inotify_home=/usr/local/inotify #judge
if [ ! -e "$src" ] \
|| [ ! -e "${rsync_passfile}" ] \
|| [ ! -e "${inotify_home}/bin/inotifywait" ] \
|| [ ! -e "/usr/bin/rsync" ];
then
echo "Check File and Folder"
exit
fi ${inotify_home}/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e close_write,delete,create,attrib $src \
| while read file
do # rsync -avzP --delete --timeout= --password-file=${rsync_passfile} $src $user@$host01::$dst >/dev/null >&
cd $src && rsync -aruz -R --delete ./ --timeout= $user@$host01::$dst --password-file=${rsync_passfile} >/dev/null >&
done
exit

同步脚本

3.执行脚本实现自动更新

[root@node2 local]# sh inotify.sh &       这种方式虽然可以实现脚本在后台运行 但是一旦关闭终端便会失效

nohup sh inotify.sh >run.log 2>&1 &      采取这种执行方式 即使关闭终端也可以生效 只要不重启系统即可一直在后台运行

[root@node2 local]# sh inotify.sh &
[] 在master上添加一个test2.txt文件保存
[root@node2 back]# ls
test.txt
[root@node2 back]# vi test2.txt
[root@node2 back]# ls
test2.txt test.txt 然后到slave节点上查看指定目录
test2.txt被自动同步到本地来
[root@localhost back]# ls
test2.txt test.txt
[root@localhost back]# vi test2.txt 加入开机启动
# echo "/bin/bash /home/yxh/inotify.sh &" >>/etc/rc.local

NFS实现映射远程磁盘目录

nfs安装
在两台机器上安装nsf 、 portmap
yum install nfs-utils portmap 88配置
88机器上的/uploaddir目录映射到89本地的/uploaddir目录
88编辑配置文件
[root]# vi /etc/exports
/uploaddir/ 10.199.142.89(rw,sync,no_root_squash) systemctl start rpcbind
systemctl start nfs 89配置
systemctl start rpcbind
systemctl start nfs mkdir /uploaddir
mount -t nfs 10.199.142.88:/uploaddir/ /uploaddir/ mount
10.199.142.88:/uploaddir on /uploaddir type nfs4

nfs安装配置

线上案例

vi /etc/rsync.password

root:rootpass

chmod  /etc/rsync.password

客户端配置用户名和密码

root@ etc]# vi rsyncd.conf

# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

uid =root
gid =root
use chroot = yes
max connections =
pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
timeout =
# ignore nonreadable = yes
# dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 # [ftp]
# path = /home/ftp
# comment = ftp export area uid = root
gid = root
use chroot = no
max connections =
strict modes = yes
hosts allow =
port =
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log [backup]
path = /deploydir
ignore errors
read only = no
write only = no
list = false
fake super = yes
secrets file = /etc/rsync.password

客户端rsyncd.conf

[root@ inotify-tools-3.14]# echo "rootpass" >/etc/rsync.password
[root@ inotify-tools-3.14]# chmod /etc/rsync.password [root@ uploaddir]# rsync -avz /uploaddir/.txt root@10.89::backup --password-file=/etc/rsync.password

服务端配置和测试

[root@ ~]# vi inotify.sh

#!/bin/bash
src=/uploaddir
host01=1.89
host02=1.90
user=root
dst=backup
rsync_passfile=/etc/rsync.password
inotify_home=/usr #judge
if [ ! -e "$src" ] \
|| [ ! -e "${rsync_passfile}" ] \
|| [ ! -e "${inotify_home}/bin/inotifywait" ] \
|| [ ! -e "/usr/bin/rsync" ];
then
echo "Check File and Folder"
exit
fi ${inotify_home}/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e close_write,delete,create,attrib $src \
| while read file
do cd $src && rsync -aruz -R --delete ./ --timeout= $user@$host01::$dst --password-file=${rsync_passfile} >/dev/null >& cd $src && rsync -aruz -R --delete ./ --timeout= $user@$host02::$dst --password-file=${rsync_passfile} >/dev/null >&
done
exit

后台服务脚本

[root@-]# cat /etc/rsync.password
rootpass [root@]# cat /etc/rsync/rsync.password
root:rootpass [root@]# cat /etc/rsyncd.conf
pid file = /var/run/rsyncd.pid
uid = nobody
gid = nobody
use chroot = no
log format = %t %a %m %f %b
syslog facility = local3
timeout =
address = 10.8 [backup]
uid =root
gid =root
use chroot = yes
max connections =
path = /deploydir
ignore errors
read only = no
write only = no
list = false
fake super = yes
secrets file = /etc/rsync/rsync.password

同一主机既是服务端也是客户端

Centos7 rsync+inotify实现实时同步更新的更多相关文章

  1. linux rsync +inotify 实现 实时同步

    前言:     rsync可以实现触发式的文件同步,但是通过crontab守护进程方式进行触发,同步的数据和实际数据会有差异,而inotify可以监控文件系统的各种变化,当文件有任何变动时,就触发rs ...

  2. rsync + inotify 数据实时同步

    一.rsync介绍 rsync英文全称为Remote synchronization,从软件的名称就可以看出来,Rsync具有可是本地和远程两台主机之间的数据快速复制同步镜像.远程备份的功能,这个功能 ...

  3. rsync简介与rsync+inotify配置实时同步数据

    rsync简介 rsync是linux系统下的数据镜像备份工具.使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH.rsync主机同步. rsync特性 rsync ...

  4. centos 配置rsync+inotify数据实时同步2

    一.Rsync服务简介 1. 什么是Rsync 它是一个远程数据同步工具,它在同步文件的同时,可通过LAN/WAN快速同步多台主机间的文件.Rsync使用所谓的“rsync算法”来使本地和远程两个主机 ...

  5. centos 配置rsync+inotify数据实时同步

    何为rsync? 定义: rsync是一个开源的快速备份工具,可以在不同主机之间镜像同步整个目录树,支持增量备份,保持链接和权限,非常适用于异地备份 何为源端和发起端? 在远程同步过程中,负责发起rs ...

  6. rsync+inotify实现实时同步案例--转

    转自:http://chocolee.blog.51cto.com/8158455/1400596 随着应用系统规模的不断扩大,对数据的安全性和可靠性也提出的更好的要求,rsync在高端业务系统中也逐 ...

  7. Rsync+inotify实现实时同步

    1.1 inotify介绍 inotify是一种强大的.细粒度的.异步的文件系统事件控制机制.linux内核从2.6.13起,加入了inotify支持,通过inotify可以监控文件系统中添加.删除. ...

  8. rsync+inotify实现文件同步更新(配置)

    linux下为了数据安全或者网站同步镜像,不得不考虑一些实时备份的问题,这篇linux下通过rsync+inotify 实现数据实时备份配置过程记录下来,防止遗忘配置过程记录下来,防止遗忘!如有建议技 ...

  9. rsync+inotify实现实时同步案例【转】

    1.1 inotify介绍 inotify是一种强大的.细粒度的.异步的文件系统事件控制机制.linux内核从2.6.13起,加入了inotify支持,通过inotify可以监控文件系统中添加.删除. ...

随机推荐

  1. Scrapy的中间件(一)

    中间件是Scrapy里面的一个核心概念.使用中间件可以在爬虫的请求发起之前或者请求返回之后对数据进行定制化修改,从而开发出适应不同情况的爬虫. "中间件"这个中文名字和前面章节讲到 ...

  2. SSM回顾

    1.mybatis 认识MyBatis:持久化 第一个MyBatis程序(重点) CRUD 配置 ResultMap结果集映射(重点) 一对多 多对一 Log4j 分页 注解开发 动态SQL 缓存 2 ...

  3. 深入js系列-类型(null)

    首先null是表示什么状态呢 这个是需要和上篇的undefined做一个区分 undefined 从未赋值 非关键词(也就是可以定义为变量名或者赋值给它) null 曾经赋值.目前没值 关键词 typ ...

  4. 接口自动化框架2-升级版(Pytest+request+Allure)

    前言: 接口自动化是指模拟程序接口层面的自动化,由于接口不易变更,维护成本更小,所以深受各大公司的喜爱. 第一版入口:接口自动化框架(Pytest+request+Allure) 本次版本做了一些升级 ...

  5. 图解 Java 垃圾回收机制,写得非常好!

    阅读本文大概需要 3.7 分钟. 翻译:Rhys_Lee, AzureSora, 溪边九节, 小小菜鸟鸡 blog.csdn.net/zl1zl2zl3/article/details/9090408 ...

  6. 使用CSS隐藏元素滚动条

    如何隐藏滚动条,同时仍然可以在任何元素上滚动? 首先,如果需要隐藏滚动条并在内容溢出时显示滚动条,只需要设置overflow:auto样式即可.想要完全隐藏滚动条只需设置overflow:hidden ...

  7. 一个sh脚本 同时运行 多个sh脚本

    问题: 原来的启动方式 cd /opt/OpenIMSCore ./pcscf.sh ./icscf.sh ./scscf.sh cd /opt/OpenIMSCore/FHoSS/deploy ./ ...

  8. Python 2 代码转 Python 3的一些转化

    Python 2 代码转 Python 3的一些转化 1.“print X” 更改为“print(X)” 2.xrange改为range 3.m.itervalues() 改为 m.values() ...

  9. [转帖]UML类图关系图解

    UML类图关系图解 https://www.cnblogs.com/TvvT-kevin/p/9357339.html 一.类结构 在类的UML图中,使用长方形描述一个类的主要构成,长方形垂直地分为三 ...

  10. 百度前端技术学院task13源代码

    突然发现只看书不练习也是不行的,这么简单的我竟然都不会写了. 要注意innerHTML,innerText和outText之间的异同. 同时也要会使用DOM2的添加事件,移除事件等 <!DOCT ...