LAMP的负载均衡和DNS的主从负载

前端两台DNS做主从复制及两台apache做负载均衡,实现LAMP的一台NFS+MySQL负载均衡访问,安装discuz软件。

httpd-2.4.10.tar.bz2
openlogic-mysql-5.6.10-linux-ia32-bin-glibc2.5-1.zip
php-5.4.13.tar.bz2
Discuz_X3.2_SC_UTF8.zip

主机A IP:192.168.100.100 搭建DNS服务器
主机B IP:192.168.100.101 搭建DNS服务器
主机C IP:192.168.100.102 安装apache和php
主机D IP:192.168.100.103 安装apache和php
主机E IP:192.168.100.104NFS服务器,MySQL服务器
域名:XUANZI.COM

实施规划:
主机E搭建的NFS服务器共享/shared目录,主机C和主机D将主机A共享的/shared目录挂载至本地的/www/xuanzi目录,当做Apache的DocumenRoot。当通过主机C的IP和主机D的IP以及其域名来访问页面时,页面内容要求一样。
在搭建DNS服务器时,主机名www.xuanzi.com有两个A记录,分别指向主机C的IP和主机D的IP。这样在浏览器输入www.xuanzi.com访问页面时,轮流解析到主机C和主机D的IP,这样便能达到负载均衡的效果。

主机A
1,DNS搭建
# yum -y install bind bind-utils

配置/etc/named.conf 文件


//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

options {
//      listen-on port 53 { 127.0.0.1; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { any; };
        recursion yes;

//      dnssec-enable yes;
//      dnssec-validation yes;

        /* Path to ISC DLV key */
//      bindkeys-file "/etc/named.iscdlv.key";

//      managed-keys-directory "/var/named/dynamic";
};

logging {
        channel default_debug {
                file "data/named.run";
"/etc/named.conf" 43L, 988C                                        26,1          Top

"/etc/named.rfc1912.zones"


        allow-update { none; };
};

zone "localhost" IN {
        type master;
        file "named.localhost";
        allow-update { none; };
};

zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
        type master;
        file "named.loopback";
        allow-update { none; };
};

zone "1.0.0.127.in-addr.arpa" IN {
        type master;
        file "named.loopback";
        allow-update { none; };
};

zone "0.in-addr.arpa" IN {
        type master;
        file "named.empty";
        allow-update { none; };
};
zone "xuanzi.com" IN {
        type master;
        file "xuanzi.com.zone";
};
zone "100.168.192.in-addr.arpa" IN {
"/etc/named.rfc1912.zones" 49L, 1075C                 

   

区域文件

$TTL 86400
$ORIGIN xuanzi.com.
@       IN      SOA     ns1.xuanzi.com. admin.xuanzi.com (
                        2017081402
                        1H
                        5M
                        7D
                        1D )
        IN      NS      ns1
        IN      NS      ns2
        IN      MX 10   mx1
ns1     IN      A       192.168.100.100
ns2     IN      A       192.168.100.101
mx1     IN      A       192.168.100.106
www     IN      A       192.168.100.102
www     IN      A       192.168.100.103

pop3    IN      CNAME   mx1
                                                  

从DNS服务器配置
"/etc/named.root.key"

//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

options {
//      listen-on port 53 { 127.0.0.1; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { any; };
        recursion yes;

//      dnssec-enable yes;
//      dnssec-validation yes;

        /* Path to ISC DLV key */
//      bindkeys-file "/etc/named.iscdlv.key";

//      managed-keys-directory "/var/named/dynamic";
};

logging {
        channel default_debug {
                file "data/named.run";
"/etc/named.conf" 43L, 988C                                        26,1          Top

反向区域文件


$TTL 86400
$ORIGIN 100.168.192.in-addr.arpa.
@       IN      SOA     ns1.xuanzi.com. admin.xuanzi.com (
                        2017081402
                        1H
                        5M
                        7D
                        1D )
        IN      NS      ns1.xuanzi.com.
        IN      NS      ns2.xuanzi.com.
100     IN      PTR     ns1.xuanzi.com.
101     IN      PTR     ns2.xuanzi.com.
102     IN      PTR     www.xuanzi.com.
103     IN      PTR     www.xuanzi.com.
106     IN      PTR     mx1.xuanzi.com.
imap    IN      PTR     imap.xuanzi.com.

配置/etc/named.rfc1912.zones文件


        file "named.localhost";
        allow-update { none; };
};

zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
        type master;
        file "named.loopback";
        allow-update { none; };
};

zone "1.0.0.127.in-addr.arpa" IN {
        type master;
        file "named.loopback";
        allow-update { none; };
};

zone "0.in-addr.arpa" IN {
        type master;
        file "named.empty";
        allow-update { none; };
};
zone "xuanzi.com" IN {
        type slave;
        masters { 192.168.100.100; };
        file "slaves/xuanzi.com.zone";
};
zone "100.168.192.in-addr.arpa" IN {
        type slave;
        masters { 192.168.100.100; };
        file "slaves/192.168.100.zone";
};
"/etc/named.rfc1912.zones" 51L, 1149C                              51,1          Bot

2,MySQL搭建
yum install mysql-server

# mysql
mysql> UPDATE user SET password=PASSWORD('xuanzi') WHERE USER='xuanzi';
mysql> GRANT ALL PRIVILEGES ON *.* TO root@'192.168.100.%' IDENTIFIED BY 'xuanzi';
mysql> FLUSH PRIVILEGES;

3,NFS配置

# mkdir /shared
# groupadd -g 500 xuanzi
# useradd -g 500 -u 500 xuanzi
# vim /etc/exportfs
    /shared 192.168.100.0/24(rw,all_squash,anonuid=500,anongid=500)
# setfacl -m u:xuanzi:rwx /shared

主机C
主机C挂载NFS共享的/shared目录,执行以下命令:

# mkdir /www/xuanzi
# mount -t nfs 192.168.1.2:/shared  /www/xuanzi

安装Apache
安装apr

    # cd /usr/local
    # tar xf apr-1.5.1.tar.bz2
    # cd apr-1.5.1
    # ./configure --prefix=/usr/local/apr
    # make
    # make install

安装apr-util

 # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
    # make 
    # make install

安装httpd

# tar xf httpd-2.4.10.tar.bz2     
 # cd httpd-2.4.10   
 # ./configure 
        --prefix=/usr/local/apache 
        --sysconfdir=/etc/httpd 
        --enable-so 
        --enable-rewrite 
        --enable-ssl     
        --enable-cgi 
        --enable-cgid 
        --enable-modules=most
        --enable-mods-shared=most 
        --enable-mpms-shared=all 
        --with-mpm=event 
        --with-apr=/usr/local/apr 
        --with-apr-util=/usr/local/apr-util
出现错误:
configure: error: pcre-config for libpcre not found. PCRE is required anavailabl from 
解决办法
# yum install -y pcre-devel    
# make    
# make install

提供SysV风格的启动脚本:/etc/init.d/httpd

#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#       HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=$?
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
    fi
    echo
}
# See how we were called.
case "$1" in
  start)
