天天看點

編譯安裝LAMP

一、什麼是LAMMP?

Linux+Apache+Mysql+Memcached+Perl/PHP/Python一組常用來搭建動态網站或者伺服器的開源軟體,本身都是各自獨立的程式,但是因為常被放在一起使用,擁有了越來越高的相容度,共同組成了一個強大的Web應用程式平台。随着開源潮流的蓬勃發展,開放源代碼的LAMP已經與J2EE和.Net商業軟體形成三足鼎立之勢,并且該軟體開發的項目在軟體方面的投資成本較低,是以受到整個IT界的關注。從網站的流量上來說,70%以上的通路流量是LAMP來提供的,LAMP是最強大的網站解決方案.

二、為什麼要編譯安裝?

這是Linux初學者經常問到的問題,編譯安裝可以提供更高的靈活性,自主的開啟或關閉某些功能,另外,系統發行商自帶的rpm包的版本比較老,而且一般是在比較通用的機器上編譯的,對于使用者來說可能不是很适合,編譯安裝更能适合自己的機器配置、性能等要求。

三、各元件的作用:

Apache:提供http服務

Xcache:為php提供加速功能;

MySQL:為網站提供資料庫支援;

Memcached:為資料庫的查詢提供高速緩存,優化查詢速度

PHP:解釋PHP程式開發的網頁

四、工作原理:

編譯安裝LAMP

1、客戶把請求發送到http伺服器;

2、http根據請求的内容進行處理,如果請求的是靜态頁面,就在本地處理,如果請求的是php頁面,http伺服器發送到FastCGI伺服器,xcache将php代碼進行編譯成opcode,加速php響應;

3、如果用戶端發起的是一個mysql查詢,PHP伺服器将查詢發到memcached接口;

4、memcached伺服器如果沒有此緩存,就向PHP伺服器傳回否定回答;

5、PHP伺服器向MySQL發起查詢請求;

6、MySQL向PHP伺服器傳回結果;

7、PHP如果配置了要緩存此結果,就将查詢結果發送給memcached伺服器進行緩存;

8、PHP将結果傳回給http伺服器

9、http伺服器回應客戶的請求;

五、配置案例:

說明:

httpd(172.16.1.1)

FastCGI(172.16.1.2)

mysql(172.16.1.3)

memcached(172.16.1.4)

(一)、編譯安裝httpd

準備工作:

安裝開發包組 "Development tools" "Server Platform Development"

下載下傳新的apr和pcre,此處示範用的版本如下:

httpd-2.4.6.tar.bz2

apr-1.4.6.tar.bz2

apr-util-1.5.2.tar.bz2

pcre-devel-7.8-6.el6.x86_64.rpm

# tar xf httpd-2.4.6.tar.bz2

# cd httpd-2.4.4

# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event

./configure 選項介紹:

--prefix=/usr/local/apache ;自定義安裝路徑

--sysconfdir=/etc/httpd24;配置檔案目錄

--enabe-so;編譯動态加載子產品(DSO)支援到httpd二進制檔案,此子產品使得Apache的各功能子產品可以與核心分開編譯、運作時動态加載。

--enable-ssl;支援ssl功能

--enable-cgi;支援cgi

--with-pcre ;支援Perl相容的正規表達式庫

--with-apr=/usr/local/apr;為apache提供底層支援的接口庫

--with-apr-until=/usr/local/apr-util

--with-zlib;支援zlib的壓縮

--enable-rewrite;支援url重寫

--enable-modules=most;支援大部分的子產品

--enable-mpms-shared=all ;指定所有子產品為共享子產品

--with-mpm-event=event;選擇Apache多路處理子產品為事件驅動子產品

MPM介紹;

1):profork

工作原理: 一個單獨的控制程序(父程序)負責産生子程序,為Unix系統下預設處理子產品,它将運作一個非線程型的、預派生的Web伺服器,這些子程序用于監聽請求并作出應答。Apache總是試圖保持一些備用的(spare)或者是空閑的子程序用于迎接即将到來的請求。這樣用戶端就不需要在得到服務前等候子程序的産生。将MaxClients設定為一個足夠大的數值以處理潛在的請求高 峰,同時又不能太大,以緻需要使用的記憶體超出實體記憶體的大小。

2)、worker

