lamp架構(gòu)=LAMP指的Linux(操作系統(tǒng))、Apache(HTTP 服務(wù)器),MySQL(數(shù)據(jù)庫(kù)軟件) 和PHP(有時(shí)也是指Perl或Python) 的第一個(gè)字母,一般用來(lái)建立web 服務(wù)器。
創(chuàng)新互聯(lián)公司長(zhǎng)期為成百上千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為山西企業(yè)提供專業(yè)的成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì),山西網(wǎng)站改版等技術(shù)服務(wù)。擁有十年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
#############源碼安裝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
檢測(cè)依賴性:
[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
沒有報(bào)錯(cuò)之后就可以執(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##修改時(shí)區(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)先級(jí),先看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
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ù)存儲(chǔ)在/var/lib/mysql/mysql.sock這個(gè)文件中
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
測(cè)試:
Php安裝成功!
Heartbeat + mysql +drbd
三個(gè)部分分別提供了高可用,數(shù)據(jù)庫(kù),以及存儲(chǔ)服務(wù)。將之后的論壇整合成一個(gè)完整的體系
說明:server3,server4提供以上三個(gè)服務(wù)
1數(shù)據(jù)庫(kù)
直接yum install mysql-server -y #server3和server4都做
mysql_secure_installation#安全初始化,設(shè)置root密碼,否則數(shù)據(jù)庫(kù)不要密碼也能登陸
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
##做測(cè)試可以用:server3.example.com IPaddr::172.25.50.200/24/eth0 mysqld(上面的是針對(duì)drbd所作的)
[root@server3 ha.d]# scp ha.cf haresources authkeys 172.25.50.40:/etc/ha.d/
兩邊都重新啟動(dòng)heartbeat
3.drbd共享存儲(chǔ)
給server3和server4都劃分一個(gè)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;#自身主將用來(lái)設(shè)置成共享的磁盤路徑
address 172.25.50.30:7789;#節(jié)點(diǎn)ip
}
on server4.example.com {
disk /dev/vda;
address 172.25.50.40:7789;
}
}
這樣就無(wú)需擔(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同時(shí)啟動(dòng)
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)建的文件,說明分布式共享存儲(chǔ)配置成功
Heartbeat+mysql
關(guān)閉兩臺(tái)虛擬機(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
正在啟動(dòng) 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ù)會(huì)自動(dòng)開啟,當(dāng)server3的heatbeat服務(wù)關(guān)閉是。Vip:172.25.50.200會(huì)調(diào)轉(zhuǎn)到server4上。
最后:
整合
現(xiàn)在我們來(lái)搭建一個(gè)論壇
[root@server1 mnt]# unzip Discuz_X3.2_SC_UTF8.zip -d /usr/local/nginx/html/
##將這個(gè)論壇壓縮包解壓在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)
測(cè)試方法,在serer1上遠(yuǎn)程登陸172.25.50.200這個(gè)ip的數(shù)據(jù)庫(kù)
并且在數(shù)據(jù)庫(kù)中有解的權(quán)限即可。
在瀏覽器上:172.25.50.10/upload/
數(shù)據(jù)庫(kù)寫入測(cè)試:在server3上
高可用測(cè)試:
關(guān)閉server3上的heartbeat服務(wù)。
如圖,可以看見heartbeat服務(wù)停了之后,sererv4自動(dòng)接管數(shù)據(jù)庫(kù),這時(shí)查看數(shù)據(jù)庫(kù)內(nèi)容與在server3上看到的一致!
實(shí)驗(yàn)成功!?。。。。。。。。。。。。。。。。。。。。。?!