lamp架构-php结合phpmyadmin、添加memcache功能模块、openresty安装配置、构建nginx高速缓存

一、php集合phpmyadmin测试

phpMyAdmin 是一个以PHP为基础,以Web-Base方式架构在网站主机上的MySQL的数据库管理工具,让管理者可用Web接口管理MySQL数据库。

[root@server1 ~]# vim .bash_profile           %首先添加php的环境变量并使其生效
PATH中添加:/usr/local/php/bin
[root@server1 ~]# source .bash_profile 

 

[root@server1 ~]# cd /usr/local/php/etc/
[root@server1 etc]# vim php.ini     %编辑php页面配置文件使其和mysql数据库结合
[root@server1 etc]# systemctl reload php-fpm.service   

 

[root@server1 ~]# unzip phpMyAdmin-5.0.2-all-languages.zip
[root@server1 ~]# cd phpMyAdmin-5.0.2-all-languages/
[root@server1 phpMyAdmin-5.0.2-all-languages]# cd ..
[root@server1 ~]# mv phpMyAdmin-5.0.2-all-languages /usr/local/nginx/html/phpadmin    %移动到nginx的默认发布目录下

上述问题是因为相关目录权限不够所导致的:
[root@server1 mysql-5.7.31]# cd /usr/local/mysql/
[root@server1 mysql]# chmod 755 data

二、php添加memcache功能模块

[root@server1 ~]# tar zxf memcache-4.0.5.2.tgz 
[root@server1 ~]# cd memcache-4.0.5.2/
[root@server1 memcache-4.0.5.2]# yum install -y autoconf
[root@server1 memcache-4.0.5.2]# phpize   %phpize是一个运行脚本,主要作用是检测php的环境还有就是在特定的目录生成相应的configure文件,这样makeinstall之后,生成的.so文件才会自动加载到php扩展目录下面。
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902

编译、安装:
[root@server1 memcache-4.0.5.2]# ./configure --enable-memcache     
[root@server1 memcache-4.0.5.2]# make
[root@server1 memcache-4.0.5.2]# make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/

[root@server1 ~]# cd /usr/local/php/etc/
[root@server1 etc]# vim php.ini
extension=memcache         %添加memcache扩展模块
[root@server1 etc]# systemctl reload php-fpm.service 
[root@server1 etc]# php -m |grep memcache
memcache

访问流程:
php > memcache.so > memcached
[root@server1 etc]# yum install -y memcached    %安装
[root@server1 etc]# systemctl start memcached.service   %启动memcached服务
[root@server1 etc]# netstat -antulp         %查看有11211端口表示正常  

[root@server1 ~]# cd memcache-4.0.5.2/
[root@server1 memcache-4.0.5.2]# cp example.php /usr/local/nginx/html/    %复制memcache的示例页面到nginx的默认发布目录下
[root@server1 ~]# cd memcache-4.0.5.2/
[root@server1 memcache-4.0.5.2]# cp memcache.php /usr/local/nginx/html/
[root@server1 memcache-4.0.5.2]# cd /usr/local/nginx/html/
[root@server1 html]# vim memcache.php
define('ADMIN_USERNAME','admin');       // Admin Username
define('ADMIN_PASSWORD','westos');      // Admin Password
$MEMCACHE_SERVERS[] = 'localhost:11211'; // add more as an array

三、openresty安装配置

源码编译安装:
[root@server1 ~]# tar zxf openresty-1.19.3.1.tar.gz
[root@server1 ~]# cd openresty-1.19.3.1
[root@server1 openresty-1.19.3.1]# ./configure 
[root@server1 openresty-1.19.3.1]# gmake
[root@server1 openresty-1.19.3.1]# gmake install
[root@server1 openresty-1.19.3.1]# cd /usr/local/openresty
[root@server1 openresty]# cd nginx/

[root@server1 nginx]# systemctl stop nginx.service        %停掉原生的nginx服务
[root@server1 nginx]# pwd
/usr/local/openresty/nginx
[root@server1 nginx]# cd conf/
[root@server1 conf]# vim nginx.conf         %编辑openresty中nginx的配置文件如下图

[root@server1 ~]# cd openresty-1.19.3.1/
[root@server1 openresty-1.19.3.1]# cd util/
[root@server1 util]# cd /usr/local/openresty/
[root@server1 openresty]# /usr/local/openresty/nginx/sbin/nginx -t    %检测nginx.conf文件是否有语法错误
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
[root@server1 openresty]# /usr/local/openresty/nginx/sbin/nginx    %启动openresty/nginx服务
[root@server1 openresty]# netstat -antulp         %能看到80端口表示服务开启成功

浏览器访问nginx服务器ip,能够看到openresty的测试页面

四nginx高速缓存

1.设置高速缓存前

[root@foundation1 ~]# ab -c10 -n5000 http://172.25.70.1/example.php     %十个并发,每个5000个请求
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.25.70.1 (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests


Server Software:        openresty/1.19.3.1
Server Hostname:        172.25.70.1
Server Port:            80

Document Path:          /example.php
Document Length:        116 bytes

将测试页放置到openresty中nginx的默认发布目录下

此时采用的是传统的缓存策略:

2.设置高速缓存

[root@server1 html]# pwd
/usr/local/openresty/nginx/html
[root@server1 html]# cd ..
[root@server1 nginx]# cd conf/
[root@server1 conf]# vim nginx.conf
upstream memcache {
        server 127.0.0.1:11211;
        keepalive 512;
        }
location /memc {
        internal;			
        memc_connect_timeout 100ms;
        memc_send_timeout 100ms;
        memc_read_timeout 100ms;
        set $memc_key $query_string;	
        set $memc_exptime 300;		
        memc_pass memcache;
        }

location ~ \.php$ {
            set $key $uri$args;		
            srcache_fetch GET /memc $key;	   %现在memcache中找,如果有则直接返回,如果没有再通过fastcgi去后端找
            srcache_store PUT /memc $key;      %将在后端找到的值存储到memcache中,下次再请求的时候可以直接返回       
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.conf;
        }
[root@server1 conf]# /usr/local/openresty/nginx/sbin/nginx -t    %检测是否有语法错误
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
[root@server1 conf]# /usr/local/openresty/nginx/sbin/nginx -s reload   %重新加载

此时采用的是高速缓存策略:

3.再次进行压力测试

[root@foundation1 ~]# ab -c10 -n5000 http://172.25.70.1/example.php
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.25.70.1 (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests


Server Software:        openresty/1.19.3.1
Server Hostname:        172.25.70.1
Server Port:            80

Document Path:          /example.php
Document Length:        116 bytes

Concurrency Level:      10
Time taken for tests:   0.646 seconds
Complete requests:      5000
Failed requests:        0
Total transferred:      1529979 bytes
HTML transferred:       580000 bytes
Requests per second:    7739.47 [#/sec] (mean)     %请求速度明显加快
Time per request:       1.292 [ms] (mean)
Time per request:       0.129 [ms] (mean, across all concurrent requests)
Transfer rate:          2312.74 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       2
Processing:     0    1   0.3      1       5
Waiting:        0    1   0.3      1       5
Total:          1    1   0.3      1       6

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      2
  95%      2
  98%      2
  99%      2
 100%      6 (longest request)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值