friht 发表于 2018-12-12 07:26:50

LAMP实例——在CentOS7使用xcache和php

  一、使用php module方式部署AMP+xcache
  1.在主机(192.168.109.136)使用rpm包方式安装httpd、php、mariadb-server、php-mysql(略),之后开启mariadb服务

  此时在/etc/httpd/conf.modules.d/目录下有文件10-php.conf,里面记录了需要加载的php模块信息为libphp5.so文件,这时php就通过模块方式与httpd进行链接。

  2.配置一个虚拟主机,配置文件/etc/httpd/conf.d/vhost2.conf文件如下:

    ServerName www.ppp213.cn
    DocumentRoot "/myvhost/vhost2"
   
      Options None
      AllowOverride None
      Require all granted
   
  3.配置一个虚拟主机,并为其设置https服务,方法:http://blog.运维网.com/papapa213/2108143 ,之后需对/etc/httpd/conf.d/ssl.conf文件做如下修改:
........

DocumentRoot "/myvhost/vhost1"
ServerName www.ppp213.edu:443
   
      AllowOverride None
      Require all granted
   
......
SSLCertificateFile /etc/httpd/ssl/httpd.crt         //证书文件路径
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key      //私钥路径
......  

  4.创建/myvhost/vhost1、/myvhost/vhost2目录,可以按照http://blog.运维网.com/papapa213/2112852 中的方法将phpMyAdmin和wordpress分别部署进vhost1与vhost2中,此时分别进行链接,得到返回结果则说明成功配置。
http://s1.运维网.com/images/20180510/1525962116393360.png
http://s1.运维网.com/images/20180510/1525962171610898.png
  

  在另一台主机使用ab指令进行测试:

  ab -c 100 -n 1000 https://192.168.109.136/index.php
  ab -c 100 -n 1000 http://192.168.109.136:8000/index.php
  分别得到如下结果:

http://s1.运维网.com/images/20180510/1525962721530898.png
http://s1.运维网.com/images/20180510/1525962739147808.png
  5.配置php-xcache

  使用rpm包安装php-xcache需要自行配置epel源,在/etc/yum.repo.d/CentOS-Base.repo文件中添加如下几行:


name=CentOS-$releasever - Epel
baseurl=http://mirrors.sohu.com/fedora-epel/$releasever/$basearch/
gpgcheck=0  

  之后使用yum clean all ; yum makecache命令重读缓存,此时可以使用yum直接安装php-xcache

  

  重新载入httpd,再次访问主机,可以看到有XCache相关参数:

http://s1.运维网.com/images/20180510/1525963810454818.png
  此时再次用另一台主机使用ab命令进行测试:

http://s1.运维网.com/images/20180510/1525964001877622.png
http://s1.运维网.com/images/20180510/1525963965864356.png
  没有看到加速效果,这有可能是因为使用rpm包安装的xcache版本不兼容所致,后面会使用编译安装的方式来进行xcache的安装部署。

  二、使用php-fpm的方式部署AMP
  1.在主机(192.168.109.5)上使用rpm包安装httpd,在主机(192.168.109.136)上卸载php包,并安装php-fpm包

  2.在主机(192.168.109.136)上如下修改配置文件/etc/php-fpm.d/www.conf
listen=9000
listen.allowed_clients=192.168.109.5  并开启php-fpm服务

  3.在主机(192.168.109.5)上配置/etc/httpd/conf.d/vhost1.conf、/etc/httpd/conf.d/vhost2.conf

      ServerName www.ppp213.net
      ProxyRequests Off
      #使用ProxyPassMatch可以使用正则表达式进行匹配固定后缀的文件名
      ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.109.136:9000/myvhost/vhost1/$1

      ServerName www.ppp213.org
      ProxyRequests Off
      ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.109.136:9000/myvhost/vhost2/$1
  开启httpd服务

  4.此时通过192.168.109.5进行访问,即可访问到192.168.109.136上配置好的资源

