天天看點

編譯安裝LAMP及性能測試

本文轉自 jinlinger 51CTO部落格,原文連結:http://blog.51cto.com/essun/1381693總體布局如下:

類型

軟體版本

位址配置設定

功能

前台

httpd-2.4.9.tar.bz2

192.168.1.20(www.essun.com)

處理靜态頁面請求

中間層處理器

PHP-5.4.26.tar.bz2

192.168.1.10

解析腳本請求

背景業務資料

mysql-5.5.33.tar.bz2

192.168.1.30

資料檔案存儲

一,安裝httpd

前提:

必須先行安裝好httpd的與MySQL的,因為後面安裝的PHP要将這兩個軟體整合起來。

1、環境說明:

先編譯安裝的httpd

httpd的版本是2.4.9

下載下傳位址:

1

2

3

<code>#wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.9.tar.bz2</code>

<code>#wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.0.tar.bz2</code>

<code>#wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.3.tar.bz2</code>

依賴關系:

在2.4.9中在以安裝apr與apr-util包,由于http-2.4.9采用了新的資料結構,是以要安裝apr-1.5.0以後的版本與apr-util-1.5.3版本,本機在安裝好要需要的環境,要安裝兩個包組

<code># yum groupinstall -y "Development tools" "Server Platform Development"</code>

<code> </code><code># yum install pcre-devel -y</code>

2、圖解編譯過程

下載下傳之後的包

<a href="http://s3.51cto.com/wyfs02/M00/23/02/wKioL1MuHovC0O0pAABwdS2tdBY570.jpg" target="_blank"></a>

安裝APR-1.5.0.tar.bz2

<a href="http://s3.51cto.com/wyfs02/M02/23/01/wKiom1MuHtiBivjbAADFSkP0bko264.jpg" target="_blank"></a>

進入APR-1.5.0目錄編譯安裝

<code>#cd apr-1.5.0</code>

<code> </code><code>#./configure --prefix=/usr/local/apr</code>

<code> </code><code>#make &amp;&amp; make install</code>

解壓并安裝apr-util-1.5.3.tar.bz

4

<code>#tar xf apr-util-1.5.3.tar.bz2</code>

<code>   </code><code>#cd apr-util-1.5.3</code>

<code>   </code><code>#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr</code>

<code>   </code><code># make &amp;&amp; make install</code>

解壓并安裝的httpd-2.4.9

<code># tar -xf  httpd-2.4.9.tar.bz2</code>

<code># cd httpd-2.4.9</code>

<code>#./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</code>

<code>    </code><code>#make &amp;&amp; make install</code>

3、修改啟動腳本(基于RPM安裝的httpd所生成的服務腳本)

添加的PidFile檔案路徑

<code>#vim /etc/httpd24/httpd.conf</code>

<a href="http://s3.51cto.com/wyfs02/M01/23/02/wKioL1MuH4zQ-GduAABYHjeYce0270.jpg" target="_blank"></a>

此處為指定httpd服務建立的pid檔案,優先讀取配置檔案中的參數。腳本本身的定義的參數将被忽略。在配置檔案中變量是不區分大小寫的,如若指定/var/run/directory/路徑,運作應用程式的使用者必須有對/var/run有建立權限。

修改腳本檔案

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

<code>      </code><code>#!/bin/bash</code>

<code>#</code>

<code># httpd        Startup script for the Apache HTTP Server</code>

<code># chkconfig: - 85 15</code>

<code># description: The Apache HTTP Server is an efficient and extensible  \</code>

<code>#           server implementing the current HTTP standards.</code>

<code># processname: httpd</code>

<code># config: /etc/httpd/conf/httpd.conf</code>

<code># config: /etc/sysconfig/httpd</code>

<code># pidfile: /var/run/httpd/httpd.pid</code>

<code>### BEGIN INIT INFO</code>

<code># Provides: httpd</code>

<code># Required-Start: $local_fs $remote_fs $network $named</code>

<code># Required-Stop: $local_fs $remote_fs $network</code>

<code># Should-Start: distcache</code>

<code># Short-Description: start and stop Apache HTTP Server</code>

<code># Description: The Apache HTTP Server is an extensible server</code>

<code>#  implementing the current HTTP standards.</code>

