《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學院為您提供精彩教程。