三个区别
当你听到memcache与memcached时把它当做是一个东东就好了,尽管它们存在区别,但是这并不影响你对它们的运用及理解。
“Memcache”它是一个自由和开放源代码、高性能、分配的内存对象缓存系统,即该系统名称为“Memcache”;
“Memcached”它是该系统的主程序文件,以守护程序方式运行于一个或多个服务器中(分布式),随时接受客户端的连接操作,使用共享内存存取数据;
“Memcachedb”它是新浪2007年的项目,在Memcached的基础上开发出来了,它与Memcache不同的是它提供了数据持久化存储
memcached 安装
由于memcached安装时,需要使用libevent类库,所以先安装libevent
libevent下载网址:http://www.monkey.org/~provos/libevent/
本手册中下载的是 libevent-1.4.8-stable.tar.gz版本安装步骤如下:
1. 解压缩
tar xzfv libevent-1.4.8-stable.tar.gz
2. 进入到 libevent-1.4.8-stable目录
cd libevent-1.4.8-stable
3. 编译,安装
./configure
make
make install
注:默认安装到/usr/local/lib/ 目录
接下来,安装memcached
memcached下载网址:http://www.danga.com/memcached/download.bml
本手册中下载的是 memcached-1.2.6.tar.gz版本
安装步骤如下:
1. 解压缩
tar xzfv memcached-1.2.6.tar.gz
2. 进入到 memcached-1.2.6目录
cd memcached-1.2.6
3. 编译,安装
./configure --prefix=/local/memcached
make
make install
安装完成后,会在 /local/memcached 出现 bin和share目录
进行 bin目录,启动 memcache
方法如下:
./memcached -d -u nobody -m 512 127.0.0.1 -p 11211
此时,会报一个异常
error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
原因是找不到libevent-1.4.so.2类库,解决办法如下:
使用LD_DEBUG=help ./memcached -v来确定 加载的类库路径,方法如下:
LD_DEBUG=libs ./memcached -v 2>&1 > /dev/null | less
则系统会显示:
<!-- <br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /> <br /> -->linux:/local/memcached/bin # LD_DEBUG = libs ./memcached -v 2 >& 1 > /dev/null | less
20421 : find library = libevent- 1.4 .so .2 ; searching
20421 : search cache = /etc/ld.so.cache
20421 : search path = /lib/tls/i686/sse2:/lib/tls/i686:/lib/tls/sse2:/lib/tls:/lib/i686/sse2:/lib/i686:/lib/sse2:/lib:/usr/lib/tls/i686
/sse2:/usr/lib/tls/i686:/usr/lib/tls/sse2:/usr/lib/tls:/usr/lib/i686/sse2:/usr/lib/i686:/usr/lib/sse2:/usr/lib (system search path)
20421 : trying file = /lib/tls/i686/sse2/libevent- 1.4 .so .2
20421 : trying file = /lib/tls/i686/libevent- 1.4 .so .2
20421 : trying file = /lib/tls/sse2/libevent- 1.4 .so .2
20421 : trying file = /lib/tls/libevent- 1.4 .so .2
20421 : trying file = /lib/i686/sse2/libevent- 1.4 .so .2
20421 : trying file = /lib/i686/libevent- 1.4 .so .2
20421 : trying file = /lib/sse2/libevent- 1.4 .so .2
20421 : trying file = /lib/libevent- 1.4 .so .2
20421 : trying file = /usr/lib/tls/i686/sse2/libevent- 1.4 .so .2
20421 : trying file = /usr/lib/tls/i686/libevent- 1.4 .so .2
20421 : trying file = /usr/lib/tls/sse2/libevent- 1.4 .so .2
20421 : trying file = /usr/lib/tls/libevent- 1.4 .so .2
20421 : trying file = /usr/lib/i686/sse2/libevent- 1.4 .so .2
20421 : trying file = /usr/lib/i686/libevent- 1.4 .so .2
20421 : trying file = /usr/lib/sse2/libevent- 1.4 .so .2
20421 : trying file = /usr/lib/libevent- 1.4 .so .2
20421 :
./memcached: error while loading shared libraries: libevent- 1.4 .so .2 : cannot open shared object file: No such file or directory
我们看到,memcached会到很多地方去找,所以根据其它求,我们只需建一个软链接,指定到我们安装的类库上即可
方法如下:
ln -s /usr/local/lib/libevent-1.4.so.2 /lib/libevent-1.4.so. 2
现在可以正常启动memcached了
./memcached -d -u nobody -m 512 127.0.0.1 -p 11211
到这里,看到memcached已经启动,说明安装成功。
如果要结束Memcache进程,执行:
# kill `cat /tmp/memcached.pid`
也可以启动多个守护进程,不过端口不能重复。
memcache启动参数说明:
-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,
-u是运行Memcache的用户,我这里是root,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.0.200,
-p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid
memcached 自己操作安装记录
1)下载tomcat lib的依赖包 ,修改防火墙,添加端口 8280 11211
2)下载memcached的依赖包 # yum install libevent-devel [libevent-1.4.13-4.el6.x86_64]
3)下载memcached,因为goole问题,使用最新版本 # wget http://memcached.org/latest [memcached-1.4.20.tar.gz]
安装: wget http://memcached.org/latest
tar -zxvf memcached-1.x.x.tar.gz
cd memcached-1.x.x
./configure --prefix=/cssdata/memcached && make && make test && sudo make install
memcachedb 安装
1. 先安装libevent
tar zxvf libevent-1.2.tar.gz
cd libevent-1.2
./configure –prefix=/usr
make
make install
2.测试libevent是否安装成功
ls -al /usr/lib | grep libevent
3.安装Berkeley Db
tar -zxvf db-4.6.19.tar.gz
cd db-4.6.19/build_unix/
../dist/configure
make && make install
#如果没有指定特殊安装路径,编译完成,需要将Berkeley Db运行库的路径添加到系统配置里面
echo "/usr/local/BerkeleyDB.4.6/lib/" >> /etc/ld.so.conf
#重载系统Ld运行库
ldconfig
4.安装memcachedb,同时需要安装中指定libevent的安装位置
cd /tmp
tar -zxvf memcachedb-1.0.3.tar.gz
cd memcachedb-1.0.3
./configure –with-libevent=/usr
make
make install
安装完成后会把memcachedb放到 /usr/local/bin/memcachedb
5.测试是否成功安装memcachedb
ls -al /usr/local/bin/mem*
6.启动memcachedb
memcachedb -p 11212 -d -r -u root -l localhost -H /data/mdb_11212 -N -P /tmp/memcachedb.pid
7.如查报Berkeley Db的文件找不到的可以加上下面这句话
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/BerkeleyDB.4.6/lib