目录

一、rsync部署

push推数据

1、编写rsync配置文件

2、备份测试

3、检验结果

二、rsync+sersync 实现数据实时同步

1、安装sersync服务

2、检验结果

pull拉取数据

1、编写rsync配置文件

2、检验结果

三、脚本编写

1、客户端脚本编写

2、服务器脚本编写


一、rsync部署

  • 服务器:source 192.168.58.130 (进行数据备份的主机)

  • 客户端:targetpc 192.168.58.131 (备份存储的主机)

push推数据

1、编写rsync配置文件

#192.168.58.131
# 在客户端上编写rsync配置文件,创建一个存放备份的同步目录
[root@targetpc ~]# vim /etc/rsyncd.conf 
# /etc/rsyncd: configuration file for rsync daemon mode
# See rsyncd.conf man page for more options.
# configuration example:
# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
# [ftp]
#        path = /home/ftp
#        comment = ftp export area
​
​
#在这些内容后面加上下面的内容
#加上
port=873
address = 192.168.58.131
uid = root
gid = root
use chroot = yes
max connections = 4
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
motd file = /etc/rsyncd.motd
hosts allow = 192.168.58.0/24
[data]
path = /data/backup
comment = bakcup data
read only = false
list = yes
auth users = rsyncuser
secrets file = /etc/rsync.passwd
#192.168.58.131
# 创建密码文件,格式   用户名:密码
# 设置密码文件权限为600或者700
[root@targetpc ~]# touch /etc/rsync.passwd
[root@targetpc ~]# vim /etc/rsync.passwd 
rsyncuser:123456
[root@targetpc ~]# chmod 600 /etc/rsync.passwd
#192.168.58.131
# 创建欢迎信息文件
[root@targetpc ~]# echo "Welcome to Backup Server" > /etc/rsyncd.motd
​
[root@targetpc ~]# systemctl start rsyncd
[root@targetpc ~]# mkdir -p /data/backup
[root@targetpc ~]# cd /data/backup

2、备份测试

#192.168.58.130
[root@source ~]# mkdir /data
[root@source ~]# cd /data
[root@source data]# touch 1.txt
[root@source data]# mkdir aaa
[root@source data]# rsync -avz /data/* rsyncuser@192.168.58.131::data
Welcome to Backup Server
​
Password: 
sending incremental file list
1.txt
aaa/
​
sent 124 bytes  received 43 bytes  9.03 bytes/sec
total size is 0  speedup is 0.00
[root@source data]# touch 2.txt
[root@source data]# ls
1.txt  2.txt  aaa
[root@source data]# rsync -avz /data/* rsyncuser@192.168.58.131::data
Welcome to Backup Server
​
Password: 
sending incremental file list
2.txt
​
sent 137 bytes  received 36 bytes  9.89 bytes/sec
total size is 0  speedup is 0.00

3、检验结果

#192.168.58.131
[root@targetpc backup]# ls
1.txt  2.txt  aaa
​
​
[root@targetpc backup]# touch 3.txt
[root@targetpc backup]# ls
1.txt  2.txt  3.txt  aaa

#192.168.58.130
[root@source data]# rsync -avz --delete /data/ rsyncuser@192.168.58.131::data
Welcome to Backup Server
​
Password: 
sending incremental file list
deleting 3.txt
​
sent 125 bytes  received 22 bytes  8.91 bytes/sec
total size is 0  speedup is 0.00

#192.168.58.131
[root@targetpc backup]# ls
1.txt  2.txt  aaa

非交互式:

如果想不输入密码,可以使用--password-file参数指定密码

#192.168.58.130
[root@source data]# vim /etc/rsync.passwd
123456
[root@source data]# chmod 600 /etc/rsync.passwd
[root@source data]#  rsync -avz --delete /data/ rsyncuser@192.168.58.131::data --password-file=/etc/rsync.passwd
Welcome to Backup Server
​
sending incremental file list
deleting data/aaa/
deleting data/2.txt
deleting data/1.txt
deleting data/
./
​
sent 132 bytes  received 70 bytes  13.93 bytes/sec
total size is 0  speedup is 0.00

#192.168.58.131
[root@targetpc backup]# ls
1.txt  2.txt  aaa

二、rsync+sersync 实现数据实时同步

1、安装sersync服务

