您的位置 首页 php

PHP搭建缓存服务Memcache/Redis

安装memcache

# 建立libevent-1.4.so.2到/usr/lib的软连接,这样memcached运行的时候才能找到libevent库

cd /usr/lib

ln -s /usr/local/libevent/lib/libevent-2.0.so.5 libevent-2.0.so.5 (具体版本根据你安装的版本不同)

2.安装memcached

tar zxvf memcached-1.4.20.tar.gz

cd memcached-1.4.20

./configure –prefix=/usr/local/memcached-1.4.20 -with-libevent=/usr/local/libevent

make

make install

3.启动memcached

cd /usr/local/

ln -s memcached-1.4.20 memcached

/usr/local/memcached/bin/memcached -d -p 22211 -u root -c 1024 -m 1024 -l 192.168.112.128

如果安装PHP支持memcache扩展 继续往下走

如果安装PHP支持memcached扩展 跳转到memcached安装文档

4. 安装PHP支持memcache扩展

cd /root/soft

tar -zxvf memcache-3.0.6.tgz

cd memcache-3.0.6

/usr/local/php/bin/phpize

./configure –enable-memcache –with-php-config=/usr/local/php/bin/php-config –with-zlib-dir

make && make install

成功之后会生成PHP支持的扩展模块

ls /usr/local/php-5.4.17/lib/php/extensions/no-debug-non-zts-20100525/

编辑php.ini 添加扩展

vi /usr/local/php/etc/php.ini

[memcache]

extension=memcache.so

memcached 加入系统服务

service php-fpm restartmemcached 系统服务启动

memcached 加入系统服务

service php-fpm restart

memcached 系统服务启动

将memcached 拷贝到/etc/init.d

chkconfig –add memcached

chkconfig memcached on

安装redis

tar zxvf redis-2.8.11.tar.gz

mv redis-2.8.11 /usr/local/redis

cd /usr/local/redis

make && make install

启动redis

redis-server /usr/local/redis/redis.conf

启动之后会出现警告处理

WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect.

按照警告的内容实现

vi /etc/sysctl.conf

文档最后添加

vm.overcommit_memory = 1

添加完之后重启系统reboot 重启之后执行 sysctl vm.overcommit_memory=1

在重新启动redis 就不会出现警告

后台启动redis (输出重定向)redis-server /usr/local/redis/redis.conf &

启动redis客户端

redis-cli

redis> set foo barOK

redis> get foo”bar”

成功

文章来源:智云一二三科技

文章标题:PHP搭建缓存服务Memcache/Redis

文章地址:https://www.zhihuclub.com/153870.shtml

关于作者: 智云科技

热门文章

网站地图