博客
关于我
rsync远程同步
阅读量:511 次
发布时间:2019-03-07

本文共 1711 字,大约阅读时间需要 5 分钟。

第十二章 rsync 远程同步

实验拓扑图

此处应插入实验拓扑图图片描述。图片展示了北京和深圳两台服务器的网络架构,采用VPN专用线路实现物理互联。

实验环境描述

某公司在深圳和北京各部署了一台网站服务器,分别负责南北大区内的客户访问。此两台服务器的网站文档需保持一致,且同步链路已通过VPN专用线路完成。

项目需求

  • 服务器A(北京):rsync发起端,传输源目录为 /var/www/html
  • 服务器B(深圳):rsync远程服务器,接收目录为 /var/www/html
  • 同时结合inotify机制,实现触发式的上传同步,确保两地站点的网页文档保持一致。

推荐操作步骤

  • 配置rsync服务器(深圳,服务器B)。
  • 在北京(服务器A)配置inotify机制,实现实时同步。
  • 实验步骤

    一、配置rsync服务器(深圳,服务器B)

  • 安装rsync:
    yum install rsync
  • 配置rsync文件:打开 /etc/rsyncd.conf,添加如下内容:
    [DEFAULT]log file /var/log/rsync.log
  • _fit,译&;能量条使用随机数secanonize 工作方式: Parallelsocket_options: SO_SNDTIMEO | SO_RCVTIMEOiction: losemax connections: 100

    保存后测试配置是否正确:

    rsync --version

    3. 配置rsync用户数据库:

    vim /etc/rsyncd_users.db

    添加一个用户并设置密码:

    user1:YourPasswordHere

    修改权限:

    chmod 600 /etc/rsyncd_users.db

    创建同步目录并设置权限:

    mkdir -p /var/www/htmlchown -R rsyncuser:rsyncgrp /var/www/html

    4. 启动rsync服务:

    rsync --daemon

    #### 二、基于inotify的实时同步(北京,服务器A)1.调整inotify内核参数:修改`/etc/sysctl.conf`,添加以下项:

    net.inotify.max_user_instances=100net.inotify.max_files=500

    应用参数:

    sysctl -p

    2.安装inotify-tools:

    tar zxvf /path/to/inotify-tools-3.x.x.tar.gz -C /optcd /opt/inotify-tools-3.x.x./configure && make && make install

    安装完成后,启动相关服务:

    systemctl start inotifydsystemctl enable inotifyd

    3. 编写同步脚本:

    vim /opt/inotify_rsync.sh

    脚本内容如下:

    #!/bin/bashsource /home/user/.bashrcrsync -avz --delete --update --timeout 30

    --excludeFromFile /etc/rsyncd_users.db
    rsync@192.168.100.20:/var/www/html/

    DOS 脚本示例(可根据实际需求调整):

    @echo offcall ssh root@192.168.100.20 /opt/inotify_rsync.sh

    4. 免交互式身份验证:- 生成SSH公钥对:  ```  ssh-keygen -t rsa  ```- 将公钥添加到服务器B:  ```  ssh-copy-id -i ~/.ssh/id_rsa root@192.168.100.20  ```5. 后台运行脚本:

    sh /opt/inotify_rsync.sh &

    ### 验证- 确认rsync服务是否运行:

    ss rsync:192.168.100.20

    - 检查是否有文件传输发生:

    tail -f /var/log/rsync.log

    转载地址:http://rfbnz.baihongyu.com/

    你可能感兴趣的文章
    nmon_x86_64_centos7工具如何使用
    查看>>
    NN&DL4.1 Deep L-layer neural network简介
    查看>>
    NN&DL4.3 Getting your matrix dimensions right
    查看>>
    NN&DL4.8 What does this have to do with the brain?
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    NO 157 去掉禅道访问地址中的zentao
    查看>>
    no available service ‘default‘ found, please make sure registry config corre seata
    查看>>
    no connection could be made because the target machine actively refused it.问题解决
    查看>>
    No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
    查看>>
    No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
    查看>>
    No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
    查看>>
    No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
    查看>>
    No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
    查看>>
    No module named 'crispy_forms'等使用pycharm开发
    查看>>
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>
    No resource identifier found for attribute 'srcCompat' in package的解决办法
    查看>>