集群部署文件同步方案(三选一)

一、rsync+lsyncd文件同步

  1. 网站文件同步路径 web1:192.168.1.1  dir=/opt/www web2:192.168.1.2 dir=/opt/www
  2. rsync配置web1:
    log file = /data/rsync/logs/sync/rsyncd.log
    pid file = /data/rsync/logs/sync/rsyncd.pid
    lock file = /var/run/rsync.lock
    use chroot = yes
    [www]
    path = /opt/www
    hosts allow = 192.168.1.2
    uid = www
    gid = www
    read only = false
    

    web2:

    log file = /data/rsync/logs/sync/rsyncd.log
    pid file = /data/rsync/logs/sync/rrsyncd.pid
    lock file = /var/run/rsync.lock
    use chroot = yes
    [www]
    path = /opt/www
    hosts allow = 192.168.1.1
    uid = www
    gid = www
    read only = false
    
  3. lsync配置web1:
    settings = {
                    logfile = "/data/rsync/logs/sync/lsyncd.log",
                    statusFile = "/data/rsync/logs/sync/lsyncd.stat",
                   statusInterval =1,
            }
    sync{
                    default.rsync,
                    source="/data/www",
                    target="192.168.1.2::wwroot/",
                    excludeFrom = "/etc/lsyncd.exclude",
                    init=false,
            rsync     = {
                    binary = "/usr/bin/rsync",
                    archive = true,
                    compress = true,
                    verbose   = true
                    }
    }
            web2:
    settings = {
                    logfile = "/data/rsync/logs/sync/lsyncd.log",
                    statusFile = "/data/rsync/logs/sync/lsyncd.stat",
                    statusInterval =1,
            }
    sync{
                    default.rsync,
                    source="/data/www",
                    target="192.168.1.1::www/",
                    excludeFrom = "/etc/lsyncd.exclude",
                    init=false,
            rsync     = {
                    binary = "/usr/bin/rsync",
                    archive = true,
                    compress = true,
                    verbose   = true
                    }
    }
    
  4. 重启服务:
    $ service xinetd restart
    $ service lsyncd restart
    
  5. 测试:
    $ rsync -v rsync://192.168.1.1
    

