xlid 发表于 2018-5-21 07:31:48

Linux rsync 数据备份

  rsync 是什么呢?

  下面是借百度的话,嘿嘿
  rsync,remote synchronize顾名思意就知道它 是一款实现远程同步功能的软件,它在同步文件的同时,可以保持原来文件的权限、时间、软硬链接等附加信息。rsync是用 “rsync 算法”提供了一 个客户机和远程文件服务器的文件同步的快速方法,而且可以通过ssh方式来传输文件,这样其保密性也非常好,另外它还是免费的软件。

rsync 包括如下的一些特性:
能更新整个目录和树和文件系统;
有选择性的保持符号链链、硬链接、文件属于、权限、设备以及时间等;
对于安装来说,无任何特殊权限要求;
对于多个文件来说,内部流水线减少文件等待的延时;
能用rsh、ssh 或直接端口做为传输入端口;
支持匿名rsync 同步文件,是理想的镜像工具;
  

  

  

  下面的安装方法我是以源码安装,个人比较偏向源码的方法安装一些个软件。
  

  
  

  

  

  1.安装gcc
  yum install gcc* -y
  

  2. 编译rsync
  ./configure --prefix=/usr/local/nginx
  make
  make install
  
  3.创建配置文件
  touch /etc/rsyncd.conf
  touch /etc/rsyncd.secrets
  chmod 600 /etc/rsyncd.secrets
  touch /etc/rsyncd.motd       --只是写一个同步的欢迎信息,可以不用。
  
  
  4.修改/etc/rsync.conf
  port = 873            --默认端口是873,随意修改。
  address = 10.10.10.11      --指定服务器IP
  uid = root            --默认传输的时候使用nobdoy,因为nobdoy有些权限不够的问题,所以我这里使用root了。
  gid = root
  use chroot = yes          --服务器传输时chroot到文件系统中
  read only = true          --不让客户端上传文件到服务器端上
  list = no
  transfer logging = true       --指定传输日志
  log format = %h %o %f %l %b   --日志格式
  log file = /var/log/rsyncd.log    --日志路径
  pid file = /var/run/rsyncd.pid    --pid路径
  hosts allow = 10.10.10.0/24      --允许同步的主机
  #slp refresh = 300
  timeout = 600             --超时时间
     max connections = 200          --最大连接数
  

  

  

                  --指定同步使用的模块
  path = /mnt/soft
  comment = This is soft data
  auth users = root            --指定认证的用户
  secrets file = /etc/rsyncd.secrets    --认证用户的密码文件
  ignore errors = yes            --忽略IO错误
  #exclude =            --可以指定同步的一个目录中,排出那个不同步
  
  
  5.修改/etc/rsyncd.secrets         --修改密码文件
  root:123456
  
  6.启动服务
  rsync --daemon 如果配置不在/etc 下 需要--config=PATH 来指定路径(--daemon已服务器模式启动)
  
  

  7.客户端rsync编译
  ./configure --prefix=/usr/local/rsync
  make
  make install
  8.客户端创建密码文件
  vim /etc/rsyncd.txt
  123456
  chmod 600 /etc/rsyncd.txt
  

  9.开始同步
  rsync -avzP --delete --password-file=/etc/rsyncd.txt root@10.10.10.11::soft /mnt/soft/
  
  
  10.客户端同步脚本
  mkdir /mnt/scripts
  vim sync_master.sh
  #!/bin/bash
  # every day sync 10.10.10.11 /mnt/soft for localhost /mnt/soft
  #
  /usr/local/rsync/bin/rsync -avzP --delete --password-file=/etc/rsyncd.txt root@10.10.10.11::soft /mnt/soft
  
  11.定时任务,每天同步一次
  crontab -e
  10 0 * * * /mnt/scripts/sync_master.sh&> /dev/null
  
  
页: [1]
查看完整版本: Linux rsync 数据备份