利用lamp架構(gòu)搭建Discuz論壇,并實(shí)現(xiàn)對數(shù)據(jù)庫的高可用-創(chuàng)新互聯(lián)

lamp架構(gòu)=LAMP指的Linux(操作系統(tǒng))、Apache(HTTP 服務(wù)器),MySQL(數(shù)據(jù)庫軟件) 和PHP(有時也是指Perl或Python) 的第一個字母,一般用來建立web 服務(wù)器。

創(chuàng)新互聯(lián)建站成立于2013年,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目做網(wǎng)站、成都網(wǎng)站制作網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元科爾沁右翼中做網(wǎng)站,已為上家服務(wù),為科爾沁右翼中各地企業(yè)和個人服務(wù),聯(lián)系電話:13518219792

利用lamp架構(gòu)搭建Discuz論壇,并實(shí)現(xiàn)對數(shù)據(jù)庫的高可用

#############源碼安裝php###########

tar jxf php-5.6.20.tar.bz2

cd php-5.6.20

解決依賴性:

yum install freetype-devel libmcrypt-2.5.8-9.el6.x86_64.rpmnet-snmp-devel libmcrypt-devel-2.5.8-9.el6.x86_64.rpm libpng-devel gmp-devel libjpeg-turbo-devel libcurl-devel libxml2-devel-y

檢測依賴性:

[root@server1 php-5.6.20]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --without-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash --with-mysql --with-mysqli --with-pdo-mysql --enable-mysqlnd

沒有報錯之后就可以執(zhí)行以下操作:

[root@server1 php-5.6.20]# make && make install

[root@server1 php-5.6.20]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini

[root@server1 php-5.6.20]# cd /usr/local/lnmp/php/etc/

