Centos7 rsync+inotify实现实时同步更新
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实现实时同步更新的更多相关文章
- linux rsync +inotify 实现 实时同步
前言: rsync可以实现触发式的文件同步,但是通过crontab守护进程方式进行触发,同步的数据和实际数据会有差异,而inotify可以监控文件系统的各种变化,当文件有任何变动时,就触发rs ...
- rsync + inotify 数据实时同步
一.rsync介绍 rsync英文全称为Remote synchronization,从软件的名称就可以看出来,Rsync具有可是本地和远程两台主机之间的数据快速复制同步镜像.远程备份的功能,这个功能 ...
- rsync简介与rsync+inotify配置实时同步数据
rsync简介 rsync是linux系统下的数据镜像备份工具.使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH.rsync主机同步. rsync特性 rsync ...
- centos 配置rsync+inotify数据实时同步2
一.Rsync服务简介 1. 什么是Rsync 它是一个远程数据同步工具,它在同步文件的同时,可通过LAN/WAN快速同步多台主机间的文件.Rsync使用所谓的“rsync算法”来使本地和远程两个主机 ...
- centos 配置rsync+inotify数据实时同步
何为rsync? 定义: rsync是一个开源的快速备份工具,可以在不同主机之间镜像同步整个目录树,支持增量备份,保持链接和权限,非常适用于异地备份 何为源端和发起端? 在远程同步过程中,负责发起rs ...
- rsync+inotify实现实时同步案例--转
转自:http://chocolee.blog.51cto.com/8158455/1400596 随着应用系统规模的不断扩大,对数据的安全性和可靠性也提出的更好的要求,rsync在高端业务系统中也逐 ...
- Rsync+inotify实现实时同步
1.1 inotify介绍 inotify是一种强大的.细粒度的.异步的文件系统事件控制机制.linux内核从2.6.13起,加入了inotify支持,通过inotify可以监控文件系统中添加.删除. ...
- rsync+inotify实现文件同步更新(配置)
linux下为了数据安全或者网站同步镜像,不得不考虑一些实时备份的问题,这篇linux下通过rsync+inotify 实现数据实时备份配置过程记录下来,防止遗忘配置过程记录下来,防止遗忘!如有建议技 ...
- rsync+inotify实现实时同步案例【转】
1.1 inotify介绍 inotify是一种强大的.细粒度的.异步的文件系统事件控制机制.linux内核从2.6.13起,加入了inotify支持,通过inotify可以监控文件系统中添加.删除. ...
随机推荐
- 2017-2018 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2017)
2017-2018 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2017) 全靠 wxh的博客 补完这套.wx ...
- LeetCode 1146. Snapshot Array
原题链接在这里:https://leetcode.com/problems/snapshot-array/ 题目: Implement a SnapshotArray that supports th ...
- 关于System.InvalidOperationException异常
什么是InvalidOperationException 操作无效异常.当方法调用对对象的当前状态无效时引发的异常. 继承 Object Exception SystemException Inval ...
- 从零和使用mxnet实现线性回归
1.线性回归从零实现 from mxnet import ndarray as nd import matplotlib.pyplot as plt import numpy as np import ...
- Vue响应式原理以及注意事项
响应基于 set 和 get(Object.defineProperty) 类型: 单向绑定 双向绑定 简单例子(基于Object.defineProperty) <!DOCTYPE html& ...
- 关于Echarts柱状图实现的细节
echarts柱状图显示数值[1] echarts2: itemStyle : { normal: {label : {show: true, position: 'top'}}}, echarts ...
- Idea 进行断点调试的 快捷键
快捷键 功能描述F8 单步调试,不进入函数内部F7 单步调试,进入函数内部Shift+F7 选择要进入的函数Shift+F8 跳出函数Alt+F9 运行到断点Alt+F8 执行表达式查看结果F9 继续 ...
- 解决solr 请求参数过长报错too many boolean clauses Exception
booleanClauses属性的意义 貌似是查询条件有几个逻辑判断而不是参数长度. 如下面两种情况 a:1 OR b:2 AND C:3那么此时booleanClauses=3 id(1 2 3 4 ...
- promise、async和await
async:async function 声明将定义一个返回 AsyncFunction 对象的异步函数.当调用一个 async 函数时,会返回一个 Promise 对象.当这个 async 函数返回 ...
- idea Autowired 提示红色的解决方式