当前位置: 首页 > news >正文

rsync+sersync实现文件实时同步

server作为备份服务器,rsyncd,客户端client使用工具连接

rsync 的服务端配置(rsyncd.conf)仅对服务器端的 rsyncd 服务生效,必须在服务器端重启服务才能加载新配置。客户端的 rsyncd 服务与当前连接的服务器端无关,重启客户端服务既不会让服务器端配置生效,也不影响客户端用rsync命令发起连接(客户端只需安装 rsync 工具,无需运行 rsyncd 服务)。

改服务端配置,就重启服务端的 rsyncd;客户端不需要运行 rsyncd 服务,也不用重启

#安装软件包[root@server ~ 10:14:10]# yum install -y rsync​# 准备同步目录,该目录任何用户都可以读写。[root@server ~ 08:43:26]#  mkdir -m 777 /backup# 配置rsync,不验证用户,直接同步[root@server ~ 10:11:06]# vim /etc/rsyncd.conf​#vim添加命令行# 添加如下配置[backup]# 描述信息comment = backup# 备份路径path = /backup# 设置可写read only = no# 指定用户名auth users = rsync# 指定用户密码文件secrets file = /etc/rsyncd.secrets​#编辑root权限[root@server ~ 10:26:58]# vim /etc/rsyncd.confuid=rootgid=root#重启[root@server ~ 10:29:23]# systemctl restart rsyncd --now​# 创建用户凭据文件[root@server ~ 10:13:16]# echo 'rsync:redhat' > /etc/rsyncd.secrets[root@server ~ 10:13:35]# chmod 400 /etc/rsyncd.secrets​# 启用并启动rsyncd服务[root@server ~ 10:13:43]# systemctl enable rsyncd --nowCreated symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.​# 配置防火墙[root@server ~ 10:13:50]# firewall-cmd --add-service=rsyncdsuccess[root@server ~ 10:14:01]#  firewall-cmd --add-service=rsyncd --permanentsuccess​#关闭seLinux[root@server ~ 10:28:59]# setenforce 0

客户端配置和测试

# 准备密码文件[root@client ~ 09:21:27]# echo redhat > rsyncd.secrets[root@client ~ 10:20:48]# chmod 400 rsyncd.secrets​​​# 传输测试[root@client ~ 10:30:04]# rsync -av --password-file=./rsyncd.secrets /etc/hostname rsync@server::backupsending incremental file listhostname​sent 110 bytes  received 35 bytes  290.00 bytes/sectotal size is 17  speedup is 0.12​​# 验证结果[root@server ~ 10:32:35]# ls /backup/hostname​

安装软件包

# 下载软件[root@client ~]# wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz#或者将sersync2.5.4_64bit_binary_stable_final.tar.gz拖入窗口安装[root@client ~ 10:41:09]# rz -Erz waiting to receive.​# 解压文件[root@client ~ 10:54:48]# tar xf sersync2.5.4_64bit_binary_stable_final.t
配置文件
[root@client ~ 10:57:18]# vim confxml.xml<?xml version="1.0" encoding="ISO-8859-1"?><head version="2.5"><host hostip="localhost" port="8008"></host><debug start="false"/><fileSystem xfs="true"/><filter start="true"><exclude expression="^cache/*"></exclude></filter><inotify><delete start="true"/><createFolder start="true"/><createFile start="false"/><closeWrite start="true"/><moveFrom start="true"/><moveTo start="true"/><attrib start="false"/><modify start="false"/></inotify><sersync><localpath watch="/app_data"><remote ip="10.1.8.10" name="backup"/></localpath><rsync><commonParams params="-azP"/><auth start="true" users="rsync" passwordfile="/root/rsyncd.secrets"/><userDefinedPort start="false" port="873"/><timeout start="false" time="100"/><ssh start="false"/></rsync><failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><crontab start="false" schedule="600"><!--600mins--><crontabfilter start="false"><exclude expression="*.php"></exclude><exclude expression="info/*"></exclude></crontabfilter></crontab><plugin start="false" name="command"/></sersync><plugin name="command"><param prefix="/bin/sh" suffix="" ignoreError="true"/><filter start="false"><include expression="(.*)\.php"/><include expression="(.*)\.sh"/></filter></plugin></head>

运行Sersync

