8767654r 发表于 2016-7-28 09:34:11

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、实验准备:
# iptables –F                   //关闭防火墙
#setenforce0                  //关闭SeLinux
# rpm –e httpd mod_ssl mod_perlsystem-config-httpd php php-cli php-ldap php-common php-mairadbmariadb-server          //卸载相关软件,防止冲突

3、安装开发包组,安装支持软件解决依赖关系:
#yum -y groupinstall "DevelopmentTools" "Server Platform Development"

#tar xf apr-1.5.0.tar.bz2 # ./configure --prefix=/usr/local/apr# make && make install#tar xf apr-util-1.5.2.tar.bz2#./configure --prefix=/usr/local/apr-util \> --with-apr=/usr/local/apr                                 
#make && make install# yum -y install pcre-developenssl-devellibevent-devel
4、源代码安装Apache:
a.编译httpd

# tar xf httpd-2.4.6.tar.bz2
# cd 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安装路径
# make && make install

b.添加PATH环境变量:
# vim /etc/profile.d/httpd24.sh
export PATH=/usr/local/apache/bin:$PATH
# source /etc/profile.d/httpd24.sh

c.启动服务:
# ln -sv /usr/local/apache/include/ /usr/include/httpd24
# apachectl start
# ss -tnl LISTEN   0      128                        :::80                                     :::*

5、二进制安装mariadb:
a.建立mysql用户和组
# useradd -r -M mysql
b.建立数据存放的目录
# mkdir -p /data/mydata
# chown -R mysql:mysql /data/mydata/
c.解压mariadb安装包
# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local
# ln -sv /usr/local/mariadb-5.5.46-linux-x86_64/ mysql
# chown -R root.mysql /usr/local/mysql/*
c.使用scripts脚本文件mysql_install_db文件来安装数据库
# scripts/mysql_install_db --user=mysql --datadir=/data/mydata
d.提供配置文件

# cp support-files/my-large.cnf /etc/my.cnf# vim /etc/my.cnfdatadir=/data/mydata         //指明mysql的数据存放路径innodb_file_per_table = ON   //成为独立表空间skip_name_resolve = ON       //跳过名称解析
e.提供mysql服务启动脚本

# cp mysql.server /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
f.添加环境变量
# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
# source /etc/profile.d/mysql.shg.导出头文件# ln -s /usr/local/include/ /usr/include/mysqlh.导出库文件:# vim /etc/ld.so.conf.d/mysql.confi.启动服务

# systemctl start mysqld
# ss -tnl LISTEN   0      50         *:3306   *:*   
6、源代码安装PHPa.安装开发包组及依赖关系的包# yum -y groupinstall "Development Tools" "Server Platform Development" # yum -y install bzip2-devel libmcrypt-devel libxml2-devel openssl-devel
b.编译php# tar xf php-5.4.26.tar.bz2
# cd 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# make && make installc.php提供配置文件# cp php.ini-production /etc/php.inid.提供php-fpm脚本
# 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-fpme.提供php-fpm配置文件
# cd /usr/local/php
# cp etc/php-fpm.conf.default etc/php-fpm.conff.启动服务# systemctl start php-fpm
# 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的模块# vim /etc/httpd24/httpd.confLoadModule 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 .phpsb.配置虚拟主机
# vim /etc/httpd24/extra/httpd-vhosts.conf
Directory Index index.php
<VirtualHost 172.16.251.138:80>
    DocumentRoot "/data/vhost1/www1"
    ServerNamewww1.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          Directoryindexindex.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.测试重启服务# mkdir -p /data/vhost1/www1# mkdir -p /data/vhost2/www2# apachectl -t# apachectl restart
8、配置php-fpm# vim /usr/local/php/etc/php-fpm.confpid = run/php-fpm.pid
listen.allowed_clients = 172.16.251.138
listen = 172.16.251.222:9000 # systemctl restart php-fpm.service
# ss -tnl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port            
LISTEN      0      128    172.16.251.222:9000                        *:*测试php和http之间是否正常
# mkdir -p /data/vhost1/www1
# mkdir -p /data/vhost2/www2
# vim /data/vhost1/www1/index.php
<?php
phpinfo();
?>
客户端测试httpd是否连接php-fpm:
http://www1.b.com

9、配置mariadb
a.创建授权用户
#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的链接测试
# 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:
# unzip wordpress-4.3.1-zh_CN.zip
# mv wordpress /data/vhost1/www1/
# cd /data/vhost1/www1/wordpress/
# mv wp-config-sample.php wp-config.php
# 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');#scp -r wordpress/ root@172.16.251.138:/data/vhost1/www1/
11、部署phpmyadmin:
# unzip phpMyAdmin-4.4.14.1-all-languages.zip
# mv phpMyAdmin-4.4.14.1-all-languages /data/vhost2/www2/
# ln -sv phpMyAdmin-4.4.14.1-all-languages/ phpmyadmin
# 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';# scp -r phpmyadmin/ root@172.16.251.138:/data/vhost2/www2/

12.压力测试
a.测试wordpress
# 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 (mean)
Time per request:       3.347 (mean, across all concurrentrequests)
Transfer rate:          50.76 received

b.编译安装xcache缓存加速# tar xf xcache-3.2.0.tar.bz2
# cd xcache-3.2.0/
# /usr/local/php/bin/phpize
# ./configure \> --enable-xcache --with-php-config=/usr/local/php/bin/php-config# make && make install
# cp /xcache-3.2.0/xcache.ini/etc/php.d/
# vim /etc/php.d/xcache.ini
添加:

extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so
修改下缓存大小:
xcache.size=               200M
# systemctl restart php-fpm.service

c.安装xcache后再测试
# 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 (mean)
Time per request:       0.213 (mean, across all concurrent requests)
Transfer rate:          2143.49 received

页: [1]
查看完整版本: LAMP平台部署及应用二(编译安装)