《PHP搭建缓存服务Memcache/Redis》要点:
本文介绍了PHP搭建缓存服务Memcache/Redis,希望对您有用。如果有疑问,可以联系我们。
相关主题:memcache扩展 / 键值KeyValue存储数据库
安装memcache
1.安装libevent(Memcache用到了libevent这个库用于Socket的处理,所以还必要安装libevent)libevent-2.0.21-stable.tar.gz
tar zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix=/usr/local/libevent
make && make install
# 建立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》是否对您有启发,欢迎查看更多与《PHP搭建缓存服务Memcache/Redis》相关教程,学精学透。维易PHP学院为您提供精彩教程。