LAMP平台(分布式)构建


前提环境准备
1.准备三台虚拟机

主机名IP
http192.168.229.138
mysql192.168.229.140
php192.168.229.141

2.关闭防火墙和selinux

systemctl stop firewalld
setenforce 0

3.三台主机设置域名解析

[root@localhost ~]# vim /etc/hosts
192.168.229.138 http
192.168.229.140 mysql
192.168.229.141 php

一、编译安装httpd

为了方便区分,可以修改主机名

[root@localhost ~]# hostname http
[root@localhost ~]# bash

1.检查是否已安装rpm包httpd

[root@http ~]# rpm -q httpd \\查看是否安装
[root@http ~]# rpm -e httpd --nodeps \\卸载已安装的程序并且忽略依赖。

2.安装前提软件

[root@http ~]# yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel

把所需要的软件包移动到/usr/src目录下或直接下载到虚拟机,然后进行前提软件安装的脚本编写,所需软件包为:apr-1.5.2.tar.gz、apr-util-1.5.4.tar.gz、pcre-8.39.tar.gz、openssl-1.0.1u.tar.gz、zlib-1.2.8.tar.gz、httpd-2.4.25.tar.gz

[root@http ~]# mkdir /sh
[root@http ~]# cd /sh
[root@http sh]# vim qianti.sh
#!/bin/bash
cd /usr/src
tar zxf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr && make && make install

cd ..
tar zxf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install

cd ..
tar zxf zlib-1.2.8.tar.gz 
cd zlib-1.2.8/
./configure --prefix=/usr/local/zlib && make && make install

cd ..
tar zxf pcre-8.39.tar.gz
cd pcre-8.39
./configure --prefix=/usr/local/pcre && make && make install

cd ..
tar zxf openssl-1.0.1u.tar.gz
cd openssl-1.0.1u
./config -fPIC --prefix=/usr/local/openssl enable-shared && make && make install

保存退出执行脚本

[root@http sh]# sh qianti.sh

3.安装Apache主程序

[root@http ~]# cd /sh
[root@http sh]# vim httpd.sh
#!/bin/bash
cd /usr/src
tar zxf httpd-2.4.25.tar.gz
cd httpd-2.4.25
./configure --prefix=/usr/local/httpd --enable-so --enable-cgi --enable-cgid --enable-ssl --with-ssl=/usr/bin/openssl --enable-rewrite --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-z=/usr/local/zlib --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=event --enable-proxy --enable-proxy-fcgi --enable-expires --enable-deflate && make && make install

4.优化链接

[root@http ~]# ln -s /usr/local/httpd/bin/* /usr/local/bin

添加系统服务

[root@http ~]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[root@http ~]# vim /etc/init.d/httpd
定位到第二行:修改为
# chkconfig: 35 85 15     \\声明服务启动级别,开机启动顺序,关机关闭顺序
# description: apache 2.4.25 \\服务声明,简要信息
保存退出
[root@http ~]# chkconfig --add httpd \\添加httpd到系统服务
[root@http ~]# chkconfig httpd on \\设置服务开机自启(等同于:systemctl enable httpd)
[root@http ~]# systemctl start httpd \\开启服务(等同于:service httpd start)

二、编译安装mysql

为了方便区分,可以修改主机名

[root@localhost ~]# hostname mysql
[root@localhost ~]# bash

1.首先创建目录用来存放软件包和编译安装脚本

[root@mysql ~]# mkdir -p /server/{soft,scripts}

把所需要的软件包移动到/server/soft目录下:cmake-2.8.6.tar.gz、mysql-5.6.36.tar.gz
编写编译安装脚本如下

[root@mysql ~]# vim /server/scripts/mysql.sh
#!/bin/bash
#由于没有下载mysql源码包,所以提前准备好
echo '正在下载资源包...'
yum -y install ncurses-devel gcc gcc-c++ 

