通过rsync+inotify数据的实时备份

简介:
通过rsync+inotify数据的实时备份
 
web1(nginx)  服务器节点1   192.168.0.9         /web1/wwwrooot
Server       内容发布节点   192.168.0.15       /web/wwwroot
 
1.安装rsync 与inotify-tools
安装inotify工具inotify-tools
 
[root@localhost wwwroot]# ll /proc/sys/fs/inotify/  有下面3项,说明系统默认支持inotify
total 0
-rw-r--r-- 1 root root 0 Aug 31 23:02 max_queued_events
-rw-r--r-- 1 root root 0 Aug 31 23:02 max_user_instances
-rw-r--r-- 1 root root 0 Aug 31 23:02 max_user_watches
 
下载inotify-tools
 
 wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
  tar xf inotify-tools-3.14.tar.gz
make  make install
 
安装inotify-tools可以生成以下2个指令
[root@localhost wwwroot]# ll /usr/local/bin/ 
total 104
-rwxr-xr-x 1 root root 37260 Aug 31 17:01 inotifywait
-rwxr-xr-x 1 root root 35434 Aug 31 17:01 inotifywatch
 
 
2.在服务节点上配置rsync(rsync服务端)
web1的节点的rsyncd.conf配置如下:
 
[root@nginx web1]# cat /etc/rsyncd.conf
uid=nobody
gid=nobody
use chroot=no
max connections=10
strict modes=no
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
log file=/var/log/rsyncd.log
 
[web1]
path=/web1/wwwroot
comment =web1 file
ignore errors
read only=no
write only=no
hosts allow=192.168.0.1/24
hosts deny=*
list=false
uid=root
gid=root
auth users=web1
secrets file=/etc/web1.pass
 
echo "/usr/bin/rsync --daemon" >>/etc/rc.local
 
3.配置内容发布节点
 
[root@localhost wwwroot]# cat inotifyrsync.sh
#!/bin/bash
host1=192.168.0.9
src=/web/wwwroot/
dst1=web1
user1=web1
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,delete,create,attrib $src \
|while read files
do
  /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/server.pass $src $user1@$host1::$dst1
echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
done
 
chmod 755 /web/wwwroot/inotifyrsync.sh
/web/wwwroot/inotifyrsync.sh &
 
最后执行脚本的时候
老是提示这个错误信息
[root@localhost wwwroot]# /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/server.pass /web/wwwroot/ web1@192.168.0.9::web1
rsync: failed to connect to 192.168.0.9: No route to host (113)
rsync error: error in socket IO (code 10) at clientserver.c(107) [sender=2.6.8]
 
一时没找到问题的原因:可以ping通192.168.0.9的,也可以ssh上去的
后来才发现是防火墙的问题
是web 节点(rsync服务端)的防火墙没有开启873(rsync的监听端口),后来关掉防火墙就可以实时同步了
一旦rsync客户端的数据有更新,会检测到有更新时会立马同步数据到rsync服务端(web节点)
 
测试结果
 
[root@client wwwroot]# touch 4.txt
 
[root@localhost wwwroot]# sh -x inotifyrsync.sh
+ host1=192.168.0.9
+ src=/web/wwwroot/
+ dst1=web1
+ user1=web1
+ /usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,delete,create,attrib /web/wwwroot/
+ read files
+ /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/server.pass /web/wwwroot/ web1@192.168.0.9::web1
building file list ...
6 files to consider
deleting landy
./
4.txt
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=1/6)
 
sent 186 bytes  received 44 bytes  460.00 bytes/sec
total size is 373  speedup is 1.62
+ echo '31/08/12 23:43 /web/wwwroot/4.txtATTRIB was rsynced'
+ read files
+ /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/server.pass /web/wwwroot/ web1@192.168.0.9::web1
building file list ...
 
 
 
[root@web1 wwwroot]# ll
total 24
-rw-r--r-- 1 root root   0 Aug 31  2012 1.txt
-rw-r--r-- 1 root root   0 Aug 31  2012 2.txt
-rw-r--r-- 1 root root   0 Aug 31  2012 3.txt
-rw-r--r-- 1 root root   0 Aug 31  2012 4.txt
-rwxr-xr-x 1 root root 373 Aug 31  2012 inotifyrsync.sh
 
实现了实时的rsync同步

