centos /linux 下安裝Memcached服務器端

我的版本爲Centos Release 5.5 (Final)
使用這個命令可以知道你的Linux版本
cat /etc/redhat-release
1.要安裝libevent庫。
cd /usr/local/src
curl -O http://monkey.org/~provos/libevent-1.4.10-stable.tar.gz
tar xzvf libevent-1.4.10-stable.tar.gz
cd libevent-1.4.10-stable
./configure --prefix=/usr/local
make
make install

2.接下來就是安裝memcached
cd /usr/local/src
wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
tar xzvf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure
make
make install
memcached 是在/usr/local/bin/memcahced下
安裝完畢後,用下面這個命令以用戶root來運行memcache
memcached -u root -d -m 64 -l 192.168.0.101 -p 11211
root 爲所執行的用戶
64 爲緩存大小64M
192.168.0.101 爲所在的服務器IP地址
11211 是所在端口

要關閉memcache
pkill memcached

3.接下來是安裝php-pecl-memcache
http://pecl.php.net/package/memcache
這個詳細配置可查看php的源碼安裝
http://www.uusnn.com.cn/index.php/archives/148
查看memcache的運行情況,可以用memcache.php來查看。
4.memcached測試
$mc = new memcache();
//用addServer比用connect要好
$mc->addServer('192.168.0.101', 11211) or die ("Could not connect");
$mc->set('uusnn','ttt');
//$mc->delete('uusnn');
$a = $mc->get('uusnn');
print_r($a);
5.推薦使用方式
The directives are used by the MemcachePool constructor so you can instantiate
several pools with different settings by using ini_set() creativly. For example

ini_set('memcache.protocol', 'binary');

$binarypool = new MemcachePool();
$binarypool->addServer(...)

ini_set('memcache.protocol', 'ascii');
ini_set('memcache.redundancy', '2');

$redundantpool = new MemcachePool();
$redundantpool->addServer(...)

ini_set('memcache.redundancy', '1');

The new interface looks like

class MemcachePool() {
bool connect(string host, int tcp_port = 11211, int udp_port = 0, bool persistent = true, int weight = 1, int timeout = 1, int retry_interval = 15)
bool addServer(string host, int tcp_port = 11211, int udp_port = 0, bool persistent = true, int weight = 1, int timeout = 1, int retry_interval = 15, bool status = true)
bool setServerParams(string host, int tcp_port = 11211, int timeout = 1, int retry_interval = 15, bool status = true)

/**
* Supports fetching flags and CAS values
*/
mixed get(mixed key, mixed &flags = null, mixed &cas = null)

/**
* Supports multi-set, for example
* $memcache->set(array('key1' => 'val1', 'key2' => 'val1'), null, 0, 60)
*/
bool add(mixed key, mixed var = null, int flag = 0, int exptime = 0)
bool set(mixed key, mixed var = null, int flag = 0, int exptime = 0)
bool replace(mixed key, mixed var = null, int flag = 0, int exptime = 0)

/**
* Compare-and-Swap, uses the CAS param from MemcachePool::get()
*/
bool cas(mixed key, mixed var = null, int flag = 0, int exptime = 0, int cas = 0)

/**
* Prepends/appends a value to an existing one
*/
bool append(mixed key, mixed var = null, int flag = 0, int exptime = 0)
bool prepend(mixed key, mixed var = null, int flag = 0, int exptime = 0)

/**
* Supports multi-key operations, for example
* $memcache->delete(array('key1', 'key2'))
*/
bool delete(mixed key, int exptime = 0)

/**
* Supports multi-key operations, for example
* $memcache->increment(array('key1', 'key2'), 1, 0, 0)
*
* The new defval (default value) and exptime (expiration time) are used
* if the key doesn't already exist. They must be supplied (even if 0) for
* this to be enabled.
*
* Returns an integer with the new value if key is a string
* Returns an array of integers if the key is an array
*/
mixed increment(mixed key, int value = 1, int defval = 0, int exptime = 0)
mixed decrement(mixed key, int value = 1, int defval = 0, int exptime = 0)

/**
* Assigns a pool-specific failure callback which will be called when
* a request fails. May be null in order to disable callbacks. The callback
* receive arguments like
*
* function mycallback($host, $tcp_port, $udp_port, $error, $errnum)
*
* Where $host and $error are strings or null, the other params are integers.
*/
bool setFailureCallback(function callback)
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章