tar zxf /server/soft/cmake-2.8.6.tar.gz -C /usr/src
cd /usr/src/cmake-2.8.6
echo '正在编译安装...'
./configure &> /dev/null
gmake && gmake install &> /dev/null

groupadd mysql
useradd -M -s /sbin/nologin mysql -g mysql

tar zxf /server/soft/mysql-5.6.36.tar.gz -C /usr/src
cd /usr/src/mysql-5.6.36
echo '预编译中...'
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all &> /dev/null
echo  '正在编译安装...'
make && make install &> /dev/null

echo  '对数据库目录进行授权:'
chown -R mysql:mysql /usr/local/mysql
echo  '建立配置文件:'
rm -rf /etc/my.cnf
cp support-files/my-default.cnf /etc/my.cnf
echo '安装Perl模块...'
yum -y install perl-Data-Dumper &> /dev/null
echo '初始化数据库...'
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
echo '设置环境变量:'
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
. /etc/profile
#mysql的启动和关闭
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start

echo  '创建软连接,优化路径:'
ln -s /usr/local/mysql/bin/mysql /usr/local/bin
ln -s /usr/local/mysql/bin/mysqladmin /usr/local/bin
#/etc/init.d/mysqld是一个shell脚本,在启动过程中会调用mysqld_safe脚本,最后调用mysqld服务启动mysql。
#$bindir/mysql_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 
netstat -anpt | grep 3306
cat << EOF

****************************************
* Mysql  has been installed successfully. *
****************************************

EOF

三、FastCGI方式编译安装php

为了方便区分,可以修改主机名

[root@localhost ~]# hostname php
[root@localhost ~]# bash

1.安装前提软件

[root@php ~]# yum -y install epel-release
[root@php ~]# yum -y install gcc gcc-c++ libxml2-devel lzip2-devel libcurl-devel libmcrypt-devel openssl-devel bzip2-devel

2.把所需软件包移动到/usr/src目录下
所需软件包为:libmcrypt-2.5.7.tar.gz、php-5.6.27.tar.gz,然后进行加密工具编译安装。

[root@php ~]# cd /usr/src
[root@php src]# tar zxf libmcrypt-2.5.7.tar.gz
[root@php src]# cd libmcrypt-2.5.7/
[root@php libmcrypt-2.5.7]# ./configure --prefix=/usr/local/libmcrypt && make && make install

3.编译安装php

[root@php ~]# cd /usr/src
[root@php src]# tar zxf php-5.6.27.tar.gz
[root@php src]# cd php-5.6.27/
[root@php php-5.6.27]# ./configure --prefix=/usr/local/php5.6 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt=/usr/local/libmcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts && make && make install

选项解释

--prefix=/usr/local/php5.6  #安装位置

--with-mysql=mysqlnd  #支持mysql

--with-pdo-mysql=mysqlnd  #支持pdo模块

--with-mysqli=mysqlnd  #支持mysqli模块
注意上面三个选项的作用:数据库与php不在一个服务器上,指定此种方式,安装数据库连接驱动.

--with-openssl  #支持openssl模块

--enable-fpm  #支持fpm模式

--enable-sockets  #启用socket支持

--enable-sysvshm  #启用系统共享内存支持

--enable-mbstring  #多字节字串、像中文就是多字节字串

--with-freetype-dir  #支持freetype,就要装freetype-devel、跟字体相关的、字体解析工具

--with-jpeg-dir

--with-png-dir
注意上面两个选项的作用:处理jpeg、png图片,php可以动态生成jpeg图片

--with-zlib  #压缩库、在互联网传输时用来压缩传输的

--with-libxml-dir=/usr  #这个libxml是用来解析xml的、指定/usr下

--enable-xml  #支持xml的

--with-mhash  #支持mhash

--with-mcrypt=/usr/local/libmcrypt  #libmcrypt-devel这个程序包所指定

--with-config-file-path=/etc  #指定配置文件的存放路径

