您的位置:首页 > 其它

使用rsync将本地文件更新到远程游…

2013-01-14 14:20 357 查看
rsync工具简介

rysnc是一个数据镜像及备份工具,具有可使本地和远程两台主机的文件,目录之间,快速同步镜像,远程数据备份等功能。在同步过程中,rsync是根据自己独特的算法,只同步有变化的文件,甚至在一个文件里只同步有变化的部分,所以可以实现快速的同步数据的功能。

更新rsync版本到最新:yum install
rsync
rpm -qa|grep -i rsync检查版本
参数说明:

-v, --verbose 详细模式输出
-z, --compress 对备份的文件在传输时进行压缩处理
-r, --recursive 对子目录以递归模式处理
-t, --times 保持文件时间信息
-p, --perms 保持文件权限
-o, --owner 保持文件属主信息
-g, --group 保持文件属组信息

服务器IP:192.168.1.253
游戏服平台:192.168.1.146

游戏服平台配置如下:

[root@localhost ~]# vim
/etc/rsyncd.conf


secrets file = /etc/rsyncd/.castlotpush_rsync.pwd

motd file = /etc/rsyncd/rsync.motd

read only = yes

list = yes

uid = root

gid = root

hosts allow = 192.168.1.253

hosts deny = 0.0.0.0/0

max connections = 2

log file = /var/log/rsyncd.log

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

[castlot_data]

comment = web folder

path = /data/castlot/client/

auth users = castlot_publish

read only =no

[root@localhost ~]# mkdir -p
/etc/rsyncd/

[root@localhost ~]# mkdir -p
/data/castlot/client/

[root@localhost ~]# vim
/etc/rsyncd/.castlotpush_rsync.pwd

castlot_publish:8QNXEDy2

[root@localhost ~]# chmod 600
/etc/rsyncd/.castlotpush_rsync.pwd
[root@localhost ~]#
ls -l
/etc/rsyncd/.castlotpush_rsync.pwd
-rw------- 1 root
root 25 02-17 17:24 /etc/rsyncd/.castlotpush_rsync.pwd

[root@localhost ~]# /usr/bin/rsync rsyncd --daemon
--config=/etc/rsyncd.conf

服务器配置如下:

[root@localhost ~]# mkdir -p
/etc/rsyncd/

[root@localhost ~]# vim
/etc/rsyncd/.castlotpush_rsync.pwd

8QNXEDy2

[root@localhost ~]# chmod 600
/etc/rsyncd/.castlotpush_rsync.pwd
[root@bogon client]#
rsync -vzrtopg --progress --delete-after
/data/castlot/client/ castlot_publish@192.168.1.146::castlot_data/
--password-file=/etc/rsyncd/.castlotpush_rsync.pwd

building file list ...

4 files to consider

./

anaconda-ks.cfg

1474 100%
0.00kB/s
0:00:00 (xfer#1, to-check=2/4)

install.log

48175 100%
11.49MB/s
0:00:00 (xfer#2, to-check=1/4)

install.log.syslog

5773 100%
805.39kB/s
0:00:00 (xfer#3, to-check=0/4)

sent 13763 bytes received 68
bytes 27662.00 bytes/sec

total size is 55422 speedup is 4.01

常见错误

用户密码错误

@ERROR: auth failed on module test

rsync error: error starting client-server protocol (code 5) at
main.c(1503) [receiver=3.0.6]

检查存储密码文件是否出错

文件权限错误

password file must not be other-accessible

continuing without password file

Password:

@ERROR: auth failed on module ***

rsync error: error starting client-server protocol (code 5) at
main.c(1503) [receiver=3.0.6]

检查存储密码文件的权限是否为600, -rw-------

rsync: failed to connect to X.X.X.X: No route to host (113)

rsync error: error in socket IO (code 10) at clientserver.c(107)
[sender=2.6.8]

  故障原因:对方没开机、防火墙阻挡、通过的网络上有防火墙阻挡,都有可能。

  解决方法:关闭防火墙,或者把防火墙的tcp udp 的873端口打开,允许rsync通过。

  实施方案:

  1、防火墙的启动与停止

  # service iptables start / stop

  2、允许rsync通过防火墙

  为防重启将规则清除,我将规则直接加到规则配置文件里边了(/etc/sysconfig/iptables),如下:

  -A INPUT -p tcp -s X.X.X.X --dport 873 -j
ACCEPT

  注意,这条规则要加在REJECT规则前。

  加好后,重启下 iptables(# service iptables restart)。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: