LAMP平臺部署及應用二(編譯安裝)

1、實驗環境:
Linux服務器操作系統版本:CentOS 7.2
http               IP: 172.16.251.138

httpd-2.4.6.tar      apr-util-1.5.2.tar  

wordpress-4.3.1-zh_CN    apr-1.5.0.tar

phpMyAdmin-4.4.14.1-all-languages
php-fpm            IP:172.16.251.222

xcache-3.1.0.tar        php-5.4.26.tar 

mariadb            IP:172.16.251.188

mariadb-5.5.46-linux-x86_64.tar (二進制包)

客戶端             IP:172.16.251.164


2、實驗準備:

[root@station138 ~]# iptables –F                   //關閉防火牆

[root@station138 ~]#setenforce0                  //關閉SeLinux

[root@station138 ~]# rpm –e httpd mod_ssl mod_perlsystem-config-httpd php php-cli php-ldap php-common php-mairadb  mariadb-server          //卸載相關軟件,防止衝突


3、安裝開發包組,安裝支持軟件解決依賴關係:

[root@station138 ~]#yum -y groupinstall "Development Tools" "Server Platform Development"

[root@station138 ~]#tar xf apr-1.5.0.tar.bz2 

[root@station138 apr-1.5.0]# ./configure --prefix=/usr/local/apr

[root@station138 apr-1.5.0]# make && make install

[root@station138 ~]#tar xf apr-util-1.5.2.tar.bz2

[root@station138 apr-util-1.5.2]#./configure --prefix=/usr/local/apr-util \

> --with-apr=/usr/local/apr                                 

[root@station138 apr-util-1.5.2]#make && make install

[root@station138 ~]# yum -y install pcre-devel  openssl-devel  libevent-devel


4、源代碼安裝Apache:

a.編譯httpd

[root@station138 ~]# tar xf httpd-2.4.6.tar.bz2 
[root@station138 ~]# cd httpd-2.4.6/
[root@station138 httpd-2.4.6]# ./configure \
> --prefix=/usr/local/apache          //安裝路徑
> --sysconfdir=/etc/httpd24          //配置文件路徑
> --enable-so   //支持動態裝卸載DSO機制,DSO是動態共享對象,可實現模塊動態生效
> --enable-ssl  //支持SSL/TLS 可實現https功能,需要安裝openssl-devel開發工具
> --enable-cgi  //支持CGI腳本 默認對非線程的MPM(多路處理)模塊開啓

> --enable-rewrite          //支持URL重寫

> --enable-defalte          //支持壓縮功能
> --enable-modules=most     //支持動態啓用的模塊 {all|most}
> --enable-mpms-shared=all  //支持動態加載的MPM模塊 {most|all}
> --with-mpm=prefork        //設置默認啓用的mpm模式 {prefork|worker|event}
> --with-pcre               //使用指定的pcre庫,需要安裝pcre-devel工具
> --with-zlib               //使用指定的zlib庫
> --with-apr=/usr/local/apr  //指定apr安裝路徑
> --with-apr-util=/usr/local/apr-util  //指定apr-util安裝路徑

[root@station138 httpd-2.4.6]# make && make install

b.添加PATH環境變量:

[root@station138 ~]# vim /etc/profile.d/httpd24.sh 

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

[root@station138 ~]# source /etc/profile.d/httpd24.sh

c.啓動服務:

[root@station138 ~]# ln -sv /usr/local/apache/include/ /usr/include/httpd24

[root@station138 ~]# apachectl start 

[root@station138 ~]# ss -tnl 

LISTEN     0      128                        :::80                                     :::*


5、二進制安裝mariadb:

a.建立mysql用戶和組

[root@station188 ~]# useradd -r -M mysql

b.建立數據存放的目錄

[root@station188 ~]# mkdir -p /data/mydata

[root@station188 ~]# chown -R mysql:mysql /data/mydata/

c.解壓mariadb安裝包

[root@station188 ~]# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local

[root@station188 ~]# ln -sv /usr/local/mariadb-5.5.46-linux-x86_64/ mysql 

[root@station188 ~]# chown -R root.mysql /usr/local/mysql/*

c.使用scripts腳本文件mysql_install_db文件來安裝數據庫