每個程序可以擁有的線程數量是固定的。伺服器會根據負載情況增加或減少程序數量。一個單獨的控制程序(父程序)負責子程序的建立。每個子程序可 以建立ThreadsPerChild數量的服務線程和一個監聽線程,該監聽線程監聽接入請求并将其傳遞給服務線程處理和應答。

3)、event

事件驅動模型,是一個程序響應多個請求,當程序向核心産生一個系統調用,核心會先讓程序去響應其它請求,等核心處理完成就通知程序,采用了邊緣觸發的機制。在apache2.4版本中支援了這種模型。

安裝

make && make install

#導出PATH,友善執行指令;

vi /etc/profile.d/apache.sh

添加:

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

# 制作啟動腳本

cp /etc/init.d/httpd /etc/init.d/httpd24

# 添加httpd24到服務清單

chkconfig --add httpd24

# 開機啟動httpd24

chkconfig httpd24 on

#修改原配置檔案路徑

vi /etc/init.d/httpd24

修改:

# 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}

pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}

#啟動服務

service httpd24 start

如果要設定https,需要再配置檔案中啟用

LoadModule ssl_module modules/mod_ssl.so

# Secure (SSL/TLS) connections

Include /etc/httpd24/extra/httpd-ssl.conf

為網站生成私鑰并為網站伺服器申請證書(配置詳解openssl)

在配置檔案/etc/httpd24/extra/httpd-ssl.conf中設定網站證書和私鑰存放位置

service httpd24 restart

netstat -tnl檢視

将CA憑證導出到用戶端,輕按兩下證書,并安裝證書到“受信任的根證書頒發機構”

編譯安裝LAMP

通路測試:https://www.magedu.com;

編譯安裝LAMP

(二)編譯php以FastCGI伺服器的方式工作:

編譯php時啟用php-fpm就可以把php啟動為一個FastCGI的伺服器;

httpd與php進行互動必須工作在反向代理模式下,并且需要fcgi子產品跟FastCGI伺服器通信;

如果想讓編譯的php支援mcrypt擴充,需要安裝如下軟體

libmcrypt-2.5.7-5.el5.i386.rpm

libmcrypt-devel-2.5.7-5.el5.i386.rpm

mhash-0.9.9-1.el5.centos.i386.rpm

mhash-devel-0.9.9-1.el5.centos.i386.rpm

# 資料庫在本地:

./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --enable-fpm --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2

# 資料庫不在本地:

./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl  --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --enable-fpm --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2

編譯參數介紹;

-prefix=/usr/local/PHP           php 安裝目錄    

--with-apxs2=/usr/local/apache/bin/apxs

--with-config-file-path=/usr/local/PHP/etc   指定php.ini位置

--with-mysql=/usr/local/mysql   mysql安裝目錄,對mysql的支援

--with-mysqli=/usr/local/mysql/bin/mysql_config    mysql進階通路接口

--with-openssl ;可以支援ssl

--enable-mbstring ;啟動多位元組字元支援

--with-freetype-dir ;這是讓PHP支援GD庫的配置選項

--with-jpeg-dir

--with-png-dir

--with-zlib;支援zlib的壓縮庫

--with-libxml-dir=/usr

--enable-xml ;支援xml格式

--enable-sockets;支援socket方式通信

--with-apxs2=/usr/local/apache/bin/apxs;php針對此接口來編譯進apache

--with-mcrypt;支援加密工具

--with-config-file-path=/etc;配置檔案檔案

--with-config-file-scan-dir=/etc/php.d;找/etc/php.d/下一.ini結尾的檔案作為配置檔案

--with-bz2

--enable-maintainer-zts;如果MPM為event和worker模型,編譯時此處須啟用,如果為prefork,它是以mod_php的方式安裝的。

make && make install

為php提供配置檔案:

# cp php.ini-production /etc/php.ini

3、配置php-fpm

為php-fpm提供Sysv init腳本,并将其添加至服務清單:

# cp sapi/fpm/init.d.php-fpm  /etc/rc.d/init.d/php-fpm

# chmod +x /etc/rc.d/init.d/php-fpm

# chkconfig --add php-fpm

# chkconfig php-fpm on

為php-fpm提供配置檔案:

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

編輯php-fpm的配置檔案:

# vim /usr/local/php/etc/php-fpm.conf

配置fpm的相關選項為你所需要的值,并啟用pid檔案(如下最後一行):

pm.max_children = 50

