memcached缓存架构优化

安装memcache工具包

yum install memcached -y
systemctl start memcached

安装memcache源码包

tar zxf memcache-4.0.5.2.tar.gz

这时切换至源码包没有configure执行文件需要执行phpize
执行之前需安装autoconf

yum install autoconf -y
cd memcache-4.0.5.2
phpize
./configure --enable-memcache
make && make install 

编写默认发布文件

cd memcache-4.0.5.2
cp example.php /usr/local/nginx/html
cp memcache.php /usr/local/nginx/html
#vim /usr/local/nginx/html/memcache.php

在这里插入图片描述
修改php配置

#vim /usr/local/php/etc/php.ini

在这里插入图片描述
重启服务

nginx -s reload
systemctl reload memcached
/etc/init.d/php-fpm reload

访问
在这里插入图片描述
在这里插入图片描述
查看处理速度

ab -c 1 -n 1000 http://172.25.19.5/example.php

在这里插入图片描述

*这是目前的架构:web -> nginx -> .php -> php-fpm:9000 -> memcached -> mysql
这样的架构速度慢,造成nginx阻塞,所以需要新的架构:web -> openresty – memc+srcache–> memcached -> mysql

安装openresty

tar zxf openresty-1.17.8.2.tar.gz
cd openresty-1.17.8.2/
./configure --prefix=/opt/openresty --with-threads --with-file-aio --with-http_ssl_module --with-http_stub_status_module
make && make install

创建快捷命令

# vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/php/bin:/usr/local/nginx/sbin

关闭nginx开启openresty

nginx -s stop
/opt/openresty/nginx/sbin/nginx

复制测试页

cp /usr/local/nginx/html/example.php /opt/openresty/nginx/html

修改配置文件

vim /opt/openresty/nginx/conf/nginx.conf

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

重启服务

/opt/openresty/nginx/sbin/nginx -s reload

测试,性能由800+提升至3000+

ab -c 1 -n 1000 http://172.25.10.5/example.php

在这里插入图片描述

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值