memcache安装

Linux下的Memcache安装

安装系统自带memcache:
1 查看源 :sudo vim /etc/apt/sources.list
2 安装memcached :sudo -E apt-get install memcacheD
3 查看是否启动 ps -ef|grep memcache

源码安装(CentOS 5.5)

1 下载libevent(依赖) 和memcached

分别到以下引用地址下载最新版本:

引用地址 http://www.monkey.org/~provos/libevent/

引用地址:http://code.google.com/p/memcached/downloads/list

2 安装ibevent(依赖) 和memcached

libevent(目前最新是libevent-2.0.10-stable.tar.gz,请注意版本号)

tar xvf libevent-2.0.10-stable.tar.gz

cd libevent-2.0.10-stable

./configure --prefix=/usr/local/libevent/

make

make install

接着,ls /usr/local/libevent/lib,将查看到的第一个类似libevent-X.X.so.X

ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /lib/libevent-2.0.so.5


测试libevent是否安装成功:
ls -al /usr/lib | grep libevent


memcached (目前最新是1.4.5,请注意版本号)

tar zxvf memcached-1.4.5.tar.gz

cd memcached-1.4.5

./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/

make

make install

测试libevent是否安装成功:
ls -al /usr/lib | grep libevent

3 启动memcached

启动参数说明(这是我是复制粘贴的,如有错误请指正):

-d 选项是启动一个守护进程

-m 是分配给Memcache使用的内存数量,单位是MB,默认64MB

-M return error on memory exhausted (rather than removing items)

-u 是运行Memcache的用户,如果当前为root 的话,需要使用此参数指定用户

-l 是监听的服务器IP地址,默认为所有网卡

-p 是设置Memcache的TCP监听的端口,最好是1024以上的端口

-c 选项是最大运行的并发连接数,默认是1024

-P 是设置保存Memcache的pid文件

-f chunk size growth factor (default: 1.25)

-I Override the size of each slab page. Adjusts max item size(1.4.2版本新增)

例子:

/usr/local/memcached/bin/memcached -d -m 100 -c 1000 -u root -p 11211

可以启动多个守护进程,但是端口不能重复。设置开机启动的话可以将上行命令增加到/etc/rc.d/rc.local文件中。

4 如果要结束Memcache进程,执行:

# kill `cat /tmp/memcached.pid`


5 测试Memcached::
telnet 192.168.141.64 12000
Trying 192.168.141.64...
Connected to 192.168.141.64 (192.168.141.64).
Escape character is '^]'.
set key1 0 60 4
zhou
STORED
get key1
VALUE key1 0 4
zhou

python-memcache:

linux system:
1 wget ftp://ftp.tummy.com/pub/python-memcached/python-memcached-1.53.tar.gz
2 解压缩 tar -zxvf python-memcached-1.53.tar.gz 
3 切换到目录 cd..
4 python setup.py install
如果报错:
需要预先安装python-setuptools (命令yum instal python-setuptools 如果此方法不好用就使用以下方法)
python安装setuptools的方法
linux 下:apt-get install python-setuptools

安装完就可以使用easy_install命令
安装easy_install package-name 
卸载easy_install -m package-name 

测试python-memcache
#!/usr/bin/env python
import memcache

pymem = memcache.Client(['x.x.x.x:11211'],debug=0)
pymem.set("key5","hello,memcache!")
value = pymem.get("key5")
print value 

原文地址:https://www.cnblogs.com/dasydong/p/4064555.html