pm.start_servers = 5

pm.min_spare_servers = 2

pm.max_spare_servers = 8

pid = /usr/local/php/var/run/php-fpm.pid

接下來就可以啟動php-fpm了:

# service php-fpm start

使用如下指令來驗正(如果此指令輸出有中幾個php-fpm程序就說明啟動成功了):

# ps aux | grep php-fpm

預設情況下,fpm監聽在127.0.0.1的9000端口,也可以使用如下指令驗正其是否已經監聽在相應的套接字。

# netstat -tnlp | grep php-fpm

tcp      0      0  127.0.0.1:9000        0.0.0.0:*        LISTEN      689/php-fpm

httpd和php不在一台主機上;需修改fastcgi監聽位址

listen = 172.16.1.2:9000

修改httpd伺服器(172.16.1.1)/etc/httpd24/httpd.conf檔案中添加如下内容:

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

修改預設網頁:

DirectoryIndex  index.php index.html

在DocumentRoot下添加:

 ProxyRequests Off

 ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.1.2:9000/www/magedu/com/$1

測試:

[root@stu01 php-5.4.19]# curl  -I http://172.16.1.1

HTTP/1.1 200 OK

Date: Fri, 23 Aug 2013 11:01:41 GMT

Server: Apache/2.4.6 (Unix) OpenSSL/1.0.0-fips PHP/5.4.19

X-Powered-By: PHP/5.4.19

Content-Type: text/html

注意:httpd伺服器(172.16.1.1)的DocumentRoot下

fcgi://172.16.1.2:9000/中的www/magedu/com/為FastCGI伺服器上檔案系統的路徑;

在FastCGI的伺服器(172.16.1.2)上有一個目錄是/www/magedu/com

例:将phpMyadmin解壓在/www/magedu/com

# unzip phpMyAdmin-4.0.5-all-languages.zip

# cd phpMyAdmin-4.0.5-all-languages

# mv * /var/www/html/

# cd /var/www/html

cp config.sample.inc.php  config.inc.php

vi config.inc.php

# 把blowfish算法的密碼填一個随機數

$cfg['blowfish_secret'] ='alkdjflakjdf';/

出現登入界面:此時資料庫尚未安裝

編譯安裝LAMP

(三)使用xcache為PHP加速;

XCache 是一個開源的 opcode 緩存器/優化器, 這意味着他能夠提高您伺服器上的 PHP 性能. 他通過Zend引擎編譯 PHP 後的資料緩沖到共享記憶體進而避免重複的編譯過程, 能夠直接使用緩沖區已編譯的代碼進而提高速度. 通常能夠提高您的頁面生成速率 2 到5 倍, 降低伺服器負載

1、安裝

# tar xf xcache-3.0.1.tar.gz

# cd xcache-3.0.1

# /usr/local/php/bin/phpize ;使php識别此子產品

# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config

# make && make install

安裝結束時,會出現類似如下行:

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20100525/

2、編輯php.ini,整合php和xcache:

首先将xcache提供的樣例配置導入php.ini

# mkdir /etc/php.d

# cp xcache.ini /etc/php.d

說明:xcache.ini檔案在xcache的源碼目錄中。

在/www/magedu/com下建立一個info.php

<?php

   phpinfo();

?>

編譯安裝LAMP

性能測試工具之ab:

ab

ulimit -n 30000 限制使用者同時打開的檔案數;預設為1000

ab

-c     -c 100 并發連接配接數

-n-n 10000總共1w次。

ab -c 100 -n 10000 http://www.magedu.com/index.php

php以子產品方式工作且沒有配置xcache之前:

[root@stu01 ~]# ab -c 50 -n 500 http://www.magedu.com/index.php

This is ApacheBench, Version 2.3 <$Revision: 655654 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.magedu.com (be patient)

Completed 100 requests

Completed 200 requests

Completed 300 requests

Completed 400 requests

Completed 500 requests

Finished 500 requests

Server Software:        Apache/2.4.6

Server Hostname:        www.magedu.com

Server Port:            80

Document Path:          /index.php

Document Length:        8139 bytes

Concurrency Level:      50

Time taken for tests:   254.889 seconds

Complete requests:      500

Failed requests:        0

Write errors:           0

Total transferred:      4680364 bytes

HTML transferred:       4069500 bytes