start
;;
  stop)
stop
;;
  status)
        status -p ${pidfile} $httpd
RETVAL=$?
;;
  restart)
stop
start
;;
  condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
  reload)
        reload
;;
  graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
  *)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL

chmod +x /etc/init.d/httpd

chkconfig --add httpd

编辑/etc/profile.d/httpd.sh   

1

PATH=$PATH:
/usr/local/apache/bin

# source /etc/profile.d/httpd.sh
#  service httpd start

安装php

# cd php-5.4.13
    # ./configure 
        --prefix=/usr/local/php 
        --with-mysql=mysqlnd
        --with-mysqli=mysqlnd
        --with-pdo-mysql=mysqlnd
        --with-openssl
        --enable-mbstring 
        --with-freetype-dir 
        --with-jpeg-dir 
        --with-png-dir 
        --with-zlib 
        --with-libxml-dir=/usr 
        --enable-xml 
        --enable-sockets 
        --with-apxs2=/usr/local/apache/bin/apxs 
        --with-mcrypt --with-config-file-path=/etc 
        --with-config-file-scan-dir=/etc/php.d 
        --with-bz2 --enable-maintainer-zts
    出现错误:
    configure: error: mcrypt.h not found. Please reinstall libmcrypt.
    解决办法:
        #yum -y install libmcrypt-devel mhash-devel
    # make
    # make install

提供php配置文件
cp php.ini-production /etc/php.ini

/etc/httpd/httpd.conf配置文件

AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    DirectoryIndex index.php index.html
    注释掉
    #/DocumentRoot "/usr/local/apache/htdocs"
    取消注释
    Include /etc/httpd/extra/httpd-vhosts.conf

主机C和主机D /etc/httpd/extra/httpd-vhosts.conf配置

<VirtualHost *:80>
    DocumentRoot "/www/xuanzi"
    <Directory "/www/xuanzi">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
    ServerName www.xuanzi.com
    ErrorLog "/var/log/httpd/xuanzi.com_error.log"
    CustomLog "/var/log/httpd/xuanzi.com_access.log" combined
</VirtualHost>

主机D
主机D和主机C配置相同,参考以上文档

*主机E **
Discuz论坛测试
# unzip Discuz_X3.2_SC_UTF8.zip
# cd upload/
# cp -R ./
/shared/

浏览器输入www.xuanzi.com即可配置安装Discuz了,要注意的是安装Discuz论坛时填入mysql服务器IP地址时,要填入192.168.1.104不能填入localhost。并且输入主机C的IP和输入主机D的IP访问的内容是相同的,比如主机C上发帖,用主机D的IP访问可以看到。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,186评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,858评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,620评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,888评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,009评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,149评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,204评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,956评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,385评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,698评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,863评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,544评论 4 335
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,185评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,899评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,141评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,684评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,750评论 2 351

推荐阅读更多精彩内容

  • 1.Linux下如何用命令查看实时日志(完整命令) tail -f 路径.log查看前多少行 tai-200f 路...
    qianyewhy阅读 2,267评论 0 11
  • 1、第八章 Samba服务器2、第八章 NFS服务器3、第十章 Linux下DNS服务器配站点,域名解析概念命令:...
    哈熝少主阅读 3,723评论 0 10
  • NFS相关介绍一、NFS简介1. NFS(Network File System): NFS是一个文件共享协议, ...
    sjfbjs阅读 875评论 0 0
  • 一、实现从根,com,rj.com 模拟互联网的DNS架构 DNS(Domain Name System,域名系统...
    ssjinyao阅读 1,420评论 0 7
  • 视频时长:67分钟 文字共计2276字,需要阅读时间6分钟 吴伯凡,男,1966年生,湖北荆州人,哲学硕士,《21...
    那些光阴阅读 2,876评论 2 5