[root@station188 mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mydata

d.提供配置文件

[root@station188 mysql]# cp support-files/my-large.cnf /etc/my.cnf

[root@station188 mysql]# vim /etc/my.cnf

datadir=/data/mydata         //指明mysql的數據存放路徑

innodb_file_per_table = ON   //成爲獨立表空間

skip_name_resolve = ON       //跳過名稱解析

e.提供mysql服務啓動腳本

[root@station188 support-files]# cp mysql.server /etc/rc.d/init.d/mysqld  
[root@station188 support-files]# chkconfig --add mysqld

f.添加環境變量

[root@station188 ~]# vim /etc/profile.d/mysql.sh 
export PATH=/usr/local/mysql/bin:$PATH

[root@station188 ~]# source /etc/profile.d/mysql.sh

g.導出頭文件

[root@station188 ~]# ln -s /usr/local/include/ /usr/include/mysql

h.導出庫文件:

[root@station188 ~]# vim /etc/ld.so.conf.d/mysql.conf

i.啓動服務

[root@station188 ~]# systemctl start mysqld 

[root@station188 ~]# ss -tnl 

LISTEN     0      50           *:3306     *:*   


6、源代碼安裝PHP

a.安裝開發包組及依賴關係的包

[root@station222 ~]# yum -y groupinstall "Development Tools" "Server Platform Development" 

[root@station222 ~]# yum -y install bzip2-devel libmcrypt-devel libxml2-devel openssl-devel

b.編譯php

[root@station222 ~]# tar xf php-5.4.26.tar.bz2 
[root@station222 ~]# cd php-5.4.26/

[root@station222 php-5.4.26]# ./configure\

 --prefix=/usr/local/php --with-openssl --with-mysql=mysqlnd

 --with-pdo-mysql=mysqlnd --with-mysql=mysqlnd --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

[root@station222 php-5.4.26]# make && make install

c.php提供配置文件

[root@station222 php-5.4.26]# cp php.ini-production /etc/php.ini

d.提供php-fpm腳本

[root@station222 php-5.4.26]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@station222 php-5.4.26]# chmod +x /etc/rc.d/init.d/php-fpm 

[root@station222 php-5.4.26]# chkconfig --add php-fpm

e.提供php-fpm配置文件

[root@station222 php-5.4.26]# cd /usr/local/php

[root@station222 php-5.4.26]# cp etc/php-fpm.conf.default etc/php-fpm.conf

f.啓動服務

[root@station222 php-5.4.26]# systemctl start php-fpm
[root@station222 php-5.4.26]# ss -tnl 
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              

LISTEN      0      128       127.0.0.1:9000                          *:*


7、httpd配置

a.支持fastFCGI的模塊

[root@station138 ~]# vim /etc/httpd24/httpd.conf

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

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

AddType application/x-httpd-php .php

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

b.配置虛擬主機

[root@station138 ~]# vim /etc/httpd24/extra/httpd-vhosts.conf
Directory Index index.php
<VirtualHost 172.16.251.138:80>
    DocumentRoot "/data/vhost1/www1"
    ServerName  www1.b.com

    ProxyRequests off

        Directoryindex index.php

    ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.251.222:9000/data/vhost1/www1/$1
   <Directory "/data/vhost1/www1">
        Options None
        AllowOverride None
        Require all granted
   </Directory>
</VirtualHost>
 
<VirtualHost 172.16.251.138:80>
    DocumentRoot "/data/vhost2/www2"
    ServerName www2.b.com

    ProxyRequests off

          Directoryindex index.php

    ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.251.222:9000/data/vhost2/www2/$1
     <Directory "/data/vhost2/www2">
         Options None
         AllowOverride None
         Require all granted
     </Directory>

</VirtualHost>

c.測試重啓服務

[root@station138 ~]# mkdir -p /data/vhost1/www1

[root@station138 ~]# mkdir -p /data/vhost2/www2

[root@station138 ~]# apachectl -t

[root@station138 ~]# apachectl restart 


8、配置php-fpm

[root@station222 ~]# vim /usr/local/php/etc/php-fpm.conf

pid = run/php-fpm.pid  
listen.allowed_clients = 172.16.251.138

listen = 172.16.251.222:9000 

[root@station222 ~]# systemctl restart php-fpm.service 
[root@station222 ~]# ss -tnl 
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              

LISTEN      0      128    172.16.251.222:9000                          *:*

測試php和http之間是否正常

[root@station222 ~]# mkdir -p /data/vhost1/www1
[root@station222 ~]# mkdir -p /data/vhost2/www2

[root@station222 ~]# vim /data/vhost1/www1/index.php
<?php
phpinfo();
?>

