web1:192.168.1.180 dir=/data/www/ecstore
web2:192.168.1.181 dir=/data/www/ecstore
######rsync+lsyncd文件同步 安装服务:lsyncd阿里云yum源epel有该服务,没有的话需要安装(yum -y install epel-release)
yum -y install rsync lsyncd xinetd
chkconfig rsync on
chkconfig lsyncd on
chkconfig xinetd on
1.rsync配置
web1:
log file = /data/logs/sync/rsyncd.log
pid file = /data/logs/sync/rsyncd.pid
lock file = /var/run/rsync.lock
use chroot = yes
[www]
path = /data/www/ecstore
hosts allow = 192.168.1.181
uid = www
gid = www
read only = false
web2:
log file = /data/logs/sync/rsyncd.log
pid file = /data/logs/sync/rrsyncd.pid
lock file = /var/run/rsync.lock
use chroot = yes
[www]
path = /data/www/ecstore
hosts allow = 192.168.1.180
uid = www
gid = www
read only = false
2.lsync配置
web1:
settings = {
logfile = "/data/logs/sync/lsyncd.log",
statusFile = "/data/logs/sync/lsyncd.stat",
statusInterval =1,
}
sync{
default.rsync,
source="/data/www/ecstore",
target="192.168.1.181::wwroot/",
excludeFrom = "/etc/lsyncd.exclude",
init=false,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
}
}
web2:
settings = {
logfile = "/data/logs/sync/lsyncd.log",
statusFile = "/data/logs/sync/lsyncd.stat",
statusInterval =1,
}
sync{
default.rsync,
source="/data/www/ecstore",
target="192.168.1.180::www/",
excludeFrom = "/etc/lsyncd.exclude",
init=false,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
}
}
重启服务:
service xinetd restart
service lsyncd restart
测试:
rsync -v rsync://192.168.1.180
######nfs文件共享方案 安装nfs服务并启用
yum -y install nfs-utils rpcbind
配置开机启动
chkconfig nfs on
chkconfig rpcbind on
启动nfs
service rpcbind start(先启动,再启动nfs,有依赖关系)
service nfs start
配置nfs信息
vim /etc/exports
写入除网站data以外的目录(注意配置,尽量写内网ip,如:192.168.1.180,不要写127.0.0.1,否则不要同步config目录)
注意:下例子是ERP的配置,不同版本系列可能目录不同,注意规避细节,501和502是www用户的gid和uid不同系统不同
/data/www/app 192.168.1.181(rw,sync,all_squash,anonuid=501,anongid=502)
/data/www/public 192.168.1.181(rw,sync,all_squash,anonuid=501,anongid=502)
/data/www/custom 192.168.1.181(rw,sync,all_squash,anonuid=501,anongid=502)
/data/www/upgrade 192.168.1.181(rw,sync,all_squash,anonuid=501,anongid=502)
/data/www/config 192.168.1.181(rw,sync,all_squash,anonuid=501,anongid=502)
/data/www/crontab 192.168.1.181(rw,sync,all_squash,anonuid=501,anongid=502)
/data/www/script 192.168.1.181(rw,sync,all_squash,anonuid=501,anongid=502)
/data/www/tools 192.168.1.181(rw,sync,all_squash,anonuid=501,anongid=502)
#这里也可以用*代替内网ip,但个人推荐使用内网ip
查看挂载NFS
#showmount -e 192.168.1.180
Export list for 192.168.1.180:
/data/httpd/www/ecstore/app/wap 192.168.1.181
/data/httpd/www/ecstore/i18n 192.168.1.181
/data/httpd/www/ecstore/themes 192.168.1.181
/data/httpd/www/ecstore/wap_themes 192.168.1.181
/data/httpd/www/ecstore/public 192.168.1.181
如果能显示以上信息,说明NFS配置是没问题的
复制web1的网站目录,scp到web2
tar -zcvf web.tar.gz /data/www/web1 && scp web.tar.gz 192.168.1.181:/data/www
进入web2服务器,解压网站文件,删除 以上目录里面的信息
rm -rf /data/www/app/* /data/www/public/* /data/www/custom/* /data/www/upgrade/* /data/www/config/* /data/www/crontab/* /data/www/script/* /data/www/tools/*
编辑/etc/fstab,设置开机自动挂载
192.168.1.180:/data/www/tools /data/www/tools nfs defaults 0 0
192.168.1.180:/data/www/script /data/www/script nfs defaults 0 0
192.168.1.180:/data/www/crontab /data/www/crontab nfs defaults 0 0
192.168.1.180:/data/www/config /data/www/config nfs defaults 0 0
192.168.1.180:/data/www/upgrade /data/www/upgrade nfs defaults 0 0
192.168.1.180:/data/www/custom /data/www/custom nfs defaults 0 0
192.168.1.180:/data/www/public /data/www/public nfs defaults 0 0
192.168.1.180:/data/www/app /data/www/app nfs defaults 0 0
先看文件夹下是否有信息残留,没有的话,执行挂载
mount -a
touch 个文件试试,如果正常写入,则表示成功
######rsync同步方案(该方案需要网站后台锁定到其中一台服务器,适合2台以上集群) 1.多台web 都要配置如下:
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/logs/sync/rsyncd/rsyncd.log(需要有相应目录)
pid file = /data/logs/sync/rsyncd/rsyncd.pid
lock file = /var/run/rsync.lock
use chroot = yes
[www]
path = /data/www/ecstore
hosts allow = 10.0.1.0/24(内网网段,可以只允许主服务器)
comment = update
ignore errors
uid = www
gid = www
read only = false
重启服务
/etc/init.d/xinetd restart
2.其他机器不需要网站目录程序,创建个/data目录,直接把整个网站推送过去
rsync -vzrtopg --numeric-ids --delete --exclude=data/logs --exclude=data/cache --progress /data/www/ecstore/public www@10.0.1.2::www
rsync -vzrtopg --numeric-ids --delete --exclude=data/logs --exclude=data/cache --progress /data/www/ecstore/public www@10.0.1.3::www
如果需要保持数据一致,需要定时推送,推送服务器IP为10.0.0.1,公网IP:x.x.x.x 重新执行下该命令,估算下时间,然后创建计划任务,计划任务执行时间尽量大于执行的时间
3.登录后台操作的,配置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
该方案必须锁定,必须执行第3步
注:文件同步之后,还需要kvstore,cache,以及数据库同步,config.php有相关配置
Sharp.CJ (2016-12-23 16:36:33) 沙发
最近在看鸟哥的书。准备花一两个月时间来熟悉下Linux