安装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