#192.168.58.130
[root@source data]# cd
[root@source ~]# rz
rz waiting to receive.**[root@source ~]# ls
anaconda-ks.cfg  ceph-release-1-1.el7.noarch.rpm  init.sh  sersync2.5.4_64bit_binary_stable_final.tar.gz  shell
​
[root@source ~]# ls
anaconda-ks.cfg  ceph-release-1-1.el7.noarch.rpm  init.sh  sersync2.5.4_64bit_binary_stable_final.tar.gz  shell
[root@source ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz 
[root@source ~]# ls
anaconda-ks.cfg                  GNU-Linux-x86  sersync2.5.4_64bit_binary_stable_final.tar.gz
ceph-release-1-1.el7.noarch.rpm  init.sh        shell
[root@source ~]# cd GNU-Linux-x86/
[root@source GNU-Linux-x86]# ls
confxml.xml  sersync2
[root@source GNU-Linux-x86]# vim confxml.xml 
<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="/opt/tongbu"><remote ip="127.0.0.1" name="tongbu1"/><!--<remote ip="192.168.8.39" name="tongbu"/>--><!--<remote ip="192.168.8.40" name="tongbu"/>--></localpath><rsync><commonParams params="-artuz"/><auth start="false" users="root" passwordfile="/etc/rsync.pas"/><userDefinedPort start="false" port="874"/><!-- port=874 --><timeout start="false" time="100"/><!-- timeout=100 --><ssh start="false"/></rsync>
<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.58.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>
#192.168.58.130
# 开启sersync守护进程同步数据,即实时同步。
# -r参数,先做一次完全同步,再做差异同步。
[root@source GNU-Linux-x86]# ./sersync2 -d -r -o ./confxml.xml 
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -d      run as a daemon
option: -r      rsync all the local files to the remote servers before the sersync work
option: -o      config xml name:  ./confxml.xml
daemon thread num: 10
parse xml config file 
host ip : localhost     host port: 8008
will ignore the inotify createFile event 
daemon start,sersync run behind the console 
use rsync password-file :
user is rsyncuser
passwordfile is         /etc/rsync.passwd
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync 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 once
working please wait...
execute command: cd /data && rsync -artuz -R --delete ./ rsyncuser@192.168.58.131::data --password-file=/etc/rsync.passwd >/dev/null 2>&1
​
#或者
[root@source GNU-Linux-x86]# nohup ./sersync2 -r -o ./confxml.xml &
[1] 117240

2、检验结果

#192.168.58.130
#更改名称,查看变化
[root@source data]# mv aaa AAA
root@source data]# ls
1.txt  2.txt  AAA
#192.168.58.131
#检测到名称已变
[root@targetpc backup]# ls
1.txt  2.txt  AAA

pull拉取数据

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

1、编写rsync配置文件

#192.168.58.130
[root@source ~]# vim /etc/rsyncd.conf
#在这个文件里加入下面内容#
ort=873
address = 192.168.58.130
uid = root
gid = root
use chroot = yes
max connections = 4
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
motd file = /etc/rsyncd.motd
hosts allow = 192.168.58.0/24
[data]
path = /data
comment = master data
read only = false
list = yes
auth users = rsyncuser
secrets file = /etc/rsync.passwd
​
# 认证文件
[root@source ~]# vim /etc/rsync.passwd
rsyncuser:123456
# 服务端上启动rsync
[root@source ~]# systemctl start rsyncd
[root@source ~]# netstat -antup | grep 873
tcp        0      0 192.168.58.130:873      0.0.0.0:*               LISTEN      15646/rsync     
# 看到以上结果,说明服务端的rsync服务已经配置完成。
# 开放873端口号,允许通过873端口号拉取数据
[root@source ~]# cd /data
[root@source data]# mkdir BBB
[root@source data]# ls
1.txt  2.txt  AAA  BBB

2、检验结果

#192.168.58.131
# 目标主机上拉取数据
[root@targetpc backup]#  rsync -avz rsyncuser@192.168.58.130::data /data/backup/
​
Password: 
receiving incremental file list
./
BBB/
​
sent 32 bytes  received 145 bytes  9.57 bytes/sec
total size is 0  speedup is 0.00
[root@targetpc backup]# ls
1.txt  2.txt  AAA  BBB

三、脚本编写

计划将服务器的/data目录的文件实时发送到客户端/data/backup目录中,操作前请检查服务器是否有该目录

1、客户端脚本编写

