一、环境搭建说明

系统环境

  CentOS7.5

备份节点

  主机名:backup01

  IP地址:172.16.2.41

数据节点

  主机名:nfs-master

  IP地址:172.16.2.31

二、在备份节点搭建rsync服务

Rsync服务端(即备份数据远程存储节点)
第一步:查看rsync安装包
rpm -qa rsync 第二步:添加rsync服务的用户,管理本地目录
useradd -s /sbin/nologin -M rsync
id rsync 第三步:配置rsync的进程模式(vim /etc/rsyncd.conf)
uid = rsync
gid = rsync
use chroot = no
max connections =
timeout =
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[backup]
path = /backup
ignore errors
read only = false
list = false
fake super = yes
hosts allow = 172.16.2.0/
hosts deny = 0.0.0.0/
auth users = rsync_backup
secrets file = /etc/rsync.password 第四步:根据rsync.conf的auth_users配置帐户,远程连接的,并根据secreets file参数生成密码文件
echo "rsync_backup:wt">>/etc/rsync.password
cat /etc/rsync.password 第五步:更改密码配置文件的权限
chmod /etc/rsync.password
ls -l /etc/rsync.password 第六步:创建共享的目录授权rsync服务管理
mkdir -p /backup
chown -R rsync.rsync /backup #提示:如果没有/backup目录,就会chdir failed 第七步:启动rsync服务并检查
rsync --daemon
ps -ef|grep rsync|grep -v grep
lsof -i : 第八步:开机自启动
echo "/usr/bin/rsync --daemon">>/etc/rc.local
tail - /etc/rc.local

三、在数据节点生成备份节点rsync服务的密码方便使用及安装inotify服务

1、生成密码

#数据端执行

第一步:生成连接服务器需要的密码文件
echo "wt">>/etc/rsync.password
cat /etc/rsync.password 第二步:为密码文件配置权限
chmod /etc/rsync.password
ls -l /etc/rsync.password

2、安装inotify服务

yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
yum install inotify-tools -y
rpm -qa inotify-tools

四、监控目录改变时执行rsync命令实时备份数据(此过程需写脚本,脚本如下)

脚本存放位置为:/server/scripts/inotify.sh,记得给脚本加上执行权限,chmod +x /server/scripts/inotify.sh

#!/bin/bash
inotifywait -mrq --timefmt '%Y/%m/%d %H:%M' --format '%T %e %w%f' -e create,attrib,modify,moved_to,close_write,delete,move /backup/ |while read file
do
cd /backup
rsync -az ./ --delete rsync_backup@172.16.2.41::backup --password-file=/etc/rsync.password
done

五、把监控脚本变成自定义服务并加入开机自启动

1、定义监控目录的脚本服务(即服务的start、stop、restart、status实现)

脚本存放位置为:/server/scripts/sync.sh,记得给脚本加上执行权限,chmod +x /server/scripts/sync.sh

#!/bin/bash
#chkconfig: . /etc/init.d/functions
if [ $# -ne ]
then
echo "usage: $0 {start|stop|status}"
exit
fi
case "$1" in
start)
if [ -e "/var/run/inotify.pid" ]
then
action "inotify service start fail" /bin/false
echo "sync server is running......"
sleep
exit
fi
/bin/bash /server/scripts/inotify.sh &
`ps -ef|grep "inotifywait"|grep -v "grep"|awk '{print $2}'` >/var/run/inotify.pid
if [ `ps -ef|grep inotify|wc -l` -gt ]
then
action "inotify service is started" /bin/true
else
action "inotify service is started" /bin/false
fi
;;
stop)
if [ `ps -ef|grep inotify|grep -v grep|wc -l` -a -e "/var/run/inotify.pid" ]
then
rm -f /var/run/inotify.pid >/dev/null >&
pkill inotifywait
else
action "inotify service stop fail" /bin/false
echo "sync server is not running"
sleep
exit
fi
sleep
if [ `ps -ef|grep inotify|grep -v grep|wc -l` -eq -a ! -e "/var/run/inotify.pid" ]
then
action "inotify service is stoped" /bin/true
else
action "inotify service is stoped" /bin/false
fi
;;
status)
if [ `ps -ef|grep inotify|wc -l` -gt ]
then
action "inotify service is running"
else
action "inotify service is stoped"
fi
;;
*)
echo "usage: $0 {start|stop|status}"
exit
esac