二、nfs文件共享方案

  1. 安装nfs服务 并启用
    $ yum -y install nfs-utils rpcbind
    
  2. 配置开机启动
    $ chkconfig nfs on
    $ chkconfig rpcbind on
    
  3. 启动nfs
    $ service rpcbind start(先启动,再启动nfs,有依赖关系)
    $ service nfs start
    
  4. 配置nfs信息
    $ vim /etc/exports
    
  5. 写入除网站data以外的目录(注意配置,尽量写内网ip,如:192.168.1.1,不要写127.0.0.1,否则不要同步config目录) 注意:下例子是ERP的配置,不同版本系列可能目录不同,注意规避细节,501和502是www用户的gid和uid不同系统不同
    /opt/www/app           *(rw,sync,all_squash,anonuid=501,anongid=502)
    /opt/www/public        *(rw,sync,all_squash,anonuid=501,anongid=502)
    /opt/www/custom        *(rw,sync,all_squash,anonuid=501,anongid=502)
    /opt/www/upgrade       *(rw,sync,all_squash,anonuid=501,anongid=502)
    /opt/www/config        *(rw,sync,all_squash,anonuid=501,anongid=502)
    /opt/www/crontab       *(rw,sync,all_squash,anonuid=501,anongid=502)
    /opt/www/script        *(rw,sync,all_squash,anonuid=501,anongid=502)
    /opt/www/tools         *(rw,sync,all_squash,anonuid=501,anongid=502)
    
  6. 查看挂载NFS用另外一台机器(web2:192.168.1.2)查看挂载信息
    $ showmount -e 192.168.1.1
    

    如果能显示以上信息,说明NFS配置是没问题的

    复制web1的网站目录,

    $ tar -zcvf web.tar.gz /opt/www/web1(最好打包)
    
    $ scp web.tar.gz 192.168.1.2:/opt/www
    

    解压网站文件

    删除 以上目录里面的信息

    $ rm -rf /opt/www/app/* /opt/www/public/* /opt/www/custom/* /opt/www/upgrade/* /opt/www/config/* /opt/www/crontab/* /opt/www/script/* /opt/www/tools/* (删除操作,请仔细核对,不要复制粘贴,删除目录等同挂载目录,留下空文件夹)
    

    挂载远端nfs程序

    编辑/etc/fstab,设置开机自动挂载

    192.168.1.1:/opt/www/tools   /opt/www/tools nfs     defaults        0 0
    192.168.1.1:/opt/www/script  /opt/www/script nfs    defaults        0 0
    192.168.1.1:/opt/www/crontab /opt/www/crontab nfs   defaults        0 0
    192.168.1.1:/opt/www/config  /opt/www/config  nfs   defaults        0 0
    192.168.1.1:/opt/www/upgrade /opt/www/upgrade nfs   defaults        0 0
    192.168.1.1:/opt/www/custom  /opt/www/custom  nfs   defaults        0 0
    192.168.1.1:/opt/www/public  /opt/www/public  nfs   defaults        0 0
    192.168.1.1:/opt/www/app     /opt/www/app   nfs     defaults        0 0
    

    先进web文件夹看下是否有信息残留,没有的话,执行挂载mount -a(如果没报错,就说明成功了,有报错请baidu查找NFS官方文档进行配置)

    再次查阅app目录

    touch 个文件试试,如果正常写入,则表示成功

三、rsync同步方案(该方案需要网站后台锁定到其中一台服务器,适合2台以上集群)

所有web 都要配置如下:

  1. 设置如下
    $ yum -y install xinetd
    $ chkconfig xinetd on
    $ chkconfig rsync on
    $ /etc/init.d/xinetd start
    #查看是否开机启动
    $ chkconfig --list|grep rsync
    $ chkconfig --list|grep xinetd
     
    $ vim /etc/rsync.conf
    log file = /data/rsync/logs/sync/rsyncd/rsyncd.log(需要有相应目录)
    pid file = /data/rsync/logs/sync/rsyncd/rsyncd.pid
    lock file = /var/run/rsync.lock
    use chroot = yes
    [www]
    path = /opt/www
    hosts allow = 10.0.1.0/24(内网网段,可以只允许主服务器)
    comment = update
    ignore errors
    uid = www
    gid = www
    read only = false
    
  2. 重启服务
    $ /etc/init.d/xinetd restart
    
  3. 其他机器不需要网站目录程序,创建个/data目录,直接把整个网站推送过去
    $ rsync -vzrtopg --numeric-ids --delete --exclude=data/logs --exclude=data/cache --progress  /opt/www/public www@10.0.1.2::www
    $ rsync -vzrtopg --numeric-ids --delete --exclude=data/logs --exclude=data/cache --progress  /opt/www/public www@10.0.1.3::www
    

    如果需要保持数据一致,需要定时推送,推送服务器IP为10.0.0.1,公网IP:x.x.x.x 重新执行下该命令,估算下时间,然后创建计划任务,计划任务执行时间尽量大于执行的时间

  4. 登录后台操作的,配置hosts文件,域名为绑定激活的域名 windows下: C:\Windows\System32\drivers\etc\hosts x.x.x.x www.ceshi.com mac: sudo vim /etc/hosts x.x.x.x www.ceshi.com 该方案必须锁定!

15 条评论

https://teamlmsequitation.fr · 2026-08-29 07:17

References:

Best online shooter https://teamlmsequitation.fr

totobet · 2026-09-08 09:59

[8538]Totobet: Login Resmi Link Alternatif Situs Slot Gacor Terpercaya,Totobet menyediakan akses login resmi dan link alternatif terbaru. Nikmati kemudahan judi online deposit dana serta panduan main baccarat. Daftar dan main sekarang! visit: totobet

phokebet9 · 2026-09-22 01:01

Hey guys just wanted to share how much I love spending my free time here. The games run super smooth on my phone and withdrawals are always on point. I have been playing for a few months now and the customer support team really knows how to treat players right. Give it a shot you will not regret it. phokebet9

topsitenet.com · 2026-09-22 02:50

References:

Casino sofort ohne anmeldung topsitenet.com

mobile casino sofortüberweisung · 2026-09-22 04:39

References:

Top sofort casinos mobile casino sofortüberweisung

sofort casino handy · 2026-09-22 21:17

References:

Spielautomaten sofortüberweisung sofort casino handy

chuangu.xyz · 2026-09-23 05:33

References:

Wie funktioniert Sofortüberweisung im Casino chuangu.xyz

https://true-nissen-3.hubstack.net/ · 2026-09-23 09:17

References:

1 dollar deposit pokies payid https://true-nissen-3.hubstack.net/

http://alfa-power.de · 2026-09-23 09:31

References:

Sofortüberweisung casino auszahlung http://alfa-power.de

https://xbymw.com/ · 2026-09-23 10:37

References:

Sofort casino deutschland https://xbymw.com/

Sofort Casino Vergleich · 2026-09-23 10:58

References:

Casino ohne mindesteinzahlung sofortüberweisung Sofort Casino Vergleich

http://bbs.xingxiancn.com/ · 2026-09-23 11:21

References:

Casino Echtgeld Sofortüberweisung http://bbs.xingxiancn.com/

http://bbs.wj10001.com/ · 2026-09-23 17:01

References:

Casino sofortüberweisung http://bbs.wj10001.com/home.php?mod=space&uid=3178948

发表回复

Avatar placeholder

您的邮箱地址不会被公开。 必填项已用 * 标注