Rsync 文件同步和数据传输软件配置

一、下载与安装rsync软件

    软件下载地址:http://rsync.samba.org

   #Tar zxvf rsync-3.X.X.tar.gz

   #Cd rsync-3.x.x

   #./configure

   #Make

   #Make install

二、Rsync的应用模式

   1.本地shell 模式:主要用于复制制动目录到另一个目录

     #rsync –av test  /test   #只复制test下的目录

     #rsync –av test/  /test  #复制test下的目目录和文件

     a 递归 v 输出详细模式信息

   2.远程shell 模式:复制本地目录到远程主机

     #rsync –av test 192.168.1.41:test

    Rsync列表模式:rsync与ls命令有相似的功能

     Rsync –a 192.168.1.41:test

  3.服务器模式:基于C/S模式的

三、应用实例:搭建远程容灾备份系统

  1.系统环境 Centos 5.5

  2.内核版本 2.6.18

  3.A系统IP地址:192.168.1.41

  4.B系统IP地址:192.168.1.42(远程备份机器)

  A服务器上配置

  在A服务器上配置rsync

  #vim /etc/rsyncd.conf
  Uid=root
  Gid=root
  [web]
  Path=/var/www/html/
  Auth users=backup
  Secrets file=/etc/server.pass
  其中在、etc/server.pass中配置如下:
  #more /etc/server.pass
  Backup:backup
  #chmod 600 /etc/server.pass
  在A服务器上启动rsync 守护进程
  #usr/local/bin/rsync –-daemon
  #ps –ef | grep rsync    -----查看进程

  B服务器上配置
  在/etc/server.pass中配置如下:
  #more /etc/server.pass
  Backup
  #chmod 600 /etc/server.pass
  在B服务器上配置rsync
#rsync -vzrtopg --delete –-progress [email protected]::web /var/www/html/ --password-file=/etc/server.pass


四、利用rsync+inotify搭建实时同步系统
系统环境 Centos 5.5
内核版本 2.6.18
A系统IP地址:192.168.1.41 (源数据服务器)
B系统IP地址:192.168.1.42 (实时同步备份服务器)
(一)实时同步备份服务器配置:192.168.1.42
1.配置rsyncd.conf
[web]
uid=root
gid=root
path=/var/www/html/
read only=no
hosts allow=192.168.1.0/24
auth users=backup
secrets file=/etc/server.pass

2. 配置rsync存放同步账号和密码文件:
#vim /etc/server.pass
Backup:pass

3. 启动rsync守护进程:
rsync --daemon

(二) 源服务器配置:192.168.1.41
1. 安装rsync: (仅安装即可,不需配置)
软件下载地址:http://rsync.samba.org
#Tar zxvf rsync-3.X.X.tar.gz
#Cd rsync-3.x.x
#./configure
#Make
#Make install
2. 安装inotify:
#tar zxvf inotify-tools-3.13.tar.gz
#cd inotify-tools-3.13
#./configure && make && make install
3. 配置rsync存放同步密码文件:
#vim /etc/server.pass
Pass
4. 配置inotify启动配置脚本:
#!/bin/bash
src=/var/www/html/
des=web
ip=192.168.1.42
user1=backup
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e modify,delete,create,attrib $src \
while read  file
        do
                rsync -vzrtopg --delete --progress --password-file=/etc/server.pass $src $user1@$ip::$des &&
                echo "${src} was rsynced"
                echo "---------------------------------------------------------------------------"
        done
5. 测试:

猜你喜欢

转载自leiyi-sz.iteye.com/blog/1840722