--with-config-file-scan-dir=/etc/php.d  #配置文件扫描路径

--with-bz2  #支持BZip2
为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项。

如果使用PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL或MySQL开发包了。mysqlnd从php5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖),但从PHP5.4开始它就是默认设置了。
4.提供php配置文件

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

5.为php-fpm提供脚本

[root@php php-5.6.27]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@php php-5.6.27]# chmod +x /etc/init.d/php-fpm
[root@php php-5.6.27]# chkconfig --add php-fpm
[root@php php-5.6.27]# chkconfig php-fpm on

6.提供php-fpm配置文件并编辑

[root@php php-5.6.27]# cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf
[root@php php-5.6.27]# vim /usr/local/php5.6/etc/php-fpm.conf
修改内容如下:
pid = run/php-fpm.pid
listen = 192.168.229.141:9000
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

7.启动php-fpm服务

[root@php php-5.6.27]# systemctl start php-fpm

8.新建虚拟主机目录用于存放网页文件

[root@php ~]# mkdir -p /var/www/benet
四、配置Apache通过fastcgi协议调用php

1.开启mod_proxy_fcgi.so和mod_proxy.so模块
在Apache2.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
[root@www ~]# apachectl -M | grep proxy
proxy_module (shared)
proxy_fcgi_module (shared)

2.建立一个目录作为虚拟主机的家目录

[root@httpd ~]# mkdir -p /var/www/benet

3.编辑主配置文件httpd.conf,开启虚拟主机

[root@httpd ~]# vim /usr/local/httpd/conf/httpd.conf
启用Include conf/extra/httpd-vhosts.conf

同时定位AddType;添加下面两行:让apache能识别php格式的页面
AddType application/x-httpd-php.php
AddType application/x-httpd-php-source.phps

并且定位至DirectoryIndex:支持php格式的主页
DirectoryIndex index.php index.html  #添加index.php(最好添加在最前面)
[root@httpd ~]# systemctl restart httpd

4.配置虚拟主机支持使用fcgi

[root@httpd ~]# vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
    ServerAdmin webmaster@benet.com
    DocumentRoot "/var/www/benet"
    ServerName www.benet.com
    ServerAlias benet.com
    ErrorLog "logs/benet.com-error_log"
    CustomLog "logs/benet.com-access_log" common
    ProxyRequests Off
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://192.168.229.141:9000/var/www/benet/$1
    #<LocationMatch "^(.*\.php(/.*)?)$">
    # ProxyPass fcgi://192.168.31.141:9000/var/www/benet
    #</LocationMatch>
<Directory "/var/www/benet">
    Options FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
</VirtualHost>
[root@httpd ~]# systemctl restart httpd

参数解释

ProxyRequests off  #关闭正向代理

ProxyPassMatch:把以.php结尾的文件请求发送到php-fpm进程,php-fpm至少需要知道运行的目录和URI。
所以这里直接在fcgi://192.168.229.141:9000后指明了这两个参数,其它的参数传递已经被mod_proxy_fcgi.so进行封装,不需要手动指定。
特别注意的是,端口后面的路径需要与<VirtualHost>中的DocumentRoot后的路径一致。