客戶端測試httpd是否連接php-fpm:

http://www1.b.com


9、配置mariadb

a.創建授權用戶

[root@station188 ~]#mysql -uroot -p

MariaDB [(none)]> create database wpdb;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on wpdb.* to 'wpuser'@'172.16.%.%' identified by 'wp123';
Query OK, 0 rows affected (0.03 sec)
MariaDB [(none)]> create database pma;  
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> grant all on pma.* to 'pmauser'@'172.16.%.%' identified by 'pma123';
Query OK, 0 rows affected (0.00 sec)

b.Php和mysql的鏈接測試

[root@station222 ~]# vim /data/vhost1/www1/index.php 

<?php
$conn = mysql_connect('172.16.251.188','wpuser','wp123');
        if ($conn)
                echo "ok";
        else
                echo "no";
?>

客戶端測試php是否連接mysql:

http://www1.b.com


10、部署WordPress:

[root@station222 ~]# unzip wordpress-4.3.1-zh_CN.zip 
[root@station222 ~]# mv wordpress /data/vhost1/www1/
[root@station222 ~]# cd /data/vhost1/www1/wordpress/
[root@station222 wordpress]# mv wp-config-sample.php wp-config.php 
[root@station222 wordpress]# vim wp-config.php 
/** WordPress數據庫的名稱 */
define('DB_NAME', 'wpdb');
/** MySQL數據庫用戶名 */
define('DB_USER', 'wpuser');
/** MySQL數據庫密碼 */
define('DB_PASSWORD', 'wp123');
/** MySQL主機 */

define('DB_HOST', '172.16.251.188');

[root@station222 www1]#scp -r wordpress/ root@172.16.251.138:/data/vhost1/www1/


11、部署phpmyadmin:

[root@station222 ~]# unzip phpMyAdmin-4.4.14.1-all-languages.zip
[root@station222 ~]# mv phpMyAdmin-4.4.14.1-all-languages /data/vhost2/www2/
[root@station222 www2]# ln -sv phpMyAdmin-4.4.14.1-all-languages/ phpmyadmin
[root@station222 www2]# vim phpmyadmin/libraries/config.default.php
$cfg['blowfish_secret'] = 'tSQRO02T+grA6rvJHCXr';
$cfg['Servers'][$i]['host'] = '172.16.251.188'; 
$cfg['Servers'][$i]['user'] = 'pmauser';

$cfg['Servers'][$i]['password'] = 'pma123';

[root@station222 www2]# scp -r phpmyadmin/ root@172.16.251.138:/data/vhost2/www2/



12.壓力測試

a.測試wordpress

[root@station222 ~]# ab -c 100 -n 1000 http://www1.b.com/wordpress

Concurrency Level:      100

Time taken for tests:   3.347 seconds

Completerequests:      1000                                                

Failed requests:        0

Write errors:           0

Total transferred:      174000 bytes

HTML transferred:       2000 bytes

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

Time per request:       334.730 [ms] (mean)

Time per request:       3.347 [ms] (mean, across all concurrentrequests)

Transfer rate:          50.76 [Kbytes/sec] received

b.編譯安裝xcache緩存加速

[root@station222 ~]# tar xf xcache-3.2.0.tar.bz2 
[root@station222 ~]# cd xcache-3.2.0/
[root@station222 xcache-3.2.0]# /usr/local/php/bin/phpize

[root@station222 xcache-3.2.0]# ./configure \

> --enable-xcache --with-php-config=/usr/local/php/bin/php-config

[root@station222 xcache-3.2.0]# make && make install
[root@station222 ~]# cp /xcache-3.2.0/xcache.ini  /etc/php.d/
[root@station222 ~]# vim /etc/php.d/xcache.ini 
添加:
[xcache-common]
extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so
修改下緩存大小:
xcache.size  =               200M

[root@station222 ~]# systemctl restart php-fpm.service

c.安裝xcache後再測試

[root@station222 ~]# ab -c 100 -n 1000 http://www1.b.com/wordpress

Concurrency Level:      100
Time taken for tests:   2.128 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Non-2xx responses:      1000
Total transferred:      4670000 bytes
HTML transferred:       2390000 bytes
Requests per second:    4700.07 [#/sec] (mean)
Time per request:       212.763 [ms] (mean)
Time per request:       0.213 [ms] (mean, across all concurrent requests)
Transfer rate:          2143.49 [Kbytes/sec] received



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章