centos /linux 下安装Memcached服务器端

4 篇文章 0 订阅
1 篇文章 0 订阅

我的版本为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)
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值