#!/bin/bash
#客户端配置
#编写rsync配置文件
read -p "请输入符合此掩码的当前主机IP(默认掩码为255.255.255.0):" ip
ip1=$(echo $ip | awk -F. '{print $1"."$2"."$3}')
echo "
port=873
address = $ip
uid = root
gid = root
use chroot = yes
max connections = 4
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
motd file = /etc/rsyncd.motd
hosts allow = $ip1.0/24
[data]
path = /data/backup
comment = bakcup data
read only = false
list = yes
auth users = rsyncuser
secrets file = /etc/rsync.passwd
" > /etc/rsyncd.conf
touch /etc/rsync.passwd
echo "rsyncuser:123456" > /etc/rsync.passwd
chmod 600 /etc/rsync.passwd
echo "Welcome to Backup Server" > /etc/rsyncd.motd
systemctl restart rsyncd
mkdir -p /data/backup

2、服务器脚本编写

#!/bin/bash
#服务端配置
read -p "请输入符合此掩码的客户端主机IP(默认掩码为255.255.255.0):" ip
echo "123456" > /etc/rsync.passwd
chmod 600 /etc/rsync.passwd
rsync -avz --delete /data/ rsyncuser@$ip::data --password-file=/etc/rsync.passwd

看到感觉有帮助的朋友,劳烦动动发财的小手给博主点个赞

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/diannao/87509.shtml
繁体地址,请注明出处:http://hk.pswp.cn/diannao/87509.shtml
英文地址,请注明出处:http://en.pswp.cn/diannao/87509.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

用 python 开发一个可调用工具的 AI Agent,实现电脑配置专业评价

在人工智能时代&#xff0c;AI Agent凭借其强大的任务处理能力&#xff0c;逐渐成为开发人员手中的得力工具。今天&#xff0c;我们就来一起动手&#xff0c;用Python打造一个能够调用工具的AI Agent&#xff0c;实现根据电脑信息对电脑配置进行专业评价的功能。 一、项目创建…

WSL 安装使用和常用命令

参考官方使用说明&#xff1a; https://learn.microsoft.com/zh-cn/windows/wsl/ 安装wsl: wsl --install --no-distribution --no-distribution&#xff1a;安装 WSL 时不要安装分发版 更新 wsl: wsl --update 设置wsl 默认版本&#xff1a; wsl --set-default-version <…

720全景VR拍摄制作实战教程

720全景VR拍摄制作实战教程 720全景VR拍摄制作是近年来兴起的一种沉浸式影像制作技术。它通过多角度拍摄&#xff0c;并将画面拼接成一个全景视角&#xff0c;使观众获得身临其境的观看体验。本教程将带你从准备阶段到拍摄阶段&#xff0c;再到后期处理阶段&#xff0c;一步步…

什么真正的云原生开发?如何区别本地开发后部署到云端?

以下是关于云原生开发的深度解析&#xff0c;以及与本地开发后迁移上云的本质区别&#xff1a; 一、真正的云原生开发&#xff1a;从理念到实践的全面革新 1. 定义与核心思想 云原生开发是一种以云计算能力为核心的架构设计和开发方法论&#xff0c;其本质是让应用从诞生之初…

从代码学习深度学习 - 词的相似性和类比任务 PyTorch版

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言加载预训练词向量TokenEmbedding 类详解预训练词向量简介 (GloVe)具体含义总结建议应用预训练词向量词相似度knn 函数get_similar_tokens 函数相似词查找示例词类比get_analogy 函数词类比任务…

ubuntu 22.04 安装部署elk(elasticsearch/logstash/kibana) 7.10.0详细教程

安装部署elk7.10.0详细教程 一、安装jdk 11环境二、安装elasticsearch 7.10.0三、安装kibana 7.10.0四、安装logstash 7.10.0五、安装ik7.10.0分词六、开启安全功能1. 开启用户名密码登录2. 开启es安全加密通信3. 开启Kibana安全功能 七、注意事项和常见错误八、其它操作及命令…

技术文章: 基板的吸水率

PCB基板或覆铜板的吸水率是一个重要的性能指标&#xff0c;它衡量了覆铜板在特定条件下&#xff08;通常是浸水后&#xff09;吸收水分的能力&#xff0c;通常用指定条件下吸水后与吸水前相比&#xff0c;质量增加的百分比来表示。当材料暴露扎起在潮湿空气中或浸没在水中时其抵…

九日集训第三天

