搭建rsync+inotify实现实时备份
一、环境搭建说明
系统环境
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实现实时备份的更多相关文章
- rsync + inotify 数据实时同步
一.rsync介绍 rsync英文全称为Remote synchronization,从软件的名称就可以看出来,Rsync具有可是本地和远程两台主机之间的数据快速复制同步镜像.远程备份的功能,这个功能 ...
- linux rsync +inotify 实现 实时同步
前言: rsync可以实现触发式的文件同步,但是通过crontab守护进程方式进行触发,同步的数据和实际数据会有差异,而inotify可以监控文件系统的各种变化,当文件有任何变动时,就触发rs ...
- CentOS7 Rsync服务搭建-Rsync+Inotify架构实现实时同步
一.rsync 概念 1.rsyncrsync是类unix/linux系统下的数据镜像备份工具.使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH.rsync主机同 ...
- centos 配置rsync+inotify数据实时同步2
一.Rsync服务简介 1. 什么是Rsync 它是一个远程数据同步工具,它在同步文件的同时,可通过LAN/WAN快速同步多台主机间的文件.Rsync使用所谓的“rsync算法”来使本地和远程两个主机 ...
- rsync简介与rsync+inotify配置实时同步数据
rsync简介 rsync是linux系统下的数据镜像备份工具.使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH.rsync主机同步. rsync特性 rsync ...
- centos7配置rsync+inotify数据实时共享
关于centos7版本上面搭建rsync服务并且实现实时同步之前一直是在6版本上面搭建rsync服务,在7版本上面折腾了半天.此处总结下inotify下载地址:http://github.com/do ...
- 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可以监控文件系统中添加.删除. ...
随机推荐
- gin索引优化实例1
GIN(Generalized Inverted Index, 通用倒排索引) 是一个存储对(key, posting list)集合的索引结构,其中key是一个键值,而posting list 是一 ...
- 百度下载给的termux是个坑
termux有两个版本,0.32以及0.64.百度提供0.32的下载,太坑爹.谷歌则是0.64的下载.32版uname -m识别为armv8l,绝对影响你进行其它linux的部署.通过atilo脚本会 ...
- Centos7安装redis5.0.7
1. 安装依赖包 yum install -y gcc gcc-c++ 2. 下载最新版redis安装包并解压安装 cd /usr/local/src wget http://download.red ...
- [Ubuntu篇] 在ubuntu上源码编译gtest,编写gtest-config.cmake并测试
本文首发于个人博客https://kezunlin.me/post/4a1427cf/,欢迎阅读! compile gtest on ubuntu 16.04 Guide compile gtest ...
- C#Windows Forms 使MessageBox顶层显示--xdd
方法1. MessageBox.Show("Text", "Caption", MessageBoxButtons.OK, MessageBoxIcon.Inf ...
- socket解决编码解码问题
MySocket类: import socket class MySocket(socket.socket): # 继承自socket文件中的socket类,此时socket就是父类 def __in ...
- 小程序如何判断用户(后台使用Django)
小程序如何判断用户是哪个: 有Web开发经验的都知道,客户端用户发起请求,服务器收到请求后,可以通过把用户user_id记录到session里,然后下次通过session里面的user_id来辨别是哪 ...
- gganimate|创建可视化动图,让你的图表会说话
本文首发于“生信补给站”公众号,https://mp.weixin.qq.com/s/kKQ2670FBiDqVCMuLBL9NQ 更多关于R语言,ggplot2绘图,生信分析的内容,敬请关注小号. ...
- Spring IOC容器装配Bean_基于XML配置方式
开发所需jar包 实例化Bean的四种方式 1.无参数构造器 (最常用) <?xml version="1.0" encoding="UTF-8"?> ...
- VMware密钥
UG5J2-0ME12-M89WY-NPWXX-WQH88 GA590-86Y05-4806Y-X4PEE-ZV8E0 YA18K-0WY8P-H85DY-L4NZG-X7RAD UA5DR-2ZD4 ...