现在的位置: 首页 > 综合 > 正文

RSYNC服务的部署与应用

2013年09月14日 ⁄ 综合 ⁄ 共 1649字 ⁄ 字号 评论关闭

最近拿到一个需求,想要从一台机器上定期下载数据,实现1对18的下载并在完成时关闭这些机器。

 

想想Linux里边好像有个rsync服务,从网上找到了不少资料,做了个CentOS 5.2 Linux->Windows自动同步的实现。

 

1.安装和配置rsync

 

参考了 am3nblog的博客。http://am3n.profusehost.net/index.php?print=70

 

  • Make sure xinetd and rsync is available, if not type
    # yum -y install rsync xinetd
  • Add xinetd service to system
    # chkconfig --add xinetd
  • Make sure xinetd running on init 3 and 5
    # chkconfig --list xinetd
  • Enable rsync
    # vi /etc/xinetd.d/rsync
    Change disable = yes into disable = no
  • Create username and password for rsync client to use
    # vi /etc/rsyncd.secrets
    sync-adminname:hispassword
  •  

    说明一下这里sync-adminname是rsync的用户名称,口令亦是rsync环境下的用户口令。

  • Create configuration and shares for rsync daemon
    # vi /etc/rsyncd.conf
    max connections = 30
    log file = /var/log/rsync.log
    timeout = 300

    [shares]
    comment = shared data stored here
    path = /home/sys-adminname/shares
    read only = false # chg to true if you want read only
    list = yes
    uid = sys-adminname
    gid = sys-adminname
    auth users = rsync-adminname
    secrets file = /etc/rsyncd.secrets
    hosts allow = 10.10.105.0/24

  •  

    说明一下这里的uid是可以访问path的用户的名称,gid同理前一说明。auth users则是rsync的用户名称。

  • Secure /etc/rsyncd.*
    # chown root.root /etc/rsyncd.*
    # chmod 600 /etc/rsyncd.*
  • Restart xinetd
    # service xinetd restart
  • Make sure rsync now running
    # chkconfig --list
  • Perhaps you also want to enable port 873 tcp and udp on your firewall so other can connect to your server
  •  

    2.安装和配置客户端

     

    据说有个cwRsync的软件,直接从网上下就好了,很多地方都有啊(相信我,你一定很容易找到)。把它安装进你的客户端windows环境。注意奥,为了使用方便在环境变量PATH里边增加你的rsync.exe所在的目录就可以了。

     

    先来给出同步的命令:

     

    C:/bak>rsync -vzrtopg --progress --delete --password-file=/cygdrive/c/rsyncd.secrets rsync-adminname@xxx.xxx.xxx.xxx::shares .

     

    为了不在提示中输入口令,在某个地方创建一个rsyncd.secrets,存放rsync-adminname的口令,例子中把该文件存放在了c:/下了,(怪怪的吧,cywin的目录好像都这样奥)。

     

    再给个Windows关机的指令:

     

    shutdown -s -f

     

    (如果你知道别人的口令,你可以关闭别人的机器奥,shutdown有说明奥)

     

    把上边两个指令做成个.bat,然后定时一下,正个任务就OK了。

     

     

     

     

    【上篇】
    【下篇】

    抱歉!评论已关闭.