Requests per second:    1.96 [#/sec] (mean)

Time per request:       25488.945 [ms] (mean)

Time per request:       509.779 [ms] (mean, across all concurrent requests)

Transfer rate:          17.93 [Kbytes/sec] received

Connection Times (ms)

             min  mean[+/-sd] median   max

Connect:        0    5  12.1      1     179

Processing:   127 24924 15913.8  22397   77363

Waiting:      122 24100 15661.8  21556   76825

Total:        127 24929 15912.8  22402   77364

Percentage of the requests served within a certain time (ms)

 50%  22402

 66%  31010

 75%  35930

 80%  39479

 90%  45833

 95%  53053

 98%  62870

 99%  66384

100%  77364 (longest request)

以子產品方式配置php後,配置完xcache之後測試:

[root@stu01 ~]# ab -c 50 -n 500 http://www.magedu.com/index.php

Time taken for tests:   3.329 seconds

Total transferred:      4680272 bytes

Requests per second:    150.20 [#/sec] (mean)

Time per request:       332.892 [ms] (mean)

Time per request:       6.658 [ms] (mean, across all concurrent requests)

Transfer rate:          1372.99 [Kbytes/sec] received

Connect:        0    8  12.8      1      86

Processing:    16  304 215.0    273    1626

Waiting:       14  287 211.1    256    1523

Total:         17  312 215.1    284    1627

 50%    284

 66%    362

 75%    405

 80%    442

 90%    524

 95%    620

 98%    842

 99%   1258

100%   1627 (longest request)

啟用FastCGI性能測試:

[root@sta2 ~]# ab -c 50 -n 500 http://www.magedu.com/index.php

Document Length:        7792 bytes

Time taken for tests:   8.186 seconds

Total transferred:      4444802 bytes

HTML transferred:       3896000 bytes

Requests per second:    61.08 [#/sec] (mean)

Time per request:       818.554 [ms] (mean)

Time per request:       16.371 [ms] (mean, across all concurrent requests)

Transfer rate:          530.28 [Kbytes/sec] received

Connect:        0    1   1.0      1       9

Processing:    72  781 131.5    809     897

Waiting:       69  777 131.2    805     894

Total:         75  782 131.2    810     898

 50%    810

 66%    821

 75%    833

 80%    842

 90%    859

 95%    875

 98%    884

 99%    891

100%    898 (longest request)

# 配置FastCGI和xcache之後測試結果:

[root@sta3 run]# ab -c 50 -n 500 http://www.magedu.com/index.php

Time taken for tests:   2.476 seconds

Total transferred:      4444778 bytes

Requests per second:    201.94 [#/sec] (mean)

Time per request:       247.602 [ms] (mean)

Time per request:       4.952 [ms] (mean, across all concurrent requests)

Transfer rate:          1753.05 [Kbytes/sec] received

Connect:        0    1   0.7      0       5

Processing:    25  236  39.3    246     282

Waiting:       22  233  39.2    243     272

Total:         26  237  38.9    246     282

WARNING: The median and mean for the initial connection time are not within a normal deviation

       These results are probably not that reliable.

 50%    246

 66%    250

 75%    252

 80%    253

 90%    257

 95%    263

 98%    269

 99%    272

100%    282 (longest request)

通過對比,PHP以FastCGI方式要比以子產品方式工作的性能要好很多;

(四)配置Memcached

Memcached是一款開源、高性能、分布式記憶體對象緩存系統,可應用各種需要緩存的場景,其主要目的是通過降低對Database的通路來加速web應用程式。它是一個基于記憶體的“鍵值對”存儲,用于存儲資料庫調用、API調用或頁面引用結果的直接資料,如字元串、對象等。

memcached是以LiveJournal旗下Danga Interactive 公司的Brad Fitzpatric 為首開發的一款軟體。現在

已成為mixi、hatena、Facebook、Vox、LiveJournal等衆多服務中提高Web應用擴充性的重要因素。

Memcached是一款開發工具,它既不是一個代碼加速器,也不是資料庫中間件。其設計哲學思想主要反映在如下方面:

1. 簡單key/value存儲:伺服器不關心資料本身的意義及結構,隻要是可序列化資料即可。存儲項由“鍵、過期時間、可選的标志及資料”四個部分組成;

2. 功能的實作一半依賴于用戶端,一半基于伺服器端:客戶負責發送存儲項至伺服器端、從服務端擷取資料以及無法連接配接至伺服器時采用相應的動作;服務端負責接收、存儲資料,并負責資料項的逾時過期;

3. 各伺服器間彼此無視:不在伺服器間進行資料同步;

4. O(1)的執行效率

5. 清理超期資料:預設情況下,Memcached是一個LRU緩存,同時,它按事先預訂的時長清理超期資料;但事實上,memcached不會删除任何已緩存資料,隻是在其過期之後不再為客戶所見;而且,memcached也不會真正按期限清理緩存,而僅是當get指令到達時檢查其時長;

memcached可以使用取餘算法和一緻性雜湊演算法來确定緩存到那台伺服器上。

取餘算法效率高,但伺服器節點變動時,會使得整個緩存系統崩潰,進而重新建構緩存,在大規模部署中很少使用;

一緻性雜湊演算法

假如在一個圓環上分布着2^32個點位,把伺服器的主機名或IP位址進行hash計算後除以2^32取餘,就得到伺服器在圓環上的位置;

資料是如何處理的?如果對mysql發起的請求為key、那麼結果為value;對mysql的key做hash運算,除以2^32取餘,得到在圓環上的點位,如果此點位上沒有memcached伺服器,它就會緩存到沿圓環的順時針方向找到的第一個memcached伺服器上。

一緻性雜湊演算法對資料的存儲時不均勻的,但可以最大限度地減少緩存的失效量。如果伺服器A當機,那麼受影響的會是從D到A這一段,其餘不受影響,大規模部署時,一定要使用一緻性雜湊演算法。

memcached的緩存對象不能大于1M,是由于其記憶體配置設定的機制決定的。它會事先對記憶體進行切片,按照增長因子進行劃分;

memcached使用基于libevent庫中epoll算法實作并行處理請求;

配置部分:

memcached官方站點:memcached.org

在RHEL 6.4 的CD光牒中有rpm包,為了一緻性,下面采用源碼安裝;

libevent至少是1.4以後的版本才會支援memcached;

memcached依賴于libevent API,是以要事先安裝之,項目首頁:http://libevent.org/,讀者可自行選擇需要的版本下載下傳。本文采用的是目前最新版本的源碼包libevent-2.0.21-stable.tar.gz。安裝過程:

# tar xf libevent-2.0.21-stable.tar.gz

# cd libevent-2.0.21

# ./configure --prefix=/usr/local/libevent

# ln -sv /usr/local/libevent/includ /usr/includ/libevent

# echo "/usr/local/libevent/lib" > /etc/ld.so.conf.d/libevent.conf

# 安裝memcached

# tar xf memcached-1.4.15.tar.gz

# cd memcached-1.4.15

# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent

# ldconfig -v | grep memcached

# cd /usr/local/memcached

# memcached的常用選項說明

-l <ip_addr>:指定程序監聽的位址;

-d: 以服務模式運作;

-u <username>:以指定的使用者身份運作memcached程序;

-m <num>:用于緩存資料的最大記憶體空間,機關為MB,預設為64MB;

-c <num>:最大支援的并發連接配接數,預設為1024;

-p <num>: 指定監聽的TCP端口,預設為11211;

-U <num>:指定監聽的UDP端口,預設為11211,0表示關閉UDP端口;

-t <threads>:用于處理入站請求的最大線程數,僅在memcached編譯時開啟了支援線程才有效;

-f <num>:設定Slab Allocator定義預先配置設定記憶體空間大小固定的塊時使用的增長因子;

-M:當記憶體空間不夠使用時傳回錯誤資訊,而不是按LRU算法利用空間;

-n: 指定最小的slab chunk大小;機關是位元組;

-S: 啟用sasl進行使用者認證;

# 啟動memcached并檢視記憶體配置設定情況

/usr/local/memcached/bin/memcached -u daemon  -f 1.1 -vvv ;按照指定的增長因子,顯示配置設定記憶體情況

-f 1.25  ; 增長因子

-u daemon;以daemon身份運作

-v ;顯示記憶體配置設定過程

-d ;背景運作;

# memcached SysV的startup腳本代碼如下所示,将其建立為/etc/init.d/memcached檔案:

#!/bin/bash

#

# Init file for memcached

# chkconfig: - 86 14

# description: Distributed memory caching daemon

# processname: memcached

# config: /etc/sysconfig/memcached

. /etc/rc.d/init.d/functions

## Default variables

PORT="11211"

USER="nobody"

MAXCONN="1024"

CACHESIZE="64"

OPTIONS=""

RETVAL=0

prog="/usr/local/memcached/bin/memcached"

desc="Distributed memory caching"

lockfile="/var/lock/subsys/memcached"

start() {

       echo -n $"Starting $desc (memcached): "

       daemon $prog -d -p $PORT -u $USER -c $MAXCONN -m $CACHESIZE

       RETVAL=$?

       [ $RETVAL -eq 0 ] && success && touch $lockfile || failure

       echo

       return $RETVAL

}

stop() {

       echo -n $"Shutting down $desc (memcached): "

       killproc $prog

       [ $RETVAL -eq 0 ] && success && rm -f $lockfile || failure

restart() {

       stop

       start

reload() {

       echo -n $"Reloading $desc ($prog): "

       killproc $prog -HUP

       [ $RETVAL -eq 0 ] && success || failure

case "$1" in

 start)

       ;;

 stop)

 restart)

       restart

 condrestart)

       [ -e $lockfile ] && restart

       ;;      

 reload)

       reload

 status)

       status $prog

  *)

       echo $"Usage: $0 {start|stop|restart|condrestart|status}"

       RETVAL=1

