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可以监控文件系统中添加.删除. ...
随机推荐
- springCloud值Eureka
Spring Cloud特点 约定优于配置 开箱即用.快速启动 适用于各种环境 PC Server 云环境 容器(Docker) 轻量级的组件 服务发现Eureka 组件的支持很丰富, ...
- 分布式环境配置虚拟域名,phpstudy配置虚拟域名,集成环境配置域名,域名禁止访问forbidden怎么解决
重启Apache,测试:
- python相对导包问题
导包分为:绝对路径.相对路径 在测试时发现不能够使用相对路径 查过之后才知道: 运行模块(如:main.py)中导包只能使用绝对路径,不能使用相对路径 官方文档: Note that relative ...
- Python实现电子词典
代码一览: dictionary/├── code│ ├── client.py│ ├── func.py│ ├── server.py│ └── settings.py├── dat ...
- Codeforces Round 563 (Div. 2) 题解
自己开了场镜像玩. 前三题大水题.D有点意思.E完全不会.F被题意杀了……然而还是不会. 不过看过(且看懂)了官方题解,所以这里是六题题解齐全的. A 水题.给原序列排序,如果此时合法则直接输出,否则 ...
- Redis哨兵、复制、集群的设计原理与区别
一 前言 谈到Redis服务器的高可用,如何保证备份的机器是原始服务器的完整备份呢?这时候就需要哨兵和复制. 哨兵(Sentinel):可以管理多个Redis服务器,它提供了监控,提醒以及自动的故障转 ...
- c++ rvo vs std::move
c++ rvo vs std::move To summarize, RVO is a compiler optimization technique, while std::move is just ...
- kali 命令
1.添加用户 如下命令是用root执行的 adduser dong 会直接在/home 目录创建 dong 目录 2.将用户划分到某个组 gpasswd -a user group 3.ifconfi ...
- Jenkins绑定git
1,新建任务
- 【转】Selenium 报错:Element is not clickable at point的解决办法
天一同学在写Selenium Java脚本时遇到一个问题,登录进入系统之后,要点击左侧的一个菜单,但是执行到该语句时报下面的错误: Firefox中报错如下:org.openqa.selenium.E ...