<code>### END INIT INFO</code>

<code># Source function library.</code>

<code>. </code><code>/etc/rc</code><code>.d</code><code>/init</code><code>.d</code><code>/functions</code>

<code>if</code> <code>[ -f </code><code>/etc/sysconfig/httpd</code> <code>]; </code><code>then</code>

<code>        </code><code>. </code><code>/etc/sysconfig/httpd</code>

<code>fi</code>

<code># Start httpd in the C locale by default.</code>

<code>HTTPD_LANG=${HTTPD_LANG-</code><code>"C"</code><code>}</code>

<code># This will prevent initlog from swallowing up a pass-phrase prompt if</code>

<code># mod_ssl needs a pass-phrase from the user.</code>

<code>INITLOG_ARGS=</code><code>""</code>

<code># Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server</code>

<code># with the thread-based "worker" MPM; BE WARNED that some modules may not</code>

<code># work correctly with a thread-based MPM; notably PHP will refuse to start.</code>

<code># Path to the apachectl script, server binary, and short-form for messages.</code>

<code>apachectl=</code><code>/usr/local/apache/bin/apachectl</code>

<code>httpd=${HTTPD-</code><code>/usr/local/apache/bin/httpd</code><code>}</code>

<code>prog=httpd</code>

<code>pidfile=${PIDFILE-</code><code>/var/run/httpd24</code><code>.pid}</code>

<code>lockfile=${LOCKFILE-</code><code>/var/lock/subsys/httpd24</code><code>}</code>

<code>RETVAL=0</code>

<code>STOP_TIMEOUT=${STOP_TIMEOUT-10}</code>

<code># The semantics of these two functions differ from the way apachectl does</code>

<code># things -- attempting to start while running is a failure, and shutdown</code>

<code># when not running is also a failure.  So we just do it the way init scripts</code>

<code># are expected to behave here.</code>

<code>start() {</code>

<code>        </code><code>echo</code> <code>-n $</code><code>"Starting $prog: "</code>

<code>        </code><code>LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS</code>

<code>        </code><code>RETVAL=$?</code>

<code>        </code><code>echo</code>

<code>        </code><code>[ $RETVAL = 0 ] &amp;&amp; </code><code>touch</code> <code>${lockfile}</code>

<code>        </code><code>return</code> <code>$RETVAL</code>

<code>}</code>

<code># When stopping httpd, a delay (of default 10 second) is required</code>

<code># before SIGKILLing the httpd parent; this gives enough time for the</code>

<code># httpd parent to SIGKILL any errant children.</code>

<code>stop() {</code>

<code>    </code><code>echo</code> <code>-n $</code><code>"Stopping $prog: "</code>

<code>    </code><code>killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd</code>

<code>    </code><code>RETVAL=$?</code>

<code>    </code><code>echo</code>

<code>    </code><code>[ $RETVAL = 0 ] &amp;&amp; </code><code>rm</code> <code>-f ${lockfile} ${pidfile}</code>

<code>reload() {</code>

<code>    </code><code>echo</code> <code>-n $</code><code>"Reloading $prog: "</code>

<code>    </code><code>if</code> <code>! LANG=$HTTPD_LANG $httpd $OPTIONS -t &gt;&amp;</code><code>/dev/null</code><code>; </code><code>then</code>

<code>        </code><code>RETVAL=6</code>

<code>        </code><code>echo</code> <code>$</code><code>"not reloading due to configuration syntax error"</code>

<code>        </code><code>failure $</code><code>"not reloading $httpd due to configuration syntax error"</code>

<code>    </code><code>else</code>

<code>        </code><code># Force LSB behaviour from killproc</code>

<code>        </code><code>LSB=1 killproc -p ${pidfile} $httpd -HUP</code>

<code>        </code><code>if</code> <code>[ $RETVAL -</code><code>eq</code> <code>7 ]; </code><code>then</code>

<code>            </code><code>failure $</code><code>"httpd shutdown"</code>

<code>        </code><code>fi</code>

<code>    </code><code>fi</code>

<code># See how we were called.</code>

<code>case</code> <code>"$1"</code> <code>in</code>

<code>  </code><code>start)</code>

<code>    </code><code>start</code>

<code>    </code><code>;;</code>

<code>  </code><code>stop)</code>