esac

exit $RETVAL

使用如下指令配置memcached成為系統服務:

# chmod +x /etc/init.d/memcached

# chkconfig --add memcached

# service memcached start

安裝Memcache的PHP擴充

# tar xf memcache-2.2.5.tgz

# cd memcache-2.2.5

/usr/local/php/bin/phpize

# ./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcache

上述安裝完後會有類似以下的提示:

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/

編輯/etc/php.ini,在“動态子產品”相關的位置添加如下一行來載入memcache擴充:

extension=/path/to/memcache.so  ; /path/to/就是上面安裝完成後的提示路徑

編譯安裝LAMP

而後對memcached功能進行測試,在網站目錄中建立測試頁面test.php,添加如下内容:

$mem = new Memcache;

$mem->connect("127.0.0.1", 11211)  or die("Could not connect");

$version = $mem->getVersion();

echo "Server's version: ".$version."<br/>\n";

$mem->set('hellokey', 'Hello World', 0, 600) or die("Failed to save data at the memcached server");

echo "Store data in the cache (data will expire in 600 seconds)<br/>\n";

$get_result = $mem->get('hellokey');

echo "$get_result is from memcached server.";        

如果有輸出“Hello World is from memcached.”等資訊,則表明memcache已經能夠正常工作。

編譯安裝LAMP