2、加入开机自启动

此脚本必须放在/usr/lib/systemd/system/下,例如/usr/lib/systemd/system/syncd.service,sysncd.service注册服务的配置如下

[Unit]
Description="这是inotify实时同步服务"
After=network.target remote-fs.target nss-lookup.target [Service]
Type=forking
ExecStart=/bin/sh /server/scripts/sync.sh start
ExecReload=/bin/sh /server/scripts/sync.sh restart
ExecStop=/bin/sh /server/scripts/sync.sh stop
KillSignal=SIGQUIT
TimeoutStopSec=
KillMode=process
PrivateTmp=true [Install]
WantedBy=multi-user.target

3、启动服务及加入开机自启动

systemctl start syncd
systemctl enable syncd

搭建rsync+inotify实现实时备份的更多相关文章

  1. rsync + inotify 数据实时同步

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

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

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

  3. CentOS7 Rsync服务搭建-Rsync+Inotify架构实现实时同步

    一.rsync 概念 1.rsyncrsync是类unix/linux系统下的数据镜像备份工具.使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH.rsync主机同 ...

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

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

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

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

  6. centos7配置rsync+inotify数据实时共享

    关于centos7版本上面搭建rsync服务并且实现实时同步之前一直是在6版本上面搭建rsync服务,在7版本上面折腾了半天.此处总结下inotify下载地址:http://github.com/do ...

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

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

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

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

  9. Rsync+inotify实现实时同步

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

随机推荐

  1. [学习笔记] 在Windows 10上安装 WebLogic 12.2.1.3

    本文适用于学习目的而撰写.截止目前WebLogic已经有12.2.1.4.0了. 在安装WebLogic 12.2.1.3.0 首先要在Windows10之上Oracle JDK 1.8.  当前认证 ...

  2. Oracle10g安装步骤(二)

    接上篇:

  3. CSS中选择器优先级与!important权重使用

    CSS中的选择器优先级与!important权重使用 .class选择器要高于标签选择器. #id选择器要高于.class选择器. 标签选择器是优先级最低的选择器. !important的属性它的权重 ...

  4. css居中布局的几种方式

    一.水平居中 若是行内元素,则直接给其父元素设置text-align: center即可 若是块级元素,则直接给该元素设置margin: 0 auto即可 若子元素包含浮动元素,则给父元素设置widt ...

  5. LVM扩容之xfs文件系统

    LVM的基础请见:https://www.cnblogs.com/wxxjianchi/p/9698089.html 一.放大LV的容量.放大容量是由内而外来操作的. 1.设置新的lvm分区:用fdi ...

  6. python json序列化与反序列化操作

    python json序列化与反序列化操作 # dumps() dict-->str 序列化 # loads() str---dict 反序列化 result1 = json.dumps({'a ...

  7. 使用 colgroup 和 col 实现响应式表格

    Table 在项目使用中十分频繁,特别是在后台管理系统中,table 无疑是数据展示的第一公民,在早些年的网页中,table 也是网页布局的第一选择,然后使用好 table 并不容易,其它有很多子元素 ...

  8. VMware中linux虚拟机的安装

    打开安装的VMware 15,点击新建虚拟机 2.选择典型即可,点击下一步 3.选择“稍后安装操作系统”,点击下一步 4.选择想安的版本,点击下一步 5.设置虚拟机名称及安装位置(路径必须全英文!) ...

  9. elastic search(es)安装

    全文搜索属于最常见的需求,开源的 Elasticsearch (以下简称 Elastic)是目前全文搜索引擎的首选. 它可以快速地储存.搜索和分析海量数据.维基百科.Stack Overflow.Gi ...

  10. matlab 降维工具 转载【https://blog.csdn.net/tarim/article/details/51253536】

    降维工具箱drtool   这个工具箱的主页如下,现在的最新版本是2013.3.21更新,版本v0.8.1b http://homepage.tudelft.nl/19j49/Matlab_Toolb ...