首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

施用rsync同步

2012-07-01 
使用rsync同步更新线上应用的时候,如果手动部署容易出错和遗漏,这里使用Linux自带的rsync功能,当应用在测

使用rsync同步

更新线上应用的时候,如果手动部署容易出错和遗漏,这里使用Linux自带的rsync功能,当应用在测试机测试ok,自动同步到正式机。这里我们把测试机称为Master,正式机称为Slave,应用从测试机同步到正式机,从Master同步到Slave。以下操作均在root账号下进行。

?

Master端配置:

1.vi /etc/rsyncd.conf

2.输入以下内容:

port = 873uid = rootgid = rootuse chroot = yesread only = yes#limit access to private LANshosts allow = YOURSmax connections =10pid file = /var/run/rsyncd.pidlog file = /var/log/rsyncd.logtimeout = 300[testlink]path = /tmp/rsyntestlist = yesauth users = rootuid = rootgid = rootexclude = *.xml *.properties *.logsecrets file = /etc/rsyncd.passread only = no

3.如果要排除某些文件可以在module节点下增加exclude = *.xml *.properties *.log 以空格分隔

4.mkdir -p /tmp/rsyntest

5.echo "this is test" > /tmp/rsyntest/test.test

6.echo "root:123456" > /etc/rsyncd.pass,这里root可以是其他Master的用户,但是必须是系统用户。

7.chmod 600 /etc/rsyncd.pass

8.启动rsync命令: rsync --daemon --config=/etc/rsyncd.conf;

?? 停止rsync命令:cat /var/run/rsyncd.pid | xargs kill -9 && rm -rf /var/run/rsyncd.pid。

?? 使用启动命令,启动Master的rsync服务。

9.记得在Master上对Slave机器开启iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 873 -s SlaveIPS -j ACCEPT

?

Slave端配置测试

1.echo "123456" > /etc/rsyncd.pass

2.chmod 600 /etc/rsyncd.pass

3.cd /tmp/rsyntest

4.注意Slave端的/etc/rsyncd.pass只有密码,没有用户名root!!!否则在指定pass文件运行时,rsync -vrtup --delete --password-file=/etc/rsyncd.pass root@masterIP::testlink /tmp/rsyntest,会报以下错误:

@ERROR: auth failed on module testlinkrsync error: error starting client-server protocol (code 5) at main.c(1527) [receiver=3.0.6]

?在Master端的日志文件/var/log/rsyncd.log,有以下报错内容:

2012/04/09 15:07:48 [28566] name lookup failed for slaveIP: Name or service not known2012/04/09 15:07:48 [28566] connect from UNKNOWN (slaveIP)2012/04/09 15:07:48 [28566] auth failed on module testlink from unknown (slaveIP): password mismatch

?

5.如果Slave端的/etc/rsyncd.pass和Master端一样,则只能按照以下不指定pass文件的方式运行:

rsync -vrtup --delete? root@masterIP::testlink /tmp/rsyntest? 提示输入密码,输入/etc/rsyncd.pass中配置的密码123456,会有以下输出:

receiving incremental file list./test.testsent 80 bytes  received 183 bytes  75.14 bytes/sectotal size is 30  speedup is 0.11

?

?

6.同步完毕在Master和Slave的对应目录分别执行? ls -alR|grep "^[-d]"|wc,看看文件夹和文件数是否一致。

?

rsyncd.conf的配置说明和rsync命令详解:

http://hi.baidu.com/xc_hai/blog/item/0ee61e8e321017f2503d9288.html

热点排行