Memcached Server + Client 完全安裝

一、環境需求
安裝Memcached需要libevent庫的支援,所以請在安裝Memcached之前檢查有沒有安裝libevent。
測試環境還需要PHP的支援,本文假設PHP已經安裝到/usr/local/php目錄下,也就是在編譯PHP的時候使用perfix參數指定目錄(–prefix= /usr/local/php)
二、下載相關軟體
Memcached下載位址︰http://www.danga.com/memcached/
memcache PHP模塊下載位址︰ http://pecl.php.net/package/memcache
libevent 下載位址︰ http://www.monkey.org/~provos/libevent/
本文不再講述如何安裝libevent
三、安裝和設定
1、安裝Memcached

tar vxzf memcached-1.1.12.tar.gz
cd memcached-1.1.12
./configure --prefix=/usr/local/memcached
make
make install

安裝完之後要啟動服務

cd /usr/local/memcached/bin
./memcached -d -m 50 -p 11211 -u root

參數說明 -m 指定使用多少的緩存空間;-p 指定要監聽的埠; -u 指定以哪個用戶來執行

2、安裝memcache PHP模組

tar vxzf memcache-1.5.tgz
cd memcache-1.5
/usr/local/php/bin/phpize
./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
make
make install

安裝完後會有類似這樣的提示︰
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/
把這個記住,然後修改php.in
i,把
extension_dir = "./"
修改為
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/"
並增加一行
extension=memcache.so
3、測試程式
自己寫一個PHP程式測試一下吧

<?php
$memcache = new Memcache;
$memcache->connect(‘localhost’, 11211) or die (“Could not connect”);
$memcache->set(‘key’, ‘test’);
$get_value = $memcache->get(‘key’);
echo $get_value;
?>

About the Author

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料