《PHP搭建緩存服務(wù)Memcache/Redis》要點(diǎn):
本文介紹了PHP搭建緩存服務(wù)Memcache/Redis,希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
相關(guān)主題:memcache擴(kuò)展 / 鍵值KeyValue存儲(chǔ)數(shù)據(jù)庫(kù)
安裝memcache
1.安裝libevent(Memcache用到了libevent這個(gè)庫(kù)用于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運(yùn)行的時(shí)候能力找到libevent庫(kù)
cd /usr/lib
ln -s /usr/local/libevent/lib/libevent-2.0.so.5 libevent-2.0.so.5 (具體版本根據(jù)你安裝的版本分歧)
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.啟動(dòng)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擴(kuò)展 繼續(xù)往下走
如果安裝PHP支持memcached擴(kuò)展 跳轉(zhuǎn)到memcached安裝文檔
4. 安裝PHP支持memcache擴(kuò)展
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
勝利之后會(huì)生成PHP支持的擴(kuò)展模塊
ls /usr/local/php-5.4.17/lib/php/extensions/no-debug-non-zts-20100525/
編纂php.ini 添加擴(kuò)展
vi /usr/local/php/etc/php.ini
[memcache]
extension=memcache.so
memcached 參加系統(tǒng)服務(wù)
service php-fpm restartmemcached 系統(tǒng)服務(wù)啟動(dòng)
memcached 參加系統(tǒng)服務(wù)
service php-fpm restart
memcached 系統(tǒng)服務(wù)啟動(dòng)
將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
啟動(dòng)redis
redis-server /usr/local/redis/redis.conf
啟動(dòng)之后會(huì)出現(xiàn)警告處理
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.
依照警告的內(nèi)容實(shí)現(xiàn)
vi /etc/sysctl.conf
文檔最后添加
vm.overcommit_memory = 1
添加完之后重啟系統(tǒng)reboot 重啟之后執(zhí)行 sysctl vm.overcommit_memory=1
在重新啟動(dòng)redis 就不會(huì)出現(xiàn)警告
后臺(tái)啟動(dòng)redis (輸出重定向)redis-server /usr/local/redis/redis.conf &
啟動(dòng)redis客戶端
redis-cli
redis> set foo barOK
redis> get foo"bar"
勝利
《PHP搭建緩存服務(wù)Memcache/Redis》是否對(duì)您有啟發(fā),歡迎查看更多與《PHP搭建緩存服務(wù)Memcache/Redis》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/11805.html