http://s1.运维网.com/images/20180511/1526010140926554.png
http://s1.运维网.com/images/20180511/1526010268174514.png
  

  三、编译安装httpd、PHP、mariadb和xcache
  使用编译安装的方式在(192.168.109.5)上安装以上服务,首先卸载之前安装好的httpd

  1.获取源代码

  Apache:http://httpd.apache.org(2.4.27)

  Mariadb:https://mariadb.org/download/ (5.5.57)
  PHP:www.php.net(5.6.31)

  2.配置开发环境
  yum groupinstall "Development Tools" "Server Platform Development"
  3.编译安装httpd-2.4.27

  1)编译安装apr

http://s1.运维网.com/images/20180511/1526014664660173.png
  

http://s1.运维网.com/images/20180511/1526014733129448.png
  

http://s1.运维网.com/images/20180511/1526014809353601.png
  2)编译安装apr-util

http://s1.运维网.com/images/20180511/1526014944208496.png
http://s1.运维网.com/images/20180511/1526014992140618.png
  

  

  3)编译安装httpd
tar xf httpd-2.4.27.tar.bz2
cd httpd-2.4.27/  此时可以使用./configure --help 查看帮助文档

  ./configure --prefix=/usr/local/apache-2427 --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-apr=/usr/local/apr-152 --with-apr-util=/usr/local/apr-util-154 --with-zlib --with-pcre --with-mpm=event
  开始编译安装:   

  make -j 4 && make install

  

http://s1.运维网.com/images/20180511/1526016326251191.png
  

  安装完成后进行收尾工作

  ①导出二进制文件:

  创建/etc/profile.d/httpd24.sh

  export PATH=/usr/local/apache-2427/bin:$PATH
  之后使用source命令使其生效

  ②导出头文件:
  ln -sv /usr/local/apache-2427/include/ /usr/include/httpd/
  ③在/etc/httpd24/httpd.conf中添加:

  PidFile /var/run/httpd.pid
  此时可以使用apachectl start命令启动httpd服务:

http://s1.运维网.com/images/20180511/1526017539392373.png
  在其他主机进行测试:

http://s1.运维网.com/images/20180511/1526017700746480.png
  

  4.安装mariadb

  1)解压缩二进制程序包并创建用于启动服务和管理数据的用户和组:

http://s1.运维网.com/images/20180511/1526018109415748.png
  2)创建相应目录并修改权限:

http://s1.运维网.com/images/20180511/1526018151689239.png
  

  之后在/etc/my.cnf添加内容:
  datadir = /mydata/data
  innodb_file_per_table = ON
  skip_name_resolve = ON
  创建启动脚本:

http://s1.运维网.com/images/20180511/1526018436242988.png
  3)导出二进制文件

  创建/etc/profile.d/mariadb5557.sh文件内容如下:
  export PATH=/usr/local/mysql/bin:$PATH
  

  4)导出头文件

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

  5)导出库文件:   

  创建 /etc/ld.so.conf.d/mariadb5557.conf文件内容如下:

  /usr/local/mysql/lib

  ldconfig -v

  6)初始化数据库

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

  

  7)启动服务:
  service mysqld start

http://s1.运维网.com/images/20180511/1526019343241435.png
  5.编译安装php

  想要正确编译php-5.6.31,可能需要解决下列依赖关系

  libxml2-devel gd-level freetype-devel libmcrypt-devel

  (待补充)

  6.编译安装xcache:

  解压xcache包后,里面并没有configure文件,此时需要使用phpize工具来生成,可以通过安装php-devel包获得phpize工具,之后在xcache目录下执行phpize,便可获得configure文件,此时即可进行编译安装

http://s1.运维网.com/images/20180511/1526022668801907.png
  

http://s1.运维网.com/images/20180511/1526022728245835.png
http://s1.运维网.com/images/20180511/1526022763444762.png
  最后可以看到编译生成的xcache模块:

http://s1.运维网.com/images/20180511/1526022807911493.png
  将xcache目录下xcache.ini文件复制到/etc/php.d目录下:

http://s1.运维网.com/images/20180511/1526022929235231.png
  之后修改/etc/php.d/xcache.ini文件,将xcache.so模块文件的路径修正。

  

  此时重启php-fpm服务,访问站点,可以看到xcache模块被载入

http://s1.运维网.com/images/20180511/1526024195155013.png



页: [1]
查看完整版本: LAMP实例——在CentOS7使用xcache和php