<code>    </code><code>stop</code>

<code>  </code><code>status)</code>

<code>        </code><code>status -p ${pidfile} $httpd</code>

<code>  </code><code>restart)</code>

<code>  </code><code>condrestart|try-restart)</code>

<code>    </code><code>if</code> <code>status -p ${pidfile} $httpd &gt;&amp;</code><code>/dev/null</code><code>; </code><code>then</code>

<code>        </code><code>stop</code>

<code>        </code><code>start</code>

<code>  </code><code>force-reload|reload)</code>

<code>        </code><code>reload</code>

<code>  </code><code>graceful|help|configtest|fullstatus)</code>

<code>    </code><code>$apachectl $@</code>

<code>  </code><code>*)</code>

<code>    </code><code>echo</code> <code>$</code><code>"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"</code>

<code>    </code><code>RETVAL=2</code>

<code>esac</code>

<code>exit</code> <code>$RETVAL</code>

4、添加到啟動隊列中

<code>#chmod +x /etc/init.d/httpd24</code>

<a href="http://s3.51cto.com/wyfs02/M01/23/01/wKiom1MuKQuijq8zAAHajvYEbi8497.jpg" target="_blank"></a>

5、啟用httpd的相關子產品

在Apache httpd 2.4以後已經專門有一個子產品針對FastCGI的實作,此子產品為mod_proxy_fcgi.so,它其實是作為mod_proxy.so子產品的擴充,是以,這兩個子產品都要加載

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

以上兩個子產品可以在httpd.conf中動态加載

6、配置虛拟主機支援使用fcgi

LoadModule vhost_alias_module modules/mod_vhost_alias.so

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

7、在相應的虛拟主機中添加類似如下。

<code>#vim /etc/httpd24/extra/httpd-vhosts.conf</code>

<a href="http://s3.51cto.com/wyfs02/M00/23/02/wKioL1MuKXmCqi-RAAM9kfTwADQ728.jpg" target="_blank"></a>

ProxyRequests Off:關閉正向代理

ProxyPassMatch:把以.php結尾的檔案請求發送到php-fpm程序,php-fpm至少需要知道運作的目錄和URI,是以這裡直接在fcgi://192.168.1.20:9000後指明了這兩個參數,其它的參數的傳遞已經被mod_proxy_fcgi.so進行了封裝,不需要手動指定。

8、編輯apache配置檔案httpd.conf,讓apache能識别php格式的頁面,并支援php格式的首頁

<a href="http://s3.51cto.com/wyfs02/M01/23/01/wKiom1MuKdaBGt7DAACLuMN99ic927.jpg" target="_blank"></a>

9、定位至DirectoryIndex index.html

  修改為:

   #DirectoryIndex  index.php  index.html

=========================================到此httpd編譯安裝完成==========================

二、安裝mysql

1、準備資料存放的檔案系統

建立一個邏輯卷,并将其挂載至特定目錄即可。邏輯卷的挂載目錄為/mydata,而後需要建立/mydata/data目錄做為mysql資料的存放目錄。

<a href="http://s3.51cto.com/wyfs02/M00/23/02/wKioL1MuKi-SWFS2AALnevJUKf4016.jpg" target="_blank"></a>

格式化、挂載到己經建立的目錄上

<a href="http://s3.51cto.com/wyfs02/M02/23/01/wKiom1MuKnuTQ3OnAAF2aYFKAcY192.jpg" target="_blank"></a>

檢視挂載(mount)

<a href="http://s3.51cto.com/wyfs02/M01/23/02/wKioL1MuKnnCTbJiAAJagsm-RzA292.jpg" target="_blank"></a>

将卷挂載到目錄/mydata之後,建立一個目錄(data)用于存放資料檔案

2、建立一個使用者,在一個安全的環境中運作

<code># groupadd -r mysql</code>

<code># useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql</code>

<code># chown -R mysql:mysql /mydata/data</code>

3、解壓、編譯

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

<code> </code><code>#cd /usr/local/</code>

<code> </code><code># ln -s mysql-5.5.33-linux2.6-x86_64 mysql</code>

<code> </code><code>#cd mysql</code>

