zoukankan      html  css  js  c++  java
  • 配置rsync服务,数据同步。

    这部分设计服务器端和客户端。

    【服务器端】

    如果服务器没有安装rsync服务则使用yum安装rsync服务。

    yum install rsync 
    

    然后

    vim /etc/xinetd.d/rsync 
    
    将disable=yes改为no
    
    service rsync
    {
    disable = no
    socket_type = stream
    wait = no
    user = root
    server = /usr/bin/rsync
    server_args = --daemon
    log_on_failure += USERID
    }
    


    1配置rsync自动启动

    [root@test etc]# chkconfig rsync on
    [root@test etc]# chkconfig rsync --list
    rsync on
    

    3 配置rsyncd.conf ,默认的情况下rsyncd.conf是不存在的,所以需要我们在/etc下面创建该文件

    [root@test etc]# vim rsyncd.conf 
    
    uid = root
    gid = root
    use chroot = no
    max connections = 4
    strict modes = yes
    port = 873
    pid file = /var/run/rsyncd.pid
    lock file = /var/run/rsync.lock
    log file = /var/log/rsyncd.log
    
    [[mysipo_wiki]]
    path = /mnt/data/www/test
    comment = This is test
    auth users = wangjiafang
    uid = root
    gid = root
    secrets file = /opt/rsync.ps
    read only = no list = no


    4 确保etc/services中rsync端口号正确

    [root@test etc]# vim /etc/services
    rsync 873/tcp # rsync
    rsync 873/udp # rsync



    5 配置rsync密码(在上边的配置文件中已经写好路径)

    /opt/rsync.ps(名字随便写,只要和上边配置文件里的一致即可),格式(一行一个用户)

    [root@test etc]# vi /opt/rsync.ps 
    wangjiafang:wangjiafang


    6 配置rsync密码文件权限

    [root@test home]# chown root.root rsync.ps 
    [root@test home]# chmod 600 rsync.ps 



    7 启动配置

    [root@test home]# /etc/init.d/xinetd restart
    Stopping xinetd: [ OK ]
    Starting xinetd: [ OK ]



    8 如果xinetd没有的话,需要安装一下

    [root@test home]# yum -y install xinetd



    启动rsync server
    RSYNC服务端启动的两种方法


    9、启动rsync服务端(独立启动)

    [root@test home]# /usr/bin/rsync --daemon



    10、启动rsync服务端 (有xinetd超级进程启动)

    [root@test home]# /usr/bin/rsync --daemon


    11 加入rc.local
    在各种操作系统中,rc文件存放位置不尽相同,可以修改使系统启动时把rsync --daemon加载进去。

    [root@test home]# vi /etc/rc.local
    /usr/bin/rsync –daemon #加入一行



    12 检查rsync是否启动

    [root@test home]# lsof -i :873
    COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
    xinetd 4396 root 5u IPv4 633387 TCP *:rsync (LISTEN)

    【客户端】

    同样。客户端也需要安装rsync

    1、修改下rsync文件

    [root@aj1 home]# vim /etc/xinetd.d/rsync 
    
    # default: off
    # description: The rsync server is a good addition to an ftp server, as it 
    # allows crc checksumming etc.
    service rsync
    {
    disable = yes
    socket_type = stream
    wait = no
    user = root
    server = /usr/bin/rsync
    server_args = --daemon
    log_on_failure += USERID
    }



    2 配置密码文件 (注:为了安全,设定密码档案的属性为:600。rsync.ps的密码一定要和Rsync Server密码设定案里的密码一样)

    [root@aj1 opt]# vim rsync.ps 
    sciooo
    [root@aj1 opt]# chown root.root .rsync.ps # 注意必须给权限
    [root@aj1 opt]# chmod 600 .rsync.ps # 必须修改权限



    3、从服务器上下载文件

    [root@aj1 rsync-3.0.4]# rsync -avz --password-file=/opt/rsync.ps wangjiafang@10.168.0.20::mysipo_wiki  /home/



    4、从本地上传到服务器上去

    [root@aj1 rsync-3.0.4]# rsync -avz --password-file=/opt/rsync.ps /home wangjiafang@10.168.0.20::mysipo_wiki

     rsync的配置参数如下:

    Rsync 参数选项说明
    
    -v, --verbose 详细模式输出 
    -q, --quiet 精简输出模式 
    -c, --checksum 打开校验开关,强制对文件传输进行校验 
    -a, --archive 归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD 
    -r, --recursive 对子目录以递归模式处理 
    -R, --relative 使用相对路径信息
                   
    rsync foo/bar/foo.c remote:/tmp/
    
    Rsync 参数在/tmp目录下创建foo.c文件,而如果使用-R参数:
    
    rsync -R foo/bar/foo.c remote:/tmp/
    
    Rsync 参数会创建文件/tmp/foo/bar/foo.c,也就是会保持完全路径信息。
    
    -b, --backup 创建备份,也就是对于目的已经存在有同样的文件名时,将老的文件重新命名为~filename。可以使用--suffix选项来指定不同的备份文件前缀。 
    --backup-dir 将备份文件(如~filename)存放在在目录下。 
    -suffix=SUFFIX 定义备份文件前缀 
    -u, --update 仅仅进行更新,也就是跳过所有已经存在于DST,并且文件时间晚于要备份的文件。(不覆盖更新的文件) 
    -l, --links 保留软链结 
    -L, --copy-links 想对待常规文件一样处理软链结 
    --copy-unsafe-links 仅仅拷贝指向SRC路径目录树以外的链结 
    --safe-links 忽略指向SRC路径目录树以外的链结 
    -H, --hard-links 保留硬链结 
    -p, --perms 保持文件权限 
    -o, --owner 保持文件属主信息 
    -g, --group 保持文件属组信息 
    -D, --devices 保持设备文件信息 
    -t, --times 保持文件时间信息 
    -S, --sparse 对稀疏文件进行特殊处理以节省DST的空间 
    -n, --dry-run现实哪些文件将被传输 
    -W, --whole-file 拷贝文件,不进行增量检测 
    -x, --one-file-system 不要跨越文件系统边界 
    -B, --block-size=SIZE 检验算法使用的块尺寸,默认是700字节 
    -e, --rsh=COMMAND 指定替代rsh的shell程序 
    --rsync-path=PATH 指定远程服务器上的rsync命令所在路径信息 
    -C, --cvs-exclude 使用和CVS一样的方法自动忽略文件,用来排除那些不希望传输的文件 
    --existing 仅仅更新那些已经存在于DST的文件,而不备份那些新创建的文件 
    --delete 删除那些DST中SRC没有的文件 
    --delete-excluded 同样删除接收端那些被该选项指定排除的文件 
    --delete-after 传输结束以后再删除 
    --ignore-errors 及时出现IO错误也进行删除 
    --max-delete=NUM 最多删除NUM个文件 
    --partial 保留那些因故没有完全传输的文件,以是加快随后的再次传输 
    --force 强制删除目录,即使不为空 
    --numeric-ids 不将数字的用户和组ID匹配为用户名和组名 
    --timeout=TIME IP超时时间,单位为秒 
    -I, --ignore-times 不跳过那些有同样的时间和长度的文件 
    --size-only 当决定是否要备份文件时,仅仅察看文件大小而不考虑文件时间 
    --modify-window=NUM 决定文件是否时间相同时使用的时间戳窗口,默认为0 
    -T --temp-dir=DIR 在DIR中创建临时文件 
    --compare-dest=DIR 同样比较DIR中的文件来决定是否需要备份 
    -P 等同于 --partial 
    --progress 显示备份过程 
    -z, --compress 对备份的文件在传输时进行压缩处理 
    --exclude=PATTERN 指定排除不需要传输的文件模式 
    --include=PATTERN 指定不排除而需要传输的文件模式 
    --exclude-from=FILE 排除FILE中指定模式的文件 
    --include-from=FILE 不排除FILE指定模式匹配的文件 
    --version 打印版本信息 
    --address 绑定到特定的地址 
    --config=FILE 指定其他的配置文件,不使用默认的rsyncd.conf文件 
    --port=PORT 指定其他的rsync服务端口 
    --blocking-io 对远程shell使用阻塞IO 
    -stats 给出某些文件的传输状态 
    --progress 在传输时现实传输过程 
    --log-format=FORMAT 指定日志文件格式 
    --password-file=FILE 从FILE中得到密码 
    --bwlimit=KBPS 限制I/O带宽,KBytes per second 
    -h, --help 显示帮助信息


    /usr/bin/rsync -vrtopg --progress --password-file=/opt/sec.key  --exclude ".svn" /data/svn/searchbbs/bbs/chinaunix/bbs_x2/trunk/* rsync://rsyncuser@192.168.1
    .156/cubbs_x2
  • 相关阅读:
    Codeforces467C George and Job
    Codeforces205E Little Elephant and Furik and RubikLittle Elephant and Furik and Rubik
    Codeforce205C Little Elephant and Interval
    51nod1829 函数
    51nod1574 排列转换
    nowcoder35B 小AA的数列
    Codeforce893E Counting Arrays
    gym101612 Consonant Fencity
    CodeForces559C Gerald and Giant Chess
    CodeForces456D A Lot of Games
  • 原文地址:https://www.cnblogs.com/wangjiafang/p/3186190.html
Copyright © 2011-2022 走看看