由于memcached安装时,需要使用libevent类库,所以先安装libevent
libevent下载网址:http://www.monkey.org/~provos/libevent/
官方网站下载地址:http://libevent.org/本次安装用的是 libevent-2.0.21-stable.tar.gz 版本安装步骤如下:
1. 解压缩
tar xzfv libevent-2.0.21-stable.tar.gz
2. 进入到 libevent-2.0.21-stable目录
cd libevent-2.0.21-stable
3. 编译,安装
./configure
make
make install
注:默认安装到/usr/local/lib/ 目录
接下来,安装memcached
memcached下载网址:http://www.memcached.org/
本手册中下载的是 memcached-1.4.20.tar.gz版本
安装步骤如下:
1. 解压缩
tar xzfv memcached-1.4.20.tar.gz
2. 进入到 memcached-1.4.20目录
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-2.0.so.5: cannot open shared object file: No such file or directory
原因是找不到libevent-2.0.so.5类库,解决办法如下:
使用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-2.0.so.5 ; 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-2.0.so.5
20421 : trying file = /lib/tls/i686/libevent-2.0.so.5
20421 : trying file = /lib/tls/sse2/libevent-2.0.so.5
20421 : trying file = /lib/tls/libevent-2.0.so.5
20421 : trying file = /lib/i686/sse2/libevent-2.0.so.5
20421 : trying file = /lib/i686/libevent-2.0.so.5
20421 : trying file = /lib/sse2/libevent-2.0.so.5
20421 : trying file = /lib/libevent-2.0.so.5
20421 : trying file = /usr/lib/tls/i686/sse2/libevent-2.0.so.5
20421 : trying file = /usr/lib/tls/i686/libevent-2.0.so.5
20421 : trying file = /usr/lib/tls/sse2/libevent-2.0.so.5
20421 : trying file = /usr/lib/tls/libevent-2.0.so.5
20421 : trying file = /usr/lib/i686/sse2/libevent-2.0.so.5
20421 : trying file = /usr/lib/i686/libevent-2.0.so.5
20421 : trying file = /usr/lib/sse2/libevent-2.0.so.5
20421 : trying file = /usr/lib/libevent-2.0.so.5
20421 :
./memcached: error while loading shared libraries: libevent-2.0.so.5 : cannot open shared object file: No such file or directory
我们看到,memcached会到很多地方去找,所以根据其它求,我们只需建一个软链接,指定到我们安装的类库上即可
方法如下:
ln -s /usr/local/lib/libevent-2.0.so.5 /lib/libevent-2.0.so.5
现在可以正常启动memcached了
./memcached -d -u nobody -m 512 127.0.0.1 -p 11211
到这里,看到memcached已经启动,说明安装成功。
测试:通过其他机器telnet 此机器的端口 ps:虚拟机上的端口是否已经打开
最后做启动文件,下次可以直接使用
1startmemcache.sh 内容为:local/memcached/bin/memcached -d -m 10 -u redhat -l 192.168.199.101 -p 11211 -c 256 -P /tmp/memcached.pid 2stopmemecache.sh内容为: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