加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

sersync+rsync实现数据同步

发布时间:2020-12-14 00:50:08 所属栏目:Linux 来源:网络整理
导读:实验拓扑 实验步骤 (1)配置rsync配置文件 编辑配置文件vim /etc/rsyncd.conf,默认是没有这个配置文件的,然后添加如下内容: Rsyncserver gid =rsync #设置运行权限为rsync用户 #默认是true,修改为no,增加对目录的文件软连接的备份 timeout =600 #设置超
  • 实验拓扑

  • 实验步骤
    (1)配置rsync配置文件
    编辑配置文件vim /etc/rsyncd.conf,默认是没有这个配置文件的,然后添加如下内容:

    Rsyncserver

    gid =rsync #设置运行权限为rsync用户
    #默认是true,修改为no,增加对目录的文件软连接的备份
    timeout =600 #设置超时的时间
    ignoreerrors
    list =false #不显示rsync服务端资源列表
    #进行数据同步的客户端IP地址,可以多个,用;隔开
    authusers = rsync_backup
    secretsfile = /etc/rsync.passwd
    [backup] #自定义备份 名称
    (2)创建使用的账号和配置密码,具体操作如下:
    [[email?protected]]# useradd rsync -s /sbin/nologin -M #和配置文件用户一致
    [[email?protected]]# id rsync
    uid=502(rsync)gid=502(rsync) 组=502(rsync)
    [[email?protected]]# vim /etc/rsync.passwd #和上面的配置文件名称一致
    rsync_backup:hjm ##用来同步数据的用户,格式为用户名:密码br/>[[email?protected]]#
    (3)创建共享目录(/backup),具体操作如下:
    [[email?protected]]# mkdir /backup #创建目录
    #对文件设置所属者
    [[email?protected]]# ll -d /backup/ #查看目录的属性br/>[[email?protected]]#
    (4)启动服务,如果出现failed to create pid file/var/run/rsyncd.pid: File exists这样的错误的话,可以用rm-f /var/run/rsyncd.pid命令把它删掉,在重新运行此命令。
    [[email?protected]]# netstat -tunlp | grep rsync
    tcp 0 0 0.0.0.0:873 0.0.0.0: LISTEN 7076/rsync
    tcp 0 0 :::873 :::
    LISTEN 7076/rsync

  • Sersync服务端配置
    (1)配置交换式密码,具体操作如下
    [[email?protected]]# vim /etc/rsync.password #设置交换式密码br/>hjm
    [[email?protected]]#
    (2)测试Sersync服务端,测试sersync是否可以进行pull或push操作,首先,我们先在Resync服务端的backup目录下新建几个文件夹,然后在sersync端看是否可以进行push或pull,如果可以的话,才能进sersync+resync的实战,具体操作如下:
    a) Resync服务端
    [[email?protected]~]# cd /backup/ #进入目录
    [[email?protected]]# touch {1..4}.txt
    [[email?protected]]# ls
    1.txt 2.txt 3.txt 4.txtbr/>[[email?protected]]#
    b) Sersync服务端
    [[email?protected]]# rsync -azv [email?protected]::backup/hjm/ --password-file=/etc/rsync.password
    receivingincremental file list
    ./
    1.txt
    2.txt
    3.txt
    4.txt
    sent 143bytes received 294 bytes 874.00 bytes/sec
    totalsize is 0 speedup is 0.00
    [[email?protected]]# ls
    1.txt 2.txt 3.txt 4.txt 5.txt hahhabr/>[[email?protected]]#
    (3)安装sersync软件
    Sersync软件包,在网上都能下载的到,我们这里事先已经下载好sersync软件包,然后对其进行解压,并把它们移动合适的位置。具体操作
    如下:
    [[email?protected]]# tar xvf sersync_64bit_binary_stable_final.tar.gz -C /usr/local/
    GNU-Linux-x86/sersync2
    [[email?protected]]# ll /usr/local/GNU-Linux-x86/
    -rwxr-xr-x.1 root root 2214 10月 26 2011 confxml.xmlbr/>[[email?protected]]#
    (4)编辑sersync配置文件
    编辑配置文件,vim /usr/local/GNU-Linux-x86/confxml.xml ,然后修改如下几个地方:


    (5)启动sersync服务
    set thesystem param
    execute:echo 50000000 >/proc/sys/fs/inotify/max_user_watches
    parse thecommand param
    daemonthread num: 10
    host ip :localhost host port: 8008
    daemonstart,sersyncrun behind the console
    user is rsync_backup
    configxml parse success
    pleaseaccording your cpu ,use-n param to adjust the cpu rate
    rsync thedirectory recursivly to the remote servers once
    -file=/etc/rsync.password>/dev/null 2>&1 run the sersync:
    [[email?protected]]#
  • 实验结果
    (1)Rsync服务端配置
    [[email?protected]]# lsbr/>[[email?protected]]#
    [[email?protected]]# lsbr/>[[email?protected]]#
    QQ在线Zabbix答疑群177428068
  • 上一篇:为什么Nginx总体性能要比Apache高?

    (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读