目录 搜索旋转排序数组 搜索旋转排序数组|| 寻找旋转排序中的数组最小值 爬楼梯 斐波那契数 第N个泰波那契数 差的绝对值为K的数对数目 猜数字 拿硬币 山峰数组的峰顶索引 搜索旋转排序数组 class Solution { public:int search(vector<int>& nums, int t…

CppCon 2017 学习:folly::Function A Non-copyable Alternative to std::function

你说的内容是关于 C 中 可调用类型&#xff08;Callable Types&#xff09; 的基础知识&#xff0c;我帮你理清并补充理解。 Callable Types&#xff08;可调用类型&#xff09;简介 C 中任何可以用 () 括号操作符“调用”的对象&#xff0c;都叫做 可调用类型。典型包括&…

PyTorch 中Tensor常用数据结构(int, list, numpy array等)互相转换和实战示例

在 PyTorch 中&#xff0c;tensor 是一种强大且灵活的数据结构&#xff0c;可以与多种 Python 常用数据结构&#xff08;如 int, list, numpy array 等&#xff09;互相转换。下面是详细解释和代码示例&#xff1a; 1. Tensor ↔ int / float 转为 int / float&#xff08;前提…

计算机网络与数据通信基础

第一章 计算机网络概述 1. 计算机网络的核心概念 1.1 定义 将 地理分散 的、具有 独立处理能力 的计算机系统&#xff08;主机/Host&#xff09;&#xff0c;通过 传输介质 与 网络设备 互连&#xff0c;在 网络协议 和 软件 支持下实现 资源共享 与 数据通信 的系统。 关键术…

【统计术语】

文章目录 基础概念术语基期与现期增长量与增长率环比与同比 比重术语平均数术语特殊增长术语其他常用术语 基础概念术语 基期与现期 基期&#xff1a;作为基础参照的时期&#xff0c;一般指过去的时间 现期&#xff1a;与基期对比的时期&#xff0c;一般指现在的时间 示例&am…

XXE(XML外部实体注入)详解

目录 一、XXE漏洞简介 二、XML详解 (一) XML文档结构 1. 文档声明 2. XML文档类型定义&#xff08;DTD&#xff09; 3. XML文档元素 4. XML文档示例 三、XXE漏洞类型 四、XXE漏洞挖掘技巧 五、XXE漏洞危害 (一) 文件读取 (二) 内网探测 1. 端口探测 2. 主机存活探…

深入解析JVM字节码执行引擎

JVM 字节码执行引擎。它是 JVM 核心组件之一&#xff0c;负责实际执行加载到内存中的字节码指令。你可以将它想象成 JVM 的“CPU”。 核心职责&#xff1a; 加载待执行的字节码&#xff1a; 从方法区&#xff08;元空间&#xff09;获取已加载类的方法字节码。创建和管理栈帧…

华为OD机试-MELON的难题-DFS(JAVA 2025A卷)

题意是从N快雨花石中找出最少拿出雨花石的块数&#xff0c;使得雨花石可以均分&#xff0c;直接使用dfs解决此类组合问题 package com.example.demo.bean;import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner;public class YuHuaStone {public s…

鸿蒙数据库操作

一、使用关系型数据库实现数据持久化&#xff0c;需要获取一个RdbStore&#xff0c;其中包括建库、建表、升降级等操作。 const STORE_CONFIG: relationalStore.StoreConfig {name: AnyOffice.db, // 数据库文件名securityLevel: relationalStore.SecurityLevel.S1, // 数据库…

基于ARM SoC的半导体测试

ARM SoC&#xff08;System on Chip&#xff09; 是一种集成了多个关键计算组件的单片系统芯片&#xff0c;广泛应用于移动设备、嵌入式系统、物联网&#xff08;IoT&#xff09;和半导体测试设备等领域。它的核心设计理念是“高度集成”&#xff0c;将处理器、内存、外设接口等…

JavaEE->多线程2

目录 一、线程安全&#xff08;重点&#xff09; 1.线程安全演示 2.线程不安全的原因 1.线程是抢占式执行的&#xff08;执行顺序是随机的&#xff09; 2.多个线程同时修改了同一个变量 3.原子性 4.内存可见性 5.指令重排序&#xff08;有序性&#xff09; 二、解决线…

Flutter TCP通信

启动TCP服务 Future<void> startServer() async {final server await ServerSocket.bind(InternetAddress.anyIPv4, 12345);print(Server listening on ${server.address}:${server.port});server.listen((Socket socket) {print(Client connected: ${socket.remoteAddr…

flask拆分计划

两个启动链接&#xff0c;看日志提示是因为2次启动&#xff0c;一次是database&#xff0c;一次是xmind2&#xff0c;去掉一次就可以&#xff0c;如何去掉一次&#xff1f; 这里启动也调用了一次&#xff0c;所以测试环境注释掉&#xff0c;如下图&#xff0c;也就调用了一次