資料庫安裝:

本例采用二進制格式的源碼:

mysql-5.5.33-linux2.6-x86_64.tar.gz

#  tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local

# ln -sv mysql-5.5.33-linux2.6-x86_64 mysql

# cd mysql

# chown root.mysql *

本例中資料目錄在/data;

# chown mysql.mysql /data

生成配置檔案

# cp support-files/my-large.cnf /etc/my.cnf

設定PATH變量

# vi /etc/profile.d/mysql.sh

export PATH=/usr/local/mysql/bin:$PATH

使配置生效

# . /etc/profile.d/mysql.sh

導出頭檔案和庫檔案

ln -sv /usr/local/mysql/include /usr/include/mysql

vi /etc/ld.so.conf.d/mysql.conf

/usr/local/mysql/lib

初始化資料庫:

# scripts/mysql_install_db --user=mysql --datadir=/data

# cp support-files/mysql.server /etc/init.d/mysqld

修改配置檔案中pid檔案位置

vi /etc/init.d/mysqld

mysqld_pid_file_path=/var/run/mysql/mysql.pid

添加到啟動清單,并設定開機啟動

chkconfig --add mysqld

chkconfig mysqld on

service mysqld start

修改PHP伺服器上phpMyadmin的配置檔案:vi /www/magedu/com/config.inc.php

修改phpMyadmin登入MySQL的密碼:

$cfg['Servers'][$i]['host'] = '172.16.1.3';

/* User used to manipulate with storage */

$cfg['Servers'][$i]['controlhost'] = '172.16.1.3';

$cfg['Servers'][$i]['controluser'] = 'root';

$cfg['Servers'][$i]['controlpass'] = 'redhat';

上一篇: 編譯安裝LAMP
下一篇: LAMP編譯安裝