LAMP的負(fù)載均衡和DNS的主從負(fù)載

前端兩臺(tái)DNS做主從復(fù)制及兩臺(tái)apache做負(fù)載均衡,實(shí)現(xiàn)LAMP的一臺(tái)NFS+MySQL負(fù)載均衡訪問,安裝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

主機(jī)A IP:192.168.100.100 搭建DNS服務(wù)器
主機(jī)B IP:192.168.100.101 搭建DNS服務(wù)器
主機(jī)C IP:192.168.100.102 安裝apache和php
主機(jī)D IP:192.168.100.103 安裝apache和php
主機(jī)E IP:192.168.100.104NFS服務(wù)器帽蝶,MySQL服務(wù)器
域名:XUANZI.COM

實(shí)施規(guī)劃:
主機(jī)E搭建的NFS服務(wù)器共享/shared目錄,主機(jī)C和主機(jī)D將主機(jī)A共享的/shared目錄掛載至本地的/www/xuanzi目錄块攒,當(dāng)做Apache的DocumenRoot励稳。當(dāng)通過主機(jī)C的IP和主機(jī)D的IP以及其域名來訪問頁面時(shí),頁面內(nèi)容要求一樣囱井。
在搭建DNS服務(wù)器時(shí)驹尼,主機(jī)名www.xuanzi.com有兩個(gè)A記錄,分別指向主機(jī)C的IP和主機(jī)D的IP庞呕。這樣在瀏覽器輸入www.xuanzi.com訪問頁面時(shí)新翎,輪流解析到主機(jī)C和主機(jī)D的IP,這樣便能達(dá)到負(fù)載均衡的效果住练。

主機(jī)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                 

   

區(qū)域文件

$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服務(wù)器配置
"/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

反向區(qū)域文件


$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

主機(jī)C
主機(jī)C掛載NFS共享的/shared目錄髓绽,執(zhí)行以下命令:

# 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
出現(xiàn)錯(cuò)誤:
configure: error: pcre-config for libpcre not found. PCRE is required anavailabl from 
解決辦法
# yum install -y pcre-devel    
# make    
# make install

提供SysV風(fēng)格的啟動(dòng)腳本:/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
    出現(xiàn)錯(cuò)誤:
    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

主機(jī)C和主機(jī)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>

主機(jī)D
主機(jī)D和主機(jī)C配置相同,參考以上文檔

*主機(jī)E **
Discuz論壇測(cè)試
# unzip Discuz_X3.2_SC_UTF8.zip
# cd upload/
# cp -R ./
/shared/

瀏覽器輸入www.xuanzi.com即可配置安裝Discuz了妆绞,要注意的是安裝Discuz論壇時(shí)填入mysql服務(wù)器IP地址時(shí)顺呕,要填入192.168.1.104不能填入localhost。并且輸入主機(jī)C的IP和輸入主機(jī)D的IP訪問的內(nèi)容是相同的括饶,比如主機(jī)C上發(fā)帖株茶,用主機(jī)D的IP訪問可以看到。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末图焰,一起剝皮案震驚了整個(gè)濱河市启盛,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌技羔,老刑警劉巖僵闯,帶你破解...
    沈念sama閱讀 218,546評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異藤滥,居然都是意外死亡鳖粟,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,224評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門拙绊,熙熙樓的掌柜王于貴愁眉苦臉地迎上來向图,“玉大人泳秀,你說我怎么就攤上這事¢剩” “怎么了嗜傅?”我有些...
    開封第一講書人閱讀 164,911評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長檩赢。 經(jīng)常有香客問我吕嘀,道長,這世上最難降的妖魔是什么漠畜? 我笑而不...
    開封第一講書人閱讀 58,737評(píng)論 1 294
  • 正文 為了忘掉前任币他,我火速辦了婚禮坞靶,結(jié)果婚禮上憔狞,老公的妹妹穿的比我還像新娘。我一直安慰自己彰阴,他們只是感情好瘾敢,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,753評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著尿这,像睡著了一般簇抵。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上射众,一...
    開封第一講書人閱讀 51,598評(píng)論 1 305
  • 那天碟摆,我揣著相機(jī)與錄音,去河邊找鬼叨橱。 笑死典蜕,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的罗洗。 我是一名探鬼主播愉舔,決...
    沈念sama閱讀 40,338評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼伙菜!你這毒婦竟也來了轩缤?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,249評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤贩绕,失蹤者是張志新(化名)和其女友劉穎是钥,沒想到半個(gè)月后拷邢,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,696評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,888評(píng)論 3 336
  • 正文 我和宋清朗相戀三年蛮穿,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片甚牲。...
    茶點(diǎn)故事閱讀 40,013評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡镶苞,死狀恐怖陕靠,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情脱茉,我是刑警寧澤剪芥,帶...
    沈念sama閱讀 35,731評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站琴许,受9級(jí)特大地震影響税肪,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜榜田,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,348評(píng)論 3 330
  • 文/蒙蒙 一益兄、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧箭券,春花似錦净捅、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,929評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至废亭,卻和暖如春国章,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背豆村。 一陣腳步聲響...
    開封第一講書人閱讀 33,048評(píng)論 1 270
  • 我被黑心中介騙來泰國打工液兽, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人掌动。 一個(gè)月前我還...
    沈念sama閱讀 48,203評(píng)論 3 370
  • 正文 我出身青樓四啰,卻偏偏與公主長得像,于是被迫代替她去往敵國和親坏匪。 傳聞我的和親對(duì)象是個(gè)殘疾皇子拟逮,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,960評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容