rsync配置

  • 目录


背景

项目组每个人需要从网上下载代码更新,效率低。mirror代码库文件数量很大,使用rsync可以保持文件时间属性,只同步更新的模块,搭建一台rsync服务器,每天定时同步代码,组员再与服务器同步mirror。

操作系统: ubuntu14.04
Rsync服务器:ubuntu14.04
Rsync客户端:ubuntu14.04

rsync简介

rsync,remote synchronize是一款实现远程同步功能的软件,它在同步文件的同时,可以保持原来文件的权限、时间、软硬链接等附加信息。 rsync是用 “rsync 算法”提供了一个客户机和远程文件服务器的文件同步的快速方法,来使本地和远程两个主机之间的文件达到同步,这个算法只传送两个文件的不同部分,而不是每次都整份传送,因此速度相当快。


rsync服务器配置

必要软件安装

$ sudo  apt-get  install  rsync  xinetd  ssh

默认情况下ubuntu是已经安装了rsync的,rsync服务默认是没有启动的,修改一下配置文件:

$ sudo vi /etc/default/rsync

RSYNC_ENABLE=true #false改为true

配置文件

rsync主要有以下三个配置文件:
rsyncd.conf(主配置文件)
rsyncd.secrets(密码文件)
rsyncd.motd(rysnc服务器信息)

  • rsyncd.conf(主配置文件)

该文件默认不存在,请创建它:

$ sudo vi /etc/rsyncd.conf
#/etc/rsyncd.conf 
# sample rsyncd.conf configuration file

# GLOBAL OPTIONS

# 指定欢迎消息文件
motd file=/etc/motd
# 指定lock文件
log file=/var/log/rsyncd
# for pid file, do not use /var/run/rsync.pid if
# you are going to run rsync out of the init.d script.
# The init.d script does its own pid file handling,
# so omit the "pid file" line completely in that case.
 pid file=/var/run/rsyncd.pid   
syslog facility=daemon
#socket options=

# MODULE OPTIONS
# 定义模块名
[mirror]
    comment = public archive
# 模块路径
    path = /home/mirror01/mirror
    use chroot = yes
#   max connections=10
    lock file = /var/lock/rsyncd
# the default for read only is yes...
    read only = yes
    list = yes
# rsync以什么用户身份启动
    uid = nobody
    gid = nogroup
#   exclude = 
#   exclude from = 
#   include =
#   include from =
# 认证的用户,服务器必须存在这个系统用户
    auth users = mirror01
    secrets file = /etc/rsyncd.secrets
    strict modes = yes
#   hosts allow =
#   hosts deny = 10.1.9.203
    ignore errors = no
    ignore nonreadable = yes
    transfer logging = no
#   log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.
    timeout = 3600
    refuse options = checksum dry-run
    dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz


# 另一个模块,过滤不想同步的文件放在ExcludeFile.txt,文件路径是/home/mirror01/mirror的相对路径.
[cut_mirror]
        comment = public archive
        path = /home/mirror01/mirror
        use chroot = yes
#       max connections=10
        lock file = /var/lock/rsyncd
# the default for read only is yes...
        read only = yes
        list = yes
        uid = nobody
        gid = nogroup
#       exclude = 
# ExcludeFile.txt文件路径是绝对路径,不同步的文件.
        exclude from = /home/mirror01/ExcludeFile.txt
#       include =
#       include from =
        auth users = mirror01
        secrets file = /etc/rsyncd.secrets
        strict modes = yes
#       hosts allow =
#       hosts deny = 10.1.9.203
        ignore errors = no
        ignore nonreadable = yes
        transfer logging = yes
        log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.
        timeout = 3600
        refuse options = checksum dry-run
        dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz
  • rsyncd.secrets(密码文件)
$ sudo vi /etc/rsyncd.secrets

服务器密码格式
hostname:password
例如服务器名为:zheng,输入以下内容并加权

zheng:123456

$ chmod 600  /etc/rsyncd.secrets
  • rsyncd.motd(rysnc服务器信息)
$ sudo vi /etc/rsyncd.motd

++++++++++++++++++++++++++
Welcome
Mirror about 300GB
Cut_mirror about 100GB
++++++++++++++++++++++++++

  • 启动rsync服务
$ sudo service rsync start

rsync客户端配置

$ sudo vi /etc/rsyncd.pwd

只输入服务器端设置的密码: 123456
然后把rsyncd.pwd加权

$ sudo chown user:user /etc/rsyncd.pwd
$ sudo chmod 600 /etc/rsyncd.pwd

客户端与服务器端同步命令

列出服务器可以同步的模块:
$ rsync  --list-only  mirror@192.168.1.1::

同步:
$ rsync -azv --delete --progress --password-file=rsyncd.secrets mirror@192.168.1.1::test   <your path>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值