下面大体说下网站架构:
首先是普通的LNMP架构,然后在这个基础上做了MariaDB-Galera的跨机房双主,再然后做了文件系统的主备实时同步。
1、首先LNMP架构很好实现也很好部署,
2、Mariadb-Galera的多主实现可以看我之前的一篇博客 【
Linux之CentOS 6.7上编译+YUM两种方法配置MariaDB Galera多主集群实现HA
】
3、至于文件的实时同步我之前也有文章说过【
Linux之Rsync+Sersync实现负载均衡节点文件数据实时同步
】
4、最主要的是文件系统主备的自动切换,在这里我取巧实现了,我把两个节点都做了主,但是用iptables控制端口的方法实现了只会出现一个主节点的结果。
#!/bin/bash ######################################################################### # File Name: AutoSyncWebFile.sh # Author: LookBack # Email: admin#dwhd.org # Version: # Created Time: 2015年10月06日 星期二 14时46分38秒 ######################################################################### RsyncServerIP=( 167.114.230.243 158.69.87.84 ) if ! which dig >/dev/null 2>&1; then yum -y install bind-utils;fi rsyncConFile="/etc/rsyncd.conf" LocalIP=`curl -s ip.cn|grep -Eo '[0-9]{1,3}(\.[0-9]{1,3}){3}'` dnsIP=`dig @8.8.8.8 www.dwhd.org|awk '/^www/{print$NF}'` remoteIptables() { checkip=$1 for i in ${RsyncServerIP[@]}; do if ! ssh root@$checkip "iptables -t filter -L INPUT -nvx --line-numbers|grep "$i.*:873$"" >/dev/null 2>&1; then ssh root@$checkip "iptables -t filter -A INPUT -s $i -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT" fi done } delRemoteAuth() { for i in ${RsyncServerIP[@]}; do if [ "$i" != "$LocalIP" ]; then IptablesRuleLine=`iptables -t filter -L INPUT -nvx --line-numbers|grep "$i.*:873$"|awk '{print$1}'` [ -n "$IptablesRuleLine" ] && iptables -t filter -D INPUT $IptablesRuleLine remoteIptables $i fi done } startRsync() { if [ "$LocalIP" = "$dnsIP" ]; then delRemoteAuth if ! ps aux|pgrep sersync2 >/dev/null 2>&1; then /usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml fi fi } startRsync
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