Linux下的Memcache安装

在一台64位Linux的机器上安装了MemCached,遇到一个小问题,特记录之。

MemCached 使用了libevent ,所以必须先安装 libevent。安装libevent到/usr/lib

wget http://www.monkey.org/~provos/libevent-1.4.9-stable.tar.gz
gzip -d libevent-1.4.9-stable.tar.gz
tar xvf libevent-1.4.9-stable.tar
cd libevent-1.4.9-stable
./configure --prefix=/usr
make
make install

安装MemCached的到/opt/memcached

wget http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz
gzip -d memcached-1.2.6.tar.gz
tar xvf memcached-1.2.6.tar
cd memcached-1.2.6
./configure --prefix=/opt/memcached --with-libevent=/usr
make
make install

但是执行memcached命令时出现错误:

#/opt/memcached/bin/memcached -h
/opt/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2:
cannot open shared object file: No such file or directory

一般对于这种依赖的库找不到的情况,在Linux中可以通过设置LD_DEBUG 环境变量来获得更多的信息

#LD_DEBUG=help ls
Valid options for the LD_DEBUG environment variable are:

  libs        display library search paths
  reloc       display relocation processing
  files       display progress for input file
  symbols     display symbol table processing
  bindings    display information about symbol binding
  versions    display version dependencies
  all         all previous options combined
  statistics  display relocation statistics
  unused      determined unused DSOs
  help        display this help message and exit

To direct the debugging output into a file instead of standard output
a filename can be specified using the LD_DEBUG_OUTPUT environment variable.

这里由于是库文件依赖有问题,则使用libs参数:

#LD_DEBUG=libs /opt/memcached/bin/memcached -h
     30596:     find library=libevent-1.4.so.2 [0]; searching
     30596:      search cache=/etc/ld.so.cache
     30596:      search path=/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/usr/lib64/tls/x86_64
/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64
(system search path)
     30596:       trying file=/lib64/tls/x86_64/libevent-1.4.so.2
     30596:       trying file=/lib64/tls/libevent-1.4.so.2
     30596:       trying file=/lib64/x86_64/libevent-1.4.so.2
     30596:       trying file=/lib64/libevent-1.4.so.2
     30596:       trying file=/usr/lib64/tls/x86_64/libevent-1.4.so.2
     30596:       trying file=/usr/lib64/tls/libevent-1.4.so.2
     30596:       trying file=/usr/lib64/x86_64/libevent-1.4.so.2
     30596:       trying file=/usr/lib64/libevent-1.4.so.2
     30596:
/opt/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2:
cannot open shared object file: No such file or directory

可以看到是在加载/usr/lib64/libevent-1.4.so.2文件时出现了问题,系统中确实是没有该文件的,查找后发现 libevent-1.4.so.2存在于/usr/lib目录,这可能是libevent在64位Linux系统上的一个bug吧,没有关系,复制一份 或者建一个软链接即可解决问题。

#ln -s /usr/lib/libevent-1.4.so.2 /usr/lib64/libevent-1.4.so.2
#/opt/memcached/bin/memcached -h
memcached 1.2.6
-p       TCP port number to listen on (default: 11211)
-U       UDP port number to listen on (default: 0, off)
-s      unix socket path to listen on (disables network support)
-a      access mask for unix socket, in octal (default 0700)
-l   interface to listen on, default is INDRR_ANY
-d            run as a daemon
-r            maximize core file limit
-u  assume identity of  (only when run as root)
-m       max memory to use for items in megabytes, default is 64 MB
-M            return error on memory exhausted (rather than removing items)
-c       max simultaneous connections, default is 1024
-k            lock down all paged memory.  Note that there is a
              limit on how much memory you may lock.  Trying to
              allocate more than that would fail, so be sure you
              set the limit correctly for the user you started
              the daemon with (not for -u  user;
              under sh this is done with 'ulimit -S -l NUM_KB').
-v            verbose (print errors/warnings while in event loop)
-vv           very verbose (also print client commands/reponses)
-h            print this help and exit
-i            print memcached and libevent license
-b            run a managed instanced (mnemonic: buckets)
-P      save PID in , only used with -d option
-f    chunk size growth factor, default 1.25
-n     minimum space allocated for key+value+flags, default 48

启动MemCached,-m表示分配的内存

#/opt/memcached/bin/memcached -d -m 1024 -u admin -l 127.0.0.1 -p 11211

 

 


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,cache,socket,unix,memcached)