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

Rsync实操

Rsync实操

一.rsync命令

 #类似于cp[root@user2 ~]# rsync info.sh root@192.168.168.130:/rootroot@192.168.168.130's password: [root@user1 ~]# lsanaconda-ks.cfg  ceph-release-1-1.el7.noarch.rpm  info.sh

二、使用rsync备份push方式

  • 服务器:server 192.168.168.130(需要进行数据备份的主机)

  • 客户端:client 192.168.168.131 (备份存储的主机)

 # 在客户端上编写rsync配置文件,创建一个存放备份的同步目录[root@targetpc ~]# vim /etc/rsyncd.conf[root@targetpc ~]# cat /etc/rsyncd.confport=873address = 192.168.168.131 #客户端地址uid = rootgid = rootuse chroot = yesmax connections = 4pid file = /var/run/rsyncd.pidlock file = /var/run/rsync.locklog file = /var/log/rsyncd.logmotd file = /etc/rsyncd.motd #可弄可不弄hosts allow = 192.168.168.0/24 #允许哪个网段传输数据[data] #网络名path = /data/backup #数据存储目录 真实名 需要创建comment = bakcup dataread only = falselist = yes#独立验证auth users = rsyncusersecrets file = /etc/rsync.passwd #自己创建​#设置独立账户密码[root@targetpc ~]# vim /etc/rsync.passwd#添加权限[root@targetpc ~]# chmod 600 /etc/rsync.passwd[root@targetpc ~]# vim /etc/rsync.passwd[root@targetpc ~]# cat /etc/rsync.passwdrsyncuser:123#设置标语[root@targetpc ~]# echo "来送数据了" > /etc/rsyncd.motd[root@targetpc ~]# systemctl restart rsyncd​#测试 服务器测试[root@sourcepc data]# ls1.txt  2.txt  3.txt  aaa[root@sourcepc data]# rsync -avz /data/* rsyncuser@192.168.168.131::data来送数据了​Password: sending incremental file list3.txt​sent 155 bytes  received 36 bytes  20.11 bytes/sectotal size is 0  speedup is 0.00#客户主机结果[root@targetpc backup]# ls1.txt  2.txt  3.txt  aaa
 ​

三、测试--delete命令push

 #--delete实验 不能与*同时用[root@targetpc backup]# ls1.txt  2.txt  3.txt  aaa  del.txt[root@sourcepc data]# ls1.txt  2.txt  3.txt  aaa​[root@sourcepc data]# rsync -avz --delete /data/* rsyncuser@192.168.168.131::data来送数据了​Password: sending incremental file list​sent 119 bytes  received 13 bytes  13.89 bytes/sectotal size is 0  speedup is 0.00[root@targetpc backup]# ls1.txt  2.txt  3.txt  aaa  del.txt#使用--delete时 去掉*[root@sourcepc data]# rsync -avz --delete /data/ rsyncuser@192.168.168.131::data来送数据了​Password: sending incremental file listdeleting del.txt./​sent 149 bytes  received 31 bytes  18.95 bytes/sectotal size is 0  speedup is 0.00[root@targetpc backup]# ls1.txt  2.txt  3.txt  aaa

四、免密同步

 
#免密[root@sourcepc data]# echo "123" > /etc/rsync.passwd[root@sourcepc data]# rsync -avz --delete /data/ rsyncuser@192.168.168.131::data --password-file=/etc/rsync.passwd #注意时--password 全称来送数据了​ERROR: password file must not be other-accessiblersync error: syntax or usage error (code 1) at authenticate.c(196) [sender=3.1.2]#设置权限[root@sourcepc data]# chmod 600 /etc/rsync.passwd[root@sourcepc data]# rsync -avz --delete /data/ rsyncuser@192.168.168.131::data --password-file=/etc/rsync.passwd来送数据了​sending incremental file list​sent 142 bytes  received 13 bytes  23.85 bytes/sectotal size is 0  speedup is 0.00

五、pull模式

以上的同步过程都是服务端主动推送数据给目标主机,这里演示下目标主机主动拉取数据进行同步

 
# 服务端上配置/etc/rsyncd.conf文件port=873address = 192.168.168.130uid = rootgid = rootuse chroot = yesmax connections = 4pid file = /var/run/rsyncd.pidlock file = /var/run/rsync.locklog file = /var/log/rsyncd.log#motd file = /etc/rsyncd.motdhosts allow = 192.168.168.0/24[data]path = /datacomment =  dataread only = falselist = yesauth users = rsyncusersecrets file = /etc/rsync.passwd# 认证文件[root@sourcepc log]# cat  /etc/rsync.passwdrsyncuser:123# 服务端上启动rsync[root@sourcepc log]# systemctl start rsyncd[root@sourcepc log]# systemctl status rsyncd● rsyncd.service - fast remote file copy program daemonLoaded: loaded (/usr/lib/systemd/system/rsyncd.service; disabled; vendor preset: disabled)Active: active (running) since 四 2025-06-19 20:35:23 CST; 2s agoMain PID: 2097 (rsync)CGroup: /system.slice/rsyncd.service└─2097 /usr/bin/rsync --daemon --no-detach​6月 19 20:35:23 sourcepc systemd[1]: Started fast remote file copy program daemon.# 目标主机上拉取数据[root@client data]# rsync -avz rsyncuser@192.168.168.130::data /dataPassword: receiving incremental file list./1.txt2.txt3.txtaaa12/bbb/ccc/​sent 100 bytes  received 305 bytes  162.00 bytes/sectotal size is 0  speedup is 0.00[root@client data]# ls1.txt  2.txt  3.txt  aaa12  backup  bbb  ccc

