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. A9G开发

    巨坑 不支持联通 发短信 上电,准备好后使用 结束标志 取消换行  以16进制发  0x1a 实际测试 中间可以有很多行内容 短信内容结束换行 最后必须以 16进制 发送 0x1a  带和不带换行都可 ...

  2. 表格插件BootStrap-Table使用教程

    Bootstrap table 是一款基于 Bootstrap 的 jQuery 表格插件,功能比较完备,能够实现数据异步获取,编辑,排序等一系列功能. 官网https://bootstrap-tab ...

  3. Python实现电子词典(web)

    思路: 准备配置文件setting.py,运行src/data.py,使用MySQL新建数据库并创建table,将字典数据导入到table中.编写server.py文件,建立服务端,循环接收web请求 ...

  4. 洛谷 P3373 【模板】线段树 2 题解

    P3373 [模板]线段树 2 题目描述 如题,已知一个数列,你需要进行下面三种操作: 1.将某区间每一个数乘上x 2.将某区间每一个数加上x 3.求出某区间每一个数的和 输入格式 第一行包含三个整数 ...

  5. 第08组 Beta冲刺(3/5)

    队名:955 组长博客:点这里! 作业博客:点这里! 组员情况 组员1(组长):庄锡荣 过去两天完成了哪些任务 文字/口头描述 ? 维持进度,检查需求 展示GitHub当日代码/文档签入记录 接下来的 ...

  6. java 调用腾讯身份OCR接口文档实例(绝对可用)

      1.情景展示 通过读取身份证照片上的信息,实现自动填充功能. 2.原因分析 想要解析照片上所携带的相关信息,就需要识别照片的功能,腾讯提供了免费的身份证OCR接口,可供大家使用. 没有耐心的可以直 ...

  7. java语言总结

    优点: 安全(废弃指针) 任何一个学过C或者C++的人都知道指针的操作对于他们是很重要的,指针能够支持内存的直接操作,这样的直接操作能够带来的是效率上的提高.但是任何一个东西都是有副作用的,指针给程序 ...

  8. MySQL重要知识点

    可能是全网最好的MySQL重要知识点 |  mp.weixin.qq.com 点击蓝色“程序猿DD”关注我 回复“资源”获取独家整理的学习资料! 标题有点标题党的意思,但希望你在看了文章之后不会有这个 ...

  9. 利用docker实现私有镜像仓库

    利用docker实现私有镜像仓库 在linux服务器上安装了docker过后,可以拉取docker镜像仓库: docker pull registry 再执行命令让镜像run起来: docker ru ...

  10. React组件介绍与使用(父传子、子传父、兄弟传)

    1.创建组件的方法     1.1.函数式无状态组件 1.1.1.语法 1 function myComponent(props) { 2 return 3 <div>Hello {pro ...