网站文件的同步

来源:互联网 发布:犀牛软件 手机建模 编辑:程序博客网 时间:2024/06/06 04:23

一个网站,除了有数据库,还有很多别的文件,比如用户上传的图片,你的网站代码之类,光有数据库而没有这些文件你的网站也没法跑起来。

和数据库比起来,网站文件要大得多,而且文件数目也多得多,要做到实时同步必须考虑“增量文件同步”,一般传统的方法是使用  inotify + rsync 写脚本来操作。

我们这里采用  Sersync (https://code.google.com/p/sersync/) 来做网站数据同步  。

 配置 Slave 上的 WWW 同步

采用 Rsync 做数据同步

启动 rsync 服务:  rsync –daemon

启动 Master 上的 Sersync2 做数据同步

<?xml version="1.0" encoding="ISO-8859-1"?><head version="2.5">    <host hostip="localhost" port="8008"></host>    <debug start="false"/>    <fileSystem xfs="false"/>    <filter start="true">    <exclude expression="^BZFSHOP/Asset/*"></exclude>    <exclude expression="^BZFSHOP/Runtime/*"></exclude>    <exclude expression="^BZFSHOP/Trash/*"></exclude>    <exclude expression="^BZFSHOP/Data/cache/*"></exclude>    <exclude expression="^BZFSHOP/Data/temp/*"></exclude>    </filter>    <inotify>    <delete start="true"/>    <createFolder start="true"/>    <createFile start="true"/>    <closeWrite start="true"/>    <moveFrom start="true"/>    <moveTo start="true"/>    <attrib start="false"/>    <modify start="false"/>    </inotify>     <sersync>    <localpath watch="/var/WWW">        <remote ip="Slave的IP" name="WWW"/>    </localpath>    <rsync>        <commonParams params="-artu"/>        <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>        <userDefinedPort start="false" port="874"/><!-- port=874 -->        <timeout start="false" time="100"/><!-- timeout=100 -->        <ssh start="false"/>    </rsync>    <failLog path="/tmp/www_rsync_fail_log.sh" timeToExecute="3"/><!--default every 3mins execute once-->    <crontab start="false" schedule="600"><!--600mins-->        <crontabfilter start="false">        <exclude expression="*.php"></exclude>        <exclude expression="info/*"></exclude>        </crontabfilter>    </crontab>    <plugin start="false" name="command"/>    </sersync> </head>


启动文件监控同步

后记

完整的对 数据库 和 所有文件 做了实时同步之后,我们的业务就有了保障。一旦主机房出现严重问题,我们可以使用备份数据立即继续中断的业务,最重要的是,业务数据几乎没有任何的丢失。

不像之前,每天一个备份,如果发生严重故障,只能从“昨天”开始了,中间数据丢失会带来巨大的麻烦。

如果需要更加安全,可以考虑 3 备份或者 N 备份,在 N 个城市同时做实时备份数据,一旦发生多点灾难一样可以迅速恢复业务,当然需要的成本也更高。

0 0
原创粉丝点击