Friday 15 August 2014

Rsync module setup

Rsync 安装配置

安装
# yum list rsync   #检查check if exist
# yum install rsync   #installing by yum


服务端配置Server side configuration
  1. Motto Of The Day 文件
    #mkdir /etc/rsyncd      #to create folder to organise  创建文件夹方便组织
    # vi /etc/rsyncd/rsyncd.motd       #to create the motd file,like below:
    Welcome to RsyncServer xxxx
  2. 密码认证文件security  authentication file , the name is not fixed.
    # vi /etc/rsyncd/rsyncd.sec_xxx (文件名随意)
    user1:password1
    user2:password2
    # chmod 600 rsyncd.sec_xxx
  3. 编辑配置文件edit the configure file
    # vi rsyncd.conf  (example:)

  1. 启动start
    1. 独立模式 daemon mode
      #rsync --daemon
      # ps aux|grep rsync  或 # netstat -nlp | grep 873  检查是否启动
      # kill $(cat /var/run/rsyncd.pid)         关闭
    2. xinetd mode
      1. # yum list installed |grep xinetd    ##check if xinetd exist, if not , then install it
        #yum install xinetd
      2. 配置Configure rsync as xinetd based service
        # vi /etc/xinetd.d/rsync
           disable     = yes  改为 no
      3. 启动服务,检查端口
        # service xinetd restart
        # netstat -nlp | grep 873

        #chkconfig --list |grep xinetd   检查xinetd服务是否自启动,若无则
        #chkconfig xinetd on
        #service xinetd start/stop          启动、停止xinetd



客户端Client
  • rsync -avrPz --exclude-from=/    [username]@[rsync-server_ip]::[模块名]/[子路径]/   [Dest] --password-file=  | grep -v '/$'
note:保险期间,源和目的路径以/结尾


附1:cwRsync相关
windows平台上的为csRsync, 基本一样,注意的是win下路径中的盘符。如:

附2:参数说明
  • -a option to make an archive of the source.  Following items enumerate details of its equivalent -rlptgoD (no -H, -A, -X)

  1. -r : recurse into directories
  2. -l : copy symlinks as symlinks
  3. -p : preserve permissions
  4. -t : preserve modification times
  5. -g : preserve group
  6. -o : preserve owner
  7. -D : preserve device and special files
  8. no -H : does not preserve hard links
  9. no -A : does not preserve ACLs
 10. no -X : does not preserve extended attributes
  • -n,
    测试,--dry-run option to perform trial run with no changes
  • --delete
删除不存在而目的地存在的文件
  • exclude
    • 客户端脚本中:
      --exclude=PATTERN
      --exclude-from=FILE  从文档中读取排除文件
      排除文档中文件列表格式(一行一个文件或目录):
      - /aaa/bbb/**
      - /aaa/ccc/ff            这里的根/相对于模块中定义的路径,而非系统/目录
    • 服务端:
      exclude from =
  • --password-file=
    客户端脚本中密码文件指定


附3.参考脚本
  • 测试机从临时目录到正式目录同步
#cat test_sync_xxx.web_from_tmp.sh   (测试脚本)
/usr/bin/rsync -varltcn --delete --exclude-from=/bak/Sync/XXX/web.exclude /www_tmp/XXX/web/  /www/XXX/web/ |grep -v '/$'
/bin/echo -e "\n\n"
/bin/echo "Excluded Files:"
/bin/cat /bak/tongbu/【】/web.exclude |grep -E -i '(^-|^[a-z]|^[A-Z])'
/bin/echo -e "\n"

note:正式脚本命名去掉test即可,脚本中去掉-n参数

  • 运营服务器上从测试机同步
  • rsync.com example:
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsync.lock
use chroot=yes
max connections=10
motd file=/etc/rsyncd/rsyncd.motd
log file=/var/log/rsync.log
transfer logging=yes
timeout=300
uid=root
gid=root

[upload_w]
path=/web_tmp/xxx/
list=yes
read only=no
ignore errors
auth users=testup_w
secrets file=/etc/rsyncd/rsyncd.sec
#hosts allow=10.8.0.1/24,180.214.166.196/29
#hosts deny=*
#incoming chmod=u+rwx,go+rx
uid=
gid=

[deploy_r]
path=/web/xxx/
list=yes
read only=yes
ignore errors
auth users=testdep_r
secrets file=/etc/rsyncd/rsyncd.sec
#hosts allow=
#hosts deny=*
#outgoing chmod=u+rwx,go+rx
#uid=
#gid=

No comments:

Post a Comment