ProxyPassMatch
只有满足特定正则模式的内容才会匹配并执行此规则,这里的模式是,^/(.*\.php(/.*)?)$
从网站(虚拟主机<VirtualHost>的根目录开始,匹配任何以.php结尾,或者在.php之后紧跟一个/再跟别的内容的路径。
^ (caret)和$ (dollar)标志要匹配的路径的开始和结束

( )括号里的内容可以用$1来表示,以方便后面引用它。
fcgi://192.168.229.141:9000通过mod_proxy_fcgi来转发代理,使用fastCGI协议,转到PHP-FPM监听的端口。

/path/to/your/documentroot/:必须与虚拟主机的路径匹配,且必须是对应php文件在操作系统中的绝对路径。否则会找不到文件。

$1:可以从原始请求扩展成整个请求路径的变量,这里指代前面( )里面匹配的那个路径(uri)

补充:Apache2.4以前的版本中,要么把PHP作为Apache的模块运行,要么添加一个第三方模块支持PHP-FPM。

5.测试lamp环境
(1)在mysql服务器,创建用于php服务器连接的数据库用户

[root@mysql ~]# mysql  #登录数据库命令
mysql> grant all on *.* to testuser@'%' identified by 'asd123';

(2)在php服务器上的/var/www/benet目录下创建.php的测试页

[root@php ~]# vim /var/www/benet/index.php
<?php
phpinfo();
?>
[root@php ~]# vim /var/www/benet/test1.php
<?php
$link=mysql_connect('192.168.229.140','testuser','asd123');
if ($link)echo "connection success......";
mysql_close();
?>

(3)测试访问index.php测试页,访问的只能是前台,也就是Apache。

192.168.229.138/index.php

在这里插入图片描述
再次访问test1.php

192.168.229.138/test1.php

在这里插入图片描述
看到上面两个测试成功,说明apache、php、mysql之间可以协同工作了。

五、ab压力测试

1.压力测试简介
网站性能压力测试是服务器网站性能调优过程中必不可缺少的一环。只有让服务器处在高压情况下,才能真正体现出软件、硬件等各种设置不当所暴露出的问题。
性能测试工具目前最常见的有以下几种:ab、http_load、webbench、siege。
ab是apache自带的压力测试工具。ab非常实用,它不仅可以对apache服务器进行网站访问压力测试,也可以对或其它类型的服务器进行压力测试。比如nginx、tomcat、IIS等。
1.ab的原理
ab是apachebench命令的缩写。
ab命令会创建多个并发访问线程,模拟多个访问者同时对某一URL地址进行访问。它的测试目标是基于URL的,因此,它既可以用来测试apache的负载压力,也可以测试nginx、lighthttp、tomcat、IIS等其它Web服务器的压力。
ab命令对发出负载的计算机要求很低,它既不会占用很高CPU,也不会占用很多内存。但却会给目标服务器造成巨大的负载,其原理类似CC攻击。自己测试使用也需要注意,否则一次上太多的负载。可能造成目标服务器资源耗完,严重时甚至导致死机。
2.ab的安装
ab的安装非常简单,如果是源码安装apache的话,那就更简单了。apache安装完毕后ab命令存放在apache安装目录的bin目录下。

[root@http bin]# pwd
/usr/local/httpd/bin
[root@http bin]# ls
ab         checkgid   envvars-std   htdbm     httpd       rotatelogs
apachectl  dbmmanage  fcgistarter   htdigest  httxt2dbm
apxs       envvars    htcacheclean  htpasswd  logresolve

如果apache是通过yum的方式安装,ab命令默认存放在/usr/bin目录下。

[root@http ~]# which ab

注意:如果不想安装apache但是又想使用ab命令,可以直接安装apache的工具包httpd-tools。

[root@http ~]# yum -y install httpd-tools

查看ab是否安装成功,可以切换到上述目录下,使用ab –V命令进行检测。

[root@http ~]# ab -V
ab: error while loading shared libraries: libssl.so.1.0.0: cannot 
open shared object file: No such file or directory

如果命令出错,可以输入下面的命令。

[root@http ~]# export LD_LIBRARY_PATH="/usr/local/openssl/lib/"
[root@http ~]# ab -V
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

3.ab参数说明
有关ab命令的使用,可以通过帮助命令进行查看。

[root@http ~]# ab --help

参数介绍

-n:在测试会话中所执行的请求个数(即总请求数)。 

-c:一次产生的请求个数(即并发用户数)。

执行ab命令

[root@httpd ~]# ab -c 500 -n 10000 http://192.168.229.138/index.html
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.229.138 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests

Server Software: Apache
Server Hostname: 192.168.229.138
Server Port: 80
Document Path: /index.html  #请求的资源
Document Length: 312 bytes  #HTTP响应数据的正文长度
Concurrency Level: 500  #并发个数(并发用户数)
Time taken for tests: 1.452 seconds  #所有这些请求处理完成所花费的时间
Complete requests: 10000  #完成请求数
Failed requests: 0  #失败的请求数
Non-2xx responses: 10000
Total transferred: 4760000 bytes  #表示所有请求的响应数据长度总和,包括每个HTTP响应数据的头信息和正文数据的长度。注意这里不包括HTTP请求数据的长度,仅仅为web服务器流向用户PC的应用层数据总长度。
HTML transferred: 3120000 bytes  #表示所有请求的响应数据中正文数据的总和,也就是减去了Total transferred中HTTP响应数据中的头信息的长度。
Requests per second: 7530.93 [#/sec] (mean)  #吞吐量-每秒请求数。计算公式:Complete requests/Time taken for tests
Time per request: 66.393 [ms] (mean)  #用户平均请求等待时间,计算公式:Time token for tests/(Complete requests/Concurrency Level)。
Time per request: 0.133 [ms] (mean, across all concurrent requests)  #服务器平均请求等待时间,计算公式:Time taken for tests/Complete requests。
Transfer rate: 3500.71 [Kbytes/sec] received  #表示这些请求在单位时间内从服务器获取的数据长度,计算公式:Total trnasferred/ Time taken for tests,很好的说明服务器的处理能力达到极限时,其出口宽带的需求量。(即平均每秒网络上的流量)

Connection Times (ms)
min mean[+/-sd] median max
Connect: 10 27 7.3 27 48
Processing: 4 37 36.5 32 439
Waiting: 2 27 37.0 21 435
Total: 30 64 37.6 60 470
Percentage of the requests served within a certain time (ms)
50% 60
66% 63
75% 64
80% 66
90% 71
95% 76
98% 89
99% 261
100% 470 (longest request)
这部分数据用于描述每个请求处理时间的分布情况,比如以上测试,80%的请求处理时间都不超过66ms,这个处理时间是指前面的Time per request,即对于单个用户而言,平均每个请求的处理时间。

继续压力测试
再来进行一次压力测试,此时并发用户数为1000,其他条件不变,查看两次测试结果的吞吐量差别。
4.ab性能指标
在进行性能测试过程中有几个指标比较重要:
(1)吞吐率(Requests per second)
服务器并发处理能力的量化描述,单位是reqs/s,指在某个并发用户数下单位时间内处理的请求数。某个并发用户数下单位时间内能处理的最大请求数,称之为最大吞吐率。
注意:吞吐率是基于并发用户数的。

a、吞吐率和并发用户数相关

b、不同的并发用户数下,吞吐率一般是不同的

计算公式:总请求数/处理完成这些请求数所花费的时间,即Request per second=Complete requests/Time taken for tests
这个数值表示当前机器的整体性能,值越大越好。

(2)并发连接数(The number of concurrent connections)
并发连接数指的是某个时刻服务器所接受的请求数目,简单的讲,就是一个会话。
(3)并发用户数(Concurrency Level)
要注意区分这个概念和并发连接数之间的区别,一个用户可能同时会产生多个会话,也即连接数。
(4)用户平均请求等待时间(Time per request)
计算公式:处理完成所有请求数所花费的时间/(总请求数/并发用户数),即:Time per request=Time taken for tests/(Complete requests/Concurrency Level)
(5)服务器平均请求等待时间(Time per request:across all concurrent requests)
计算公式:处理完成所有请求数所花费的时间/总请求数,即:Time taken for/testsComplete requests
可以看到,它是吞吐率的倒数。
同时,它也等于用户平均请求等待时间/并发用户数,即Time per request/Concurrency Level。

六、安装php加速软件Xcache

1.php的工作模式
php在lamp环境下共有三种工作模式:

(1)CGI模式

(2)apache模块

(3)FastCGI模式

CGI模式下运行PHP,性能不是很好。作为apache的模块方式运行是比较熟悉的。FastCGI的方式和apache模块的不同点在于:FastCGI方式下的PHP是一处独立的进程,所有PHP子进程都由PHP的php-fpm组件负责管理;而apache模块化方式运行的PHP,则是apache负责调用PHP完成工作。PHP的FastCGI方式性能要比apache模块化方式强很多。
2.FastCGI工作机制
首先客户端发起请求,请求分为2种,一种是静态请求,它可以由Apache直接响应返回;另一种是动态的请求,如果其中包含php或者Perl脚本解释性语言,则由Apache服务器通过fastcgi协议调用php服务器执行并返回给Apache,由Apache返回解释执行后的结果。如果这个过程中涉及到对数据的操作,此时php服务器还会通过mysql协议调用mysql服务器。
在这里插入图片描述
在php主机上完成下面的操作
3.上传或下载xcache安装包
上传xcache安装包到虚拟机或网上下载:
说明:
php 安装目录:/usr/local/php5.6
php.ini 配置文件路径:/etc/php.ini
php 网页根目录:/var/www/benet

[root@php ~]# wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz

4.安装xcache

[root@php ~]# tar zxf xcache-3.2.0.tar.gz  #解压
[root@php ~]# cd xcache-3.2.0/  #进入安装目录
[root@php xcache-3.2.0]# yum -y install autoconf
[root@php xcache-3.2.0]# /usr/local/php5.6/bin/phpize  #用phpize生成configure配置文件
[root@php xcache-3.2.0]# ./configure --enable-xcache --enable-xcache-coverager --enable-xcache-optimizer --with-php-config=/usr/local/php5.6/bin/php-config  #配置
[root@php xcache-3.2.0]# make && make install  #编译、安装
安装完成之后,在extensions后面会出现一个路径,记住它,后面会用到。

5.创建xcache缓存文件并赋权

[root@php xcache-3.2.0]# touch /tmp/xcache
[root@php xcache-3.2.0]# chmod 777 /tmp/xcache 

6.复制xcache网站目录到php(192.168.229.141)和httpd(192.168.1.138)网站根目录下

[root@php xcache-3.2.0]# cp -r htdocs/ /var/www/benet/xcache
[root@php xcache-3.2.0]# scp -rp /var/www/benet/xcache/ root@192.168.229.138:/var/www/benet/

7.修改php配置文件,添加xcache参数,重启php-fpm

[root@php ~]# vim /etc/php.ini
添加到文件末尾:
[xcache-common]
extension = /usr/local/php5.6/lib/php/extensions/no-debug-zts-20131226/xcache.so  #把xcache.so前的路径换成上面需要记住的那个路径,make install的最后一行路径。
[xcache.admin]
xcache.admin.enable_auth = Off
[xcache]
xcache.shm_scheme ="mmap"
xcache.size=60M
xcache.count =1
xcache.slots =8K
xcache.ttl=0
xcache.gc_interval =0
xcache.var_size=64M
xcache.var_count =1
xcache.var_slots =8K
xcache.var_ttl=0
xcache.var_maxttl=0
xcache.var_gc_interval =300
xcache.test =Off
xcache.readonly_protection = Off
xcache.mmap_path ="/tmp/xcache"
xcache.coredump_directory =""
xcache.cacher =On
xcache.stat=On
xcache.optimizer =Off
[xcache.coverager]
xcache.coverager =On
xcache.coveragedump_directory =""
[root@php ~]# systemctl restart php-fpm

8.测试访问httpd的xcache虚拟目录

http://192.168.229.138/xcache

在这里插入图片描述
执行第一次压力测试:

[root@php ~]# ab -c 100 -n 1000 http://192.168.229.138/index.php
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.229.138 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software: Apache
Server Hostname: 192.168.229.138
Server Port: 80

Document Path: /index.php
Document Length: 85006 bytes

Concurrency Level: 100
Time taken for tests: 1.773 seconds
Complete requests: 1000
Failed requests: 368
(Connect: 0, Receive: 0, Length: 368, Exceptions: 0)
Total transferred: 85259504 bytes
HTML transferred: 85013504 bytes
Requests per second: 563.88 [#/sec] (mean)
Time per request: 177.344 [ms] (mean)
Time per request: 1.773 [ms] (mean, across all concurrent requests)
Transfer rate: 46948.95 [Kbytes/sec] received

Connection Times (ms)
        min mean[+/-sd] median max
Connect: 0 1 2.7 0 16
Processing: 31 167 73.7 140 406
Waiting: 23 162 73.1 136 401
Total: 40 168 73.0 141 406

Percentage of the requests served within a certain time (ms)
50% 141
66% 152
75% 176
80% 188
90% 294
95% 389
98% 396
99% 400
100% 406 (longest request)

执行第二次压力测试

[root@php ~]# ab -c 100 -n 1000 http://192.168.229.138/index.php
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.229.138 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software: Apache
Server Hostname: 192.168.229.138
Server Port: 80

Document Path: /index.php
Document Length: 85006 bytes

Concurrency Level: 100
Time taken for tests: 1.264 seconds
Complete requests: 1000
Failed requests: 316
(Connect: 0, Receive: 0, Length: 316, Exceptions: 0)
Total transferred: 85257983 bytes
HTML transferred: 85011983 bytes
Requests per second: 790.93 [#/sec] (mean)
Time per request: 126.434 [ms] (mean)
Time per request: 1.264 [ms] (mean, across all concurrent requests)
Transfer rate: 65852.24 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 2.7 0 11
Processing: 33 120 20.6 120 180
Waiting: 28 115 20.0 115 179
Total: 44 121 19.2 121 180
Percentage of the requests served within a certain time (ms)
50% 121
66% 124
75% 127
80% 128
90% 147
95% 159
98% 166
99% 169
100% 180 (longest request)

9.查看xcache的命中率
在这里插入图片描述

七、部署Discuz论坛

1.复制Discuz包到apache和php服务器的/var/www/benet目录,解压并重命名赋权。
httpd和php的操作步骤一样。

~]# unzip Discuz_7.0.0_FULL_SC_UTF8.zip
~]# mv upload/ /var/www/benet/bbs
~]# chmod -R 777 /var/www/benet/bbs

2.在php服务器修改配置文件,重启服务

[root@php ~]# vim /etc/php.ini
找到下行并改为:
short_open_tag = On
[root@php ~]# service php-fpm restart

3.mysql服务器上创建bbs数据库及用户

mysql> create database bbsdb;
Query OK, 1 row affected (0.01 sec)

mysql> grant all on bbsdb.* to runbbs@'%' identified by 'asd123';
Query OK, 0 rows affected, 1 warning (0.03 sec)

4.访问Apache,安装discuz论坛。

http://192.168.229.138/bbs

在这里插入图片描述
除了数据库名:bbsdb、数据库用户名:runbbs、密码,其他一律下一步。
在这里插入图片描述
出现上面这种情况是由于php服务器安装了discuz之后导致程序发生变化从而导致动态服务器和静态服务器的程序不一致,只需要手动把bbs服务器的文件和web服务器进行一次同步即可,如果想实现自动同步,需要使用其他服务,如initory+rsync、sersync等工具。
php服务器上同步操作优化论坛界面:

[root@php benet]# scp -r /var/www/benet/bbs/* 192.168.229.138:/var/www/benet/bbs/

动态服务器和静态服务器同步文件之后,再次访问bbs的网址就正常了。
在这里插入图片描述
访问后台,输入以下地址。

http://192.168.229.138/bbs/admin.php?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值