六、rsync+sersync 实现数据实时同步push

 #在需要备份主机处 安装sersync 使用的外部安装包#使用rz 调入安装包[root@sourcepc ~]# rz[root@sourcepc ~]# lsanaconda-ks.cfg                  info.shceph-release-1-1.el7.noarch.rpm  sersync2.5.4_64bit_binary_stable_final.tar.gz#解压[root@sourcepc ~]# tar -xf sersync2.5.4_64bit_binary_stable_final.tar.gz[root@sourcepc ~]# lsanaconda-ks.cfg                  GNU-Linux-x86  sersync2.5.4_64bit_binary_stable_final.tar.gzceph-release-1-1.el7.noarch.rpm  info.sh#进行配置[root@sourcepc ~]# cd GNU-Linux-x86/[root@sourcepc GNU-Linux-x86]# lsconfxml.xml  sersync2[root@sourcepc GNU-Linux-x86]# vim confxml.xml #修改的部分</filter><inotify><delete start="true"/><createFolder start="true"/><createFile start="true"/><closeWrite start="true"/><moveFrom start="true"/><moveTo start="true"/><attrib start="true"/><modify start="true"/></inotify>​<sersync><localpath watch="/data"><remote ip="192.168.168.131" name="data"/><!--<remote ip="192.168.8.39" name="tongbu"/>--><!--<remote ip="192.168.8.40" name="tongbu"/>--></localpath><rsync><commonParams params="-artuz"/><auth start="true" users="rsyncuser" passwordfile="/etc/rsync.passwd"/><userDefinedPort start="false" port="874"/><!-- port=874 --><timeout start="false" time="100"/><!-- timeout=100 --><ssh start="false"/></rsync>​#执行文件[root@sourcepc GNU-Linux-x86]# ./sersync2 -d -r -o ./confxml.xml set the system paramexecute:echo 50000000 > /proc/sys/fs/inotify/max_user_watchesexecute:echo 327679 > /proc/sys/fs/inotify/max_queued_eventsparse the command paramoption: -d      run as a daemonoption: -r      rsync all the local files to the remote servers before the sersync workoption: -o      config xml name:  ./confxml.xmldaemon thread num: 10parse xml config filehost ip : localhost     host port: 8008will ignore the inotify createFile event daemon start,sersync run behind the console use rsync password-file :user is rsyncuserpasswordfile is         /etc/rsync.passwdconfig 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 rate------------------------------------------rsync the directory recursivly to the remote servers onceworking please wait...execute command: cd /data && rsync -artuz -R --delete ./ rsyncuser@192.168.168.131::data --password-file=/etc/rsync.passwd >/dev/null 2>&1 [root@sourcepc GNU-Linux-x86]# run the sersync: watch path is: /data​#测试[root@sourcepc data]# ls1.txt  2.txt  3.txt  aaa[root@sourcepc data]# mkdir bbb​[root@targetpc backup]# ls1.txt  2.txt  3.txt  aaa  bbb​​[root@sourcepc data]# ls1.txt  2.txt  3.txt  aaa  bbb  ccc[root@sourcepc data]# mv aaa aaa12[root@targetpc backup]# ls1.txt  2.txt  3.txt  aaa12  bbb  ccc

相关文章:

  • 适配器模式:接口转换的神奇魔法[特殊字符],让不兼容的类和谐共处!
  • 锂电池保护板测试仪:守护电池安全的幕后保障
  • Transformer+CNN特征提取与跨注意力特征融合
  • 功能安全时钟切换:关键考量与实施策略
  • [Data Pipeline] Kafka消息 | Redis缓存 | Docker部署(Lambda架构)
  • jquery 赋值时不触发change事件解决——仙盟创梦IDE
  • 将多个Excel合并到一个Excel中的方法
  • 【嵌入式硬件实例】-555定时器控制舵机/伺服电机
  • MySQL 三大日志:Redo、Undo 与 Binlog 详解
  • Spring Boot 集成 Elasticsearch(含 ElasticsearchRestTemplate 示例)
  • 102页满分PPT | 汽车设备制造业企业信息化业务解决方案智能制造汽车黑灯工厂解决方案
  • [安卓/IOS按键精灵辅助工具]关于脚本中的统计记录功能
  • 黑盒测试(一)(包含源码)
  • WEB安全--WAF的绕过思路
  • React 轻量级状态管理器Zustand
  • YOLOv8改进:Neck篇——2024.1全新MFDS-DETR的HS-FPN特征融合层解析
  • 【Gin框架】中间件
  • 墨记APP:水墨风记事,书写生活诗意
  • 【AI Study】第四天,Pandas(10)- 实用技巧
  • 软件范式正在经历第三次革命
  • 做vi设计的国外网站/app广告投放价格表
  • 做网站郑州汉狮/国内重大新闻10条
  • 沈阳网站建设技术支持/seo排名工具给您好的建议下载官网
  • 门户网站是什么意思啊/百度seo关键词优化
  • 武威网站建设/网络营销学校
  • 找网络公司做网站需要注意/免费发布平台