[root@client ~ 11:01:20]# cp GNU-Linux-x86/sersync2 /usr/local/bin/[root@client ~ 11:02:24]# sersync2 -hset the system paramexecute:echo 50000000 > /proc/sys/fs/inotify/max_user_watchesexecute:echo 327679 > /proc/sys/fs/inotify/max_queued_eventsparse the command param_______________________________________________________参数-d:启用守护进程模式参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍c参数-n: 指定开启守护线程的数量,默认为10个参数-o:指定配置文件,默认使用confxml.xml文件参数-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块参数-m:单独启用其他模块,使用 -m socket 开启socket模块参数-m:单独启用其他模块,使用 -m http 开启http模块不加-m参数,则默认执行同步程序_____________________________________________________________​# 运行 Sersync,-d 后台运行[root@client ~ 11:02:35]# sersync2 -o confxml.xml -dset the system paramexecute:echo 50000000 > /proc/sys/fs/inotify/max_user_watchesexecute:echo 327679 > /proc/sys/fs/inotify/max_queued_eventsparse the command paramoption: -o  config xml name:  confxml.xmloption: -d  run as a daemondaemon thread num: 10parse xml config filehost ip : localhost host port: 8008now the filter work ,if you set the crontab,you have to set crontab filter WARNING XFS FILE SYSTEM WORKdaemon start,sersync run behind the console use rsync password-file :user is rsyncpasswordfile is     /root/rsyncd.secretsconfig xml parse successplease set /etc/rsyncd.conf max connections=0 Manuallysersync working thread 12  = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)please according your cpu ,use -n param to adjust the cpu raterun the sersync: watch path is: /app_data

测试文件实时同步

# server 端监控目录 /backup[root@server ~ 10:41:27]# watch -n 1 ls /backup​#在客户端创建文件和目录[root@client ~ 11:03:42]# echo hello world > /app_data/welcome.txt[root@client ~ 11:04:22]# mkdir /app_data/dbdata​# 客户端删除文件[root@client ~ 11:04:37]# rm -fr /app_data/*

[root@client ~ 11:04:55]# cp confxml.xml /etc/sersyncd.conf[root@client ~ 11:23:24]# vim /etc/systemd/system/sersyncd.service[Unit]Description=SerSync server daemon​[Service]Type=forkingExecStart=/usr/local/bin/sersync2 -o /etc/sersyncd.conf -d​[Install]WantedBy=multi-user.target[root@client ~ 11:24:22]# systemctl daemon-reload [root@client ~ 11:24:27]# systemctl enable sersyncd.serviceCreated symlink from /etc/systemd/system/multi-user.target.wants/sersyncd.service to /etc/systemd/system/sersyncd.service.​
http://www.xdnf.cn/news/1215721.html

相关文章:

  • Spark的宽窄依赖
  • 第七章:进入Redis的SET核心
  • 重生之我在暑假学习微服务第五天《Docker部署项目篇》
  • 【人工智能99问】混合专家模型(MoE)是如何训练的?(18/99)
  • pytorch小记(三十三):PyTorch 使用 TensorBoard 可视化训练过程(含完整示例)
  • LLM—— 基于 MCP 协议(SSE 模式)的工具调用实践
  • 30道JS高频经典笔试题集合+详解(一)
  • 华为昇腾×绿算全闪存缓存释放澎湃潜能
  • 【LeetCode】链表反转实现与测试
  • 比特币挖矿的能源消耗和环保问题
  • 关于“LoggerFactory is not a Logback LoggerContext but Logback is on ......“的解决方案
  • C++代码题部分(1)
  • LLM 模型部署难题的技术突破:从轻量化到分布式推理的全栈解决方案
  • AutoSAR(MCAL) --- ADC
  • Linux虚拟内存
  • 【C#】DevExpress.XtraEditors.MemoEdit memoEditLog控件讲解
  • AI服务器中,EEPROM有哪些部件使用,需要存储哪些信息?
  • Syzkaller实战教程2:运行环境配置+实例运行
  • 在Trae中使用MoonBit月兔
  • Android调用python库和方法的实现
  • 三十四、【Linux常用工具】rsync+inotify实时同步演示
  • GitHub使用小记——本地推送、外部拉取和分支重命名
  • Camera相机人脸识别系列专题分析之十九:MTK ISP6S平台FDNode传递三方FFD到APP流程解析
  • git本地仓库,工作区和暂存区的知识
  • llama factory本地部署常见问题
  • 用Python+MySQL实战解锁企业财务数据分析
  • 会吸的簸箕专利拆解:迷你真空组件的吸力控制与吸入口设计原理
  • Redis学习------缓存穿透
  • 数据建模怎么落地?从概念、逻辑到物理模型,一文讲请!
  • Prometheus-2--什么是Exporter是什么?