<code># chown -R mysql.mysql .</code>

<code> </code><code># scripts/mysql_install_db --user=mysql --datadir=/mydata/data</code>

<code>#chown -R root .</code>

4、為mysql提供主配置檔案:

<code># cd /usr/local/mysql</code>

<code># cp support-files/my-large.cnf  /etc/my.cnf</code>

并修改此檔案中thread_concurrency的值為你的CPU個數乘以2,比如這裡使用如下行:

thread_concurrency = 4

另外還需要添加如下行指定mysql資料檔案的存放位置:

datadir = /mydata/data

5、為服務添加腳本

<a href="http://s3.51cto.com/wyfs02/M00/23/01/wKiom1MuK9-yKaELAAL2cGSEbBY684.jpg" target="_blank"></a>

6、為了使用mysql的安裝符合系統使用規範,并将其開發元件導出給系統使用,這裡還需要進行如下步驟:

導出man幫助手冊

<code>#echo 'MANPATH /usr/local/mysql/man' &gt;&gt;/etc/man.config</code>

連結頭檔案

<code>#ln -s include /usr/include/mysql</code>

指定庫檔案

<code>#echo '/usr/local/mysql/lib' &gt; /etc/ld.so.conf.d/mysql.conf</code>

<code> </code><code>#ldconfig</code>

導入二進制檔案

<code>#echo 'export PATH=/usr/local/mysql/bin:$PATH' &gt;/etc/profile.d/mysql.sh</code>

<code># . /etc/profile.d/mysql.sh</code>

============================================到此安裝完成 mysql============================

三、安裝php

1、下載下傳位址:

<code>#wget http:</code><code>//am1.php.net/distributions/php-5.4.26.tar.bz2</code>

2、安裝流程

./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  --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts

注:

今天下午安裝 php 5.4.26的時候出現了一個錯誤,是關于libxml2 configure: error: xml2-config not found. Please check your libxml2 installation.

系統 centos 6.5 X64

我首先檢視 有沒有安裝libxml2

[root@station114 php-5.4.26]# rpm -ql  libxml2

/usr/bin/xmlcatalog

/usr/bin/xmllint

/usr/lib64/libxml2.so.2

/usr/lib64/libxml2.so.2.7.6

/usr/share/doc/libxml2-2.7.6

/usr/share/doc/libxml2-2.7.6/AUTHORS

/usr/share/doc/libxml2-2.7.6/ChangeLog.gz

/usr/share/doc/libxml2-2.7.6/Copyright

/usr/share/doc/libxml2-2.7.6/NEWS

/usr/share/doc/libxml2-2.7.6/README

/usr/share/doc/libxml2-2.7.6/TODO

/usr/share/man/man1/xmlcatalog.1.gz

/usr/share/man/man1/xmllint.1.gz

/usr/share/man/man3/libxml.3.gz

安裝了,可是不好使,廢話少說,直接上源碼的

#wget http://xmlsoft.org/sources/libxml2-2.9.0.tar.gz

#tar xf libxml2-29.0.tar.gz

#cd libxml2-2.9.0

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

#make &amp;&amp; make install

此過程可能會出現各種警告,請自行忽略

重新編譯

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

<code>#make</code>

<code>#make install</code>

<a href="http://s3.51cto.com/wyfs02/M01/23/02/wKioL1MuLbezA_AFAAKM_LHv18U148.jpg" target="_blank"></a>

3、修改配置檔案

<code># cp php.ini-production /etc/php.ini</code>

4、配置php-fpm

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

<code>cd</code> <code>php-5.4.26</code>

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

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

<code># chkconfig --add php-fpm</code>

<code># chkconfig php-fpm on</code>

<a href="http://s3.51cto.com/wyfs02/M00/23/01/wKiom1MuLnKji68YAACF1BN01Lw927.jpg" target="_blank"></a>

5、為php-fpm提供配置檔案:

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

編輯php-fpm的配置檔案:

<code># vim /usr/local/php/etc/php-fpm.conf</code>

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

<a href="http://s3.51cto.com/wyfs02/M02/23/02/wKioL1MuLnChJofXAAHZG9_Hk-E610.jpg" target="_blank"></a>

本次實驗用的到參數說明

