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可以监控文件系统中添加.删除. ...
随机推荐
- ABP 报错1
报错:.net core 2.2 HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure 解决:安装.net core 2.2就解决了, 本地安装 ...
- sass、less异同
相同点: 1.混入(Mixins):class中的class 2.参数混入:可以传递参数的class,就像函数一样 3.嵌套规则:class中嵌套class,从而减少重复的代码 4.运算:css中用上 ...
- 洛谷p1776宝物筛选
宝物筛选 多重背包问题 物品数目已知 可以枚举每个物品 当做01背包来做 不过会超时 此时需要二进制拆分来优化 分解成新的物品 再跑一遍01背包即可 //二进制拆分+01背包 //设f[j]表示前i件 ...
- 【border相关】【P3426】 [POI2005]SZA-Template
[border相关][P3426] [POI2005]SZA-Template Description 给定一个字符串 \(S\),要求一个最短的字符串 \(T\),使得 \(S\) 可以由 \(T\ ...
- PATA1082Read Number in Chinese
有几点需要注意的地方一是将right转化为与left在在同一节 while (left + 4 <= right) { right -= 4;//每次将right移动4位,直到left与righ ...
- String.format()的详细用法
问题 在开发的时候一段字符串的中间某一部分是需要可变的 比如一个Textview需要显示”XXX用户来自 上海 年龄 21 性别 男” 其中的 XXX 是用户名 每个用户也是不一样的 地区 上海 为可 ...
- Guava cacha 机制及源码分析
1.ehcahce 什么时候用比较好:2.问题:当有个消息的key不在guava里面的话,如果大量的消息过来,会同时请求数据库吗?还是只有一个请求数据库,其他的等待第一个把数据从DB加载到Guava中 ...
- 软件工程1916|W(福州大学)_助教博客】个人总结作业(第12次)成绩公示
1.作业链接 个人作业--软件工程实践总结作业 https://edu.cnblogs.com/campus/fzu/SoftwareEngineering1916W/homework/3316 2. ...
- sklearn保存模型的两种方式
sklearn 中模型保存的两种方法 一. sklearn中提供了高效的模型持久化模块joblib,将模型保存至硬盘. from sklearn.externals import joblib # ...
- mapreduce 函数入门 一
MapReduce 程序的业务编码分为两个大部分,一部分配置程序的运行信息,一部分 编写该 MapReduce 程序的业务逻辑,并且业务逻辑的 map 阶段和 reduce 阶段的代码分别继 承 Ma ...