Linux下的Memcache的安装方法
这篇文章主要讲解了"Linux下的Memcache的安装方法",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"Linux下的Memcache的安装方法"吧!
由于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
则系统会显示:
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
感谢各位的阅读,以上就是"Linux下的Memcache的安装方法"的内容了,经过本文的学习后,相信大家对Linux下的Memcache的安装方法这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!