nginxs

运维博客

快速搭建rsync服务

2016/03/11 23:56 于 系统 1

微信 微博 豆瓣 人人

rsync 是一款用于远程同步或备份的工具。它包括server端和client端,client把文件通过指定验证方式连接到服务端。
rsync特点:可以压缩传输,限速传输,同步中定义文件的权限不变,rsync传输保留软连接,同步完成的文件都进行了完整校验不会重复传输同一个文件到同目录(文件名相同情况下)。



  1. 准备两个节点

    IP hostname
    192.168.81.128 server
    192.168.81.129 clent

  2. server配置

安装软件
[root@server ~]# yum -y install rsync
创建配置文件目录
[root@server ~]# mkdir /etc/rsyncd/
配置文件

[root@server ~]# cat /etc/rsyncd/rsyncd.conf 
secrets file = /etc/rsyncd/rsyncd.secrets
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
read only = no
list = yes
uid = root
gid = root
port = 873
use chroot = no
[data]
comment = nginxs rsync server
path = /opt/shell/
read only = no
auth users = datauser

密码文件

[root@server ~]# cat /etc/rsyncd/rsyncd.secrets 
datauser:nginxs.net
[root@server ~]# chmod 0600 /etc/rsyncd/rsyncd.secrets
[root@server ~]# /usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf


  1. . clent配置

    [root@client ~]# yum -y install rsync
    [root@client ~]# chmod 0600 /etc/rsyncd/pass.conf
    [root@client ~]# cat /etc/rsyncd/pass.conf
    ops.com
    [root@client ~]# rsync -avzp --password-file=/root/pass.conf /opt/shell/ datauser@192.168.81.128::data
    sending incremental file list
    ./
    README.txt

    sent 110 bytes received 36 bytes 97.33 bytes/sec
    total size is 26 speedup is 0.18

    --password-file=/root/pass.conf 指定密码文件
    /opt/shell/ 同步目录
    ops@192.168.81.128::ops 第一个ops用户,第两个ops为project,中间IP为服务IP

下面几个实用参数

--bwlimit=100              # rsync限速同步 限制I/O带宽,KBytes per second
-a, --archive #归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD
-z #压缩
-v #详细提示
-r, --recursive #对子目录以递归模式处理
-u #只进行更新,防止本地新文件被重写,注意两者机器的时钟的同时
-H, --hard-links #保留硬链结
-p, --perms #保持文件权限
-o, --owner #保持文件属主信息
-g, --group #保持文件属组信息
--password-file=FILE #从FILE中得到密码
--exclude=PATTERN #指定排除不需要传输的文件模式

微信扫描二维码了解更多 ->

[运维博客]
[运维博客](http://nginxs.blog.51cto.com/

rsyncrsync快速搭建文件同步服务rsync文件同步rsync限速同步

管理