<a href="http://s3.51cto.com/wyfs02/M01/23/01/wKiom1MuLq2iaAadAAI6Wux3rG0739.jpg" target="_blank"></a>

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

<code># service php-fpm start</code>

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

<code>#ss -tunl |grep ":9000"</code>

<a href="http://s3.51cto.com/wyfs02/M01/23/02/wKioL1MuLtewDrCOAABkh6Mgrzg436.jpg" target="_blank"></a>

此次實驗所使用的位址與端口

8、而後重新啟動httpd,或讓其重新載入配置檔案即可測試php是否已經可以正常使用。

在192.168.1.10上的/www/essun.com/

#vim index.php

測試頁面index.php示例如下

<code>&lt;?php</code>

<code>     </code><code>$link</code> <code>= mysql_connect(</code><code>'192.168.1.30'</code><code>,</code><code>'root'</code><code>,</code><code>'mysql'</code><code>);</code>

<code>     </code><code>if</code> <code>(</code><code>$link</code><code>)</code>

<code>       </code><code>echo</code> <code>"Success..."</code><code>;</code>

<code>     </code><code>else</code>

<code>       </code><code>echo</code> <code>"Failure..."</code><code>;</code>

<code>     </code><code>mysql_close();</code>

<code>   </code><code>?&gt;</code>

測試結果

<a href="http://s3.51cto.com/wyfs02/M01/23/01/wKiom1MuL27zq7A4AABCKQertO8794.jpg" target="_blank"></a>

證明與mysql連接配接成功。

下面将使用phpMyAdmin-4.0.5-all-languages連接配接管理資料,同時對此站點進行壓力測試

将下載下傳後的包放到192.168.1.10php處理器的站點目錄中

<code>#wget    http://ncu.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.0.10/phpMyAdmin-4.0.10-all-languages.zip</code>

<code># unzip  phpMyAdmin-4.0.10-all-languages.zip</code>

<code> </code><code>#cd phpMyAdmin-4.0.10-all-languages</code>

<code> </code><code>#mv * /www/essun.com/</code>

<a href="http://s3.51cto.com/wyfs02/M00/23/01/wKiom1MuL-XxvcaDAAHqffJSvtI832.jpg" target="_blank"></a>

對其壓力測試

<code>#ab -c 100 -n 1000 http://essun.com/</code>

<a href="http://s3.51cto.com/wyfs02/M01/23/01/wKiom1MuMCaRlsqMAAMLbOLu3C8182.jpg" target="_blank"></a>

四、安裝xcache,為php加速

1、下載下傳位址

<code>#wget http://xcache.lighttpd.net/pub/Releases/3.1.0/xcache-3.1.0.tar.bz2</code>

2、編譯安裝

<code># tar xf xcache-3.0.3.tar.gz</code>

<code># cd xcache-3.0.3</code>

<code># /usr/local/php/bin/phpize</code>

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

<code># make &amp;&amp; make install</code>

<a href="http://s3.51cto.com/wyfs02/M01/23/02/wKioL1MuMSHCFfKHAAEq7iaP0f0033.jpg" target="_blank"></a>

将編譯生成的shared extensions後面的資料寫入配置檔案中,

找到zend_extension開頭的行,修改為如下行:

zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

注意:如果php.ini檔案中有多條zend_extension指令行,要確定此新增的行排在第一位

<a href="http://s3.51cto.com/wyfs02/M00/23/02/wKioL1MuMbaz9XFFAAD-GIK3dJY431.jpg" target="_blank"></a>

檢視xcache是否安裝成功

在/www/esun.com/下建立一個目錄為test,在其下測試頁面

<code>phpinfo();</code>

<code>?&gt;</code>

結果是

<a href="http://s3.51cto.com/wyfs02/M02/23/03/wKioL1MuMm3Rpar4AAHh1QRscMc635.jpg" target="_blank"></a>

安裝XCache成功

再次測試:

<a href="http://s3.51cto.com/wyfs02/M01/23/03/wKioL1MuMqLwqthMAAJrRRaKtqQ052.jpg" target="_blank"></a>

明顯比上一次測試響應的要快的多

==========================================到此LAMP編譯與性能測試完成======================,如需轉載請自行聯系原作者