[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf

cd /mnt/php-5.6.20/sapi/fpm/

[root@server1 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm

[root@server1 fpm]# chmod +x /etc/init.d/php-fpm

[root@server1 fpm]# cd /usr/local/lnmp/php/etc/

[root@server1 etc]# vim php-fpm.conf#取消25行的注釋

 25 pid = run/php-fpm.pid

[root@server1 etc]# vim php.ini##修改時區(qū)

925 date.timezone = 'Asia/Shanghai'

[root@server1 etc]# /etc/init.d/php-fpm start

Starting php-fpm  done

[root@server1 etc]# cd /usr/local/

[root@server1 local]# cd nginx/sbin/

[root@server1 sbin]# ls

nginx

[root@server1 sbin]# pwd

/usr/local/nginx/sbin

[root@server1 sbin]# vim ~/.bash_profile

PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin

[root@server1 sbin]# source ~/.bash_profile

[root@server1 sbin]# nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

 cd/usr/local/nginx/conf

[root@server1 conf]# vim nginx.conf

 49         location / {

 50             root   html;

 51             index index.php index.html index.htm;#調(diào)整優(yōu)先級,先看index.php

 52         }

 71         location ~ \.php$ {

 72             root           html;

 73             fastcgi_pass   127.0.0.1:9000;

 74             fastcgi_index  index.php;

 75             fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

 76             include        fastcgi.conf;

[root@server1 conf]# nginx

[root@server1 conf]# nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@server1 conf]# cd ..

[root@server1 nginx]# cd html/

[root@server1 html]# vim nginx.php

<?php

phpinfo()

?>

找到當(dāng)前主機(jī)mysql的緩存文件

[root@server1 mysql]# ll /var/lib/mysql/mysql.sock

srwxrwxrwx 1 mysql mysql 0 3月  23 17:16 /var/lib/mysql/mysql.sock

cd /usr/local/lnmp/php/etc

[root@server1 etc]# vim php.ini

#默認(rèn)數(shù)據(jù)存儲在/var/lib/mysql/mysql.sock這個文件中

1001 pdo_mysql.default_socket=/var/lib/mysql/mysql.sock

1150 mysql.default_socket =/var/lib/mysql/mysql.sock

1209 mysqli.default_socket =/var/lib/mysql/mysql.sock

[root@server1 etc]# /etc/init.d/php-fpm reload

Reload service php-fpm  done

測試:

利用lamp架構(gòu)搭建Discuz論壇,并實(shí)現(xiàn)對數(shù)據(jù)庫的高可用

Php安裝成功!

Heartbeat + mysql +drbd

三個部分分別提供了高可用,數(shù)據(jù)庫,以及存儲服務(wù)。將之后的論壇整合成一個完整的體系

說明:server3,server4提供以上三個服務(wù)

1數(shù)據(jù)庫

直接yum install mysql-server -y  #server3和server4都做

mysql_secure_installation#安全初始化,設(shè)置root密碼,否則數(shù)據(jù)庫不要密碼也能登陸

2.Heartbeat

[root@server3 heartbeat]# ls

heartbeat-3.0.4-2.el6.x86_64.rpm        heartbeat-libs-3.0.4-2.el6.x86_64.rpm

heartbeat-devel-3.0.4-2.el6.x86_64.rpm  ldirectord-3.9.5-3.1.x86_64.rpm

Server3,server4都要安裝

[root@server3 heartbeat]# yum install * -y

[root@server3 heartbeat]# cd /etc/ha.d/

[root@server3 ha.d]# ls

harc  rc.d  README.config  resource.d  shellfuncs

[root@server3 ha.d]# cp /usr/share/doc/heartbeat-3.0.4/{authkeys,ha.cf,haresources} .

[root@server3 ha.d]# vim ha.cf

48 keepalive 2

56 deadtime 30

76 udpport 1111

91 bcast   eth0

157 auto_failback on

211         node    server3.example.com

212         node    server4.example.com

222 ping 172.25.50.250

254 respawn hacluster /usr/lib64/heartbeat/ipfail

262 apiauth ipfail gid=haclient uid=hacluster

[root@server3 ha.d]# vim authkeys

 23 auth 1

 24 1 crc

 25 #2 sha1 HI!

 26 #3 md5 Hello!

[root@server3 ha.d]# vim haresources

在文件最后添加:

server3.example.com IPaddr::172.25.50.200/24/eth0 drbddisk::homework Filesystem::/dev/drbd2::/var/lib/mysql::ext4 mysqld

##做測試可以用:server3.example.com IPaddr::172.25.50.200/24/eth0 mysqld(上面的是針對drbd所作的)

[root@server3 ha.d]# scp ha.cf haresources authkeys 172.25.50.40:/etc/ha.d/

兩邊都重新啟動heartbeat

3.drbd共享存儲

給server3和server4都劃分一個4G的虛擬磁盤

[root@server3 mnt]# fdisk -l

Disk/dev/vdb: 4294 MB, 4294967296 bytes

16 heads, 63 sectors/track, 8322 cylinders

Units = cylinders of 1008 * 512 = 516096 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

[root@server4 drbd]# fdisk -l

Disk/dev/vda: 4294 MB, 4294967296 bytes

16 heads, 63 sectors/track, 8322 cylinders

Units = cylinders of 1008 * 512 = 516096 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

安裝以下rpm包

drbd-8.4.2-2.el6.x86_64.rpm

drbd-bash-completion-8.4.2-2.el6.x86_64.rpm

drbd-heartbeat-8.4.2-2.el6.x86_64.rpm

drbd-km-2.6.32_431.el6.x86_64-8.4.2-2.el6.x86_64.rpm

drbd-pacemaker-8.4.2-2.el6.x86_64.rpm

drbd-udev-8.4.2-2.el6.x86_64.rpm

drbd-utils-8.4.2-2.el6.x86_64.rpm

drbd-xen-8.4.2-2.el6.x86_64.rpm

[root@server3 drbd]# rpm -ivh *

Server4也需要安裝這些rpm包

[root@server3 mnt]# cd /etc/drbd.d/

[root@server3 drbd.d]# ls

global_common.conf

[root@server3 drbd.d]# vim homework.res

[root@server3 drbd.d]# cat homework.res

resource homework {

meta-disk internal;

device /dev/drbd2;#自定義的共享磁盤名稱

syncer {verify-alg sha1;

}

on server3.example.com {#節(jié)點(diǎn)的hostname

disk /dev/vdb;#自身主將用來設(shè)置成共享的磁盤路徑

address 172.25.50.30:7789;#節(jié)點(diǎn)ip

}

on server4.example.com {

disk /dev/vda;

address 172.25.50.40:7789;

}

}

這樣就無需擔(dān)心發(fā)布共享磁盤名稱不一樣如何解決的問題了

[root@server3 drbd.d]# scp homework.res 172.25.50.40:/etc/drbd.d/

[root@server3 drbd.d]# drbdadm create-md homework

##server3和server4都做

  --==  Thank you for participating in the global usage survey  ==--

The server's response is:

Writing meta data...

initializing activity log

NOT initializing bitmap

New drbd meta data block successfully created.

[root@server3 drbd.d]# /etc/init.d/drbd start#server4同時啟動

Starting DRBD resources: [

     create res: homework

   prepare disk: homework

    adjust disk: homework

     adjust net: homework

]

[root@server3 drbd.d]# cat /proc/drbd

version: 8.4.2 (api:1/proto:86-101)

GIT-hash: 7ad5f850d711223713d6dcadc3dd48860321070c build by root@server1.example.com, 2017-02-21 09:59:13

 1: cs:Connected ro:Secondary/Secondaryds:Inconsistent/Inconsistent C r-----

    ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:4194140

[root@server3 drbd.d]# drbdadm primary homework --force

[root@server3 drbd.d]# mkfs.ext4 /dev/drbd2

[root@server3 mnt]# mount /dev/drbd2 /mnt/mount/

[root@server3 mnt]# cd mount/

[root@server3 mount]# ls

lost+found

[root@server3 mount]# touch 111

[root@server3 mount]# ls

111  lost+found

[root@server3 mount]# cd ..

[root@server3 mnt]# umount /mnt/mount/

[root@server3 mnt]# drbdadm secondary homework

[root@server4 drbd.d]# drbdadm primary homework

[root@server4 drbd.d]# vim homework.res

[root@server4 drbd.d]# mount /dev/drbd2 /mnt/mount/

[root@server4 drbd.d]# cd /mnt/mount/

[root@server4 mount]# ls

111  lost+found

[root@server4 mnt]# umount /mnt/mount/

[root@server4 mnt]# drbdadm secondary homework

在掛載的目錄下看到在server3上創(chuàng)建的文件,說明分布式共享存儲配置成功

Heartbeat+mysql

關(guān)閉兩臺虛擬機(jī)的 heartbeat 服務(wù)

[root@server3 mnt]# /etc/init.d/mysqld stop

[root@server3 mnt]# drbdadm primary homework

[root@server3 mnt]# mount /dev/drbd2 /mnt/mount/

[root@server3 mount]# cd /var/lib/mysql/

[root@server3 mysql]# cp -r * /mnt/mount/

[root@server3 ~]# umount /mnt/mount/

[root@server3 ~]# mount /dev/drbd2 /var/lib/mysql/

[root@server3 ~]# chown mysql.mysql /var/lib/mysql/ -R

[root@server3 ~]# /etc/init.d/mysqld start

正在啟動 mysqld:                                          [確定]

[root@server3 ~]# cd

[root@server3 ~]# /etc/init.d/mysqld stop

停止 mysqld:                                              [確定]

[root@server3 ~]# umount /var/lib/mysql/

[root@server3 ~]# drbdadm secondary homework

把server3,server4的heartbeat服務(wù)打開服務(wù)會自動開啟,當(dāng)server3的heatbeat服務(wù)關(guān)閉是。Vip:172.25.50.200會調(diào)轉(zhuǎn)到server4上。

最后:

整合

現(xiàn)在我們來搭建一個論壇

[root@server1 mnt]# unzip Discuz_X3.2_SC_UTF8.zip -d /usr/local/nginx/html/

##將這個論壇壓縮包解壓在nginx的默認(rèn)發(fā)布目錄中

[root@server1 mnt]# cd /usr/local/nginx/html/

[root@server1 html]# ls

50x.html  index.html  nginx.php  readme  upload  utility

[root@server1 html]# cd upload/

[root@server1 upload]# ls

admin.php  connect.php      forum.php  member.php  search.php  uc_server

api        cp.php           group.php  misc.php    source      userapp.php

api.php    crossdomain.xml  home.php   plugin.php  static

archiver   data             index.php  portal.php  template

config     favicon.ico      install    robots.txt  uc_client

[root@server1 upload]# chmod 777 config/

[root@server1 upload]# chmod 777 data/ -R

[root@server1 upload]# chmod 777 uc_* -R

在serer3上設(shè)置root用戶可以遠(yuǎn)程登陸的權(quán)限

 grant all privileges on *.* to "root"@"%" identified  by "redhat";

Query OK, 0 rows affected (0.00 sec)

測試方法,在serer1上遠(yuǎn)程登陸172.25.50.200這個ip的數(shù)據(jù)庫

并且在數(shù)據(jù)庫中有解的權(quán)限即可。

利用lamp架構(gòu)搭建Discuz論壇,并實(shí)現(xiàn)對數(shù)據(jù)庫的高可用

在瀏覽器上:172.25.50.10/upload/

利用lamp架構(gòu)搭建Discuz論壇,并實(shí)現(xiàn)對數(shù)據(jù)庫的高可用

利用lamp架構(gòu)搭建Discuz論壇,并實(shí)現(xiàn)對數(shù)據(jù)庫的高可用

利用lamp架構(gòu)搭建Discuz論壇,并實(shí)現(xiàn)對數(shù)據(jù)庫的高可用

數(shù)據(jù)庫寫入測試:在server3上

利用lamp架構(gòu)搭建Discuz論壇,并實(shí)現(xiàn)對數(shù)據(jù)庫的高可用

高可用測試:

關(guān)閉server3上的heartbeat服務(wù)。

利用lamp架構(gòu)搭建Discuz論壇,并實(shí)現(xiàn)對數(shù)據(jù)庫的高可用

利用lamp架構(gòu)搭建Discuz論壇,并實(shí)現(xiàn)對數(shù)據(jù)庫的高可用

如圖,可以看見heartbeat服務(wù)停了之后,sererv4自動接管數(shù)據(jù)庫,這時查看數(shù)據(jù)庫內(nèi)容與在server3上看到的一致!

實(shí)驗(yàn)成功?。。。。。。。。。。。。。。。。。。。。。。。?/p>

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

新聞標(biāo)題:利用lamp架構(gòu)搭建Discuz論壇,并實(shí)現(xiàn)對數(shù)據(jù)庫的高可用-創(chuàng)新互聯(lián)
文章來源:http://www.muchs.cn/article22/cdshjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計、營銷型網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、商城網(wǎng)站、品牌網(wǎng)站建設(shè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)