本文转自 xxl714 51CTO博客,原文链接:http://blog.51cto.com/dreamgirl1314/979489,如需转载请自行联系原作者
相关文章
|
3天前
|
人工智能 自然语言处理 Shell
深度评测 | 仅用3分钟,百炼调用满血版 Deepseek-r1 API,百万Token免费用,简直不要太爽。
仅用3分钟,百炼调用满血版Deepseek-r1 API,享受百万免费Token。阿里云提供零门槛、快速部署的解决方案,支持云控制台和Cloud Shell两种方式,操作简便。Deepseek-r1满血版在推理能力上表现出色,尤其擅长数学、代码和自然语言处理任务,使用过程中无卡顿,体验丝滑。结合Chatbox工具,用户可轻松掌控模型,提升工作效率。阿里云大模型服务平台百炼不仅速度快,还确保数据安全,值得信赖。
132422 24
深度评测 | 仅用3分钟,百炼调用满血版 Deepseek-r1 API,百万Token免费用,简直不要太爽。
|
5天前
|
人工智能 API 网络安全
用DeepSeek,就在阿里云!四种方式助您快速使用 DeepSeek-R1 满血版!更有内部实战指导!
DeepSeek自发布以来,凭借卓越的技术性能和开源策略迅速吸引了全球关注。DeepSeek-R1作为系列中的佼佼者,在多个基准测试中超越现有顶尖模型,展现了强大的推理能力。然而,由于其爆火及受到黑客攻击,官网使用受限,影响用户体验。为解决这一问题,阿里云提供了多种解决方案。
16271 37
|
13天前
|
机器学习/深度学习 人工智能 自然语言处理
PAI Model Gallery 支持云上一键部署 DeepSeek-V3、DeepSeek-R1 系列模型
DeepSeek 系列模型以其卓越性能在全球范围内备受瞩目,多次评测中表现优异,性能接近甚至超越国际顶尖闭源模型(如OpenAI的GPT-4、Claude-3.5-Sonnet等)。企业用户和开发者可使用 PAI 平台一键部署 DeepSeek 系列模型,实现 DeepSeek 系列模型与现有业务的高效融合。
|
4天前
|
并行计算 PyTorch 算法框架/工具
本地部署DeepSeek模型
要在本地部署DeepSeek模型,需准备Linux(推荐Ubuntu 20.04+)或兼容的Windows/macOS环境,配备NVIDIA GPU(建议RTX 3060+)。安装Python 3.8+、PyTorch/TensorFlow等依赖,并通过官方渠道下载模型文件。配置模型后,编写推理脚本进行测试,可选使用FastAPI服务化部署或Docker容器化。注意资源监控和许可协议。
1235 8
|
13天前
|
人工智能 搜索推荐 Docker
手把手教你使用 Ollama 和 LobeChat 快速本地部署 DeepSeek R1 模型,创建个性化 AI 助手
DeepSeek R1 + LobeChat + Ollama:快速本地部署模型,创建个性化 AI 助手
3385 117
手把手教你使用 Ollama 和 LobeChat 快速本地部署 DeepSeek R1 模型,创建个性化 AI 助手
|
8天前
|
人工智能 自然语言处理 API
DeepSeek全尺寸模型上线阿里云百炼!
阿里云百炼平台近日上线了DeepSeek-V3、DeepSeek-R1及其蒸馏版本等六款全尺寸AI模型,参数量达671B,提供高达100万免费tokens。这些模型在数学、代码、自然语言推理等任务上表现出色,支持灵活调用和经济高效的解决方案,助力开发者和企业加速创新与数字化转型。示例代码展示了如何通过API使用DeepSeek-R1模型进行推理,用户可轻松获取思考过程和最终答案。
|
5天前
|
人工智能 自然语言处理 程序员
如何在通义灵码里用上DeepSeek-V3 和 DeepSeek-R1 满血版671B模型?
除了 AI 程序员的重磅上线外,近期通义灵码能力再升级全新上线模型选择功能,目前已经支持 Qwen2.5、DeepSeek-V3 和 R1系列模型,用户可以在 VSCode 和 JetBrains 里搜索并下载最新通义灵码插件,在输入框里选择模型,即可轻松切换模型。
896 14
|
12天前
|
API 开发工具 Python
阿里云PAI部署DeepSeek及调用
本文介绍如何在阿里云PAI EAS上部署DeepSeek模型,涵盖7B模型的部署、SDK和API调用。7B模型只需一张A10显卡,部署时间约10分钟。文章详细展示了模型信息查看、在线调试及通过OpenAI SDK和Python Requests进行调用的步骤,并附有测试结果和参考文档链接。
1900 9
阿里云PAI部署DeepSeek及调用
|
9天前
|
人工智能 数据可视化 Linux
【保姆级教程】3步搞定DeepSeek本地部署
DeepSeek在2025年春节期间突然爆火出圈。在目前DeepSeek的网站中,极不稳定,总是服务器繁忙,这时候本地部署就可以有效规避问题。本文以最浅显易懂的方式带读者一起完成DeepSeek-r1大模型的本地部署。
|
12天前
|
缓存 自然语言处理 安全
快速调用 Deepseek API!【超详细教程】
Deepseek 强大的功能,在本教程中,将指导您如何获取 DeepSeek API 密钥,并演示如何使用该密钥调用 DeepSeek API 以进行调试。

热门文章

最新文章