在一台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的到/u01/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=/u01/memcached --with-libevent=/usr make make install
但是执行memcached命令时出现错误:
#/u01/memcached/bin/memcached -h /u01/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 /u01/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: /u01/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 #/u01/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表示分配的内存
#/u01/memcached/bin/memcached -d -m 1024 -u admin -l 127.0.0.1 -p 11211
./memcached -d -m 1024 -u root -l 10.1.4.195 -p 11211
选项 | 说明 |
-p | 使用的TCP端口。默认为11211 |
-m | 最大内存大小。默认为64M |
-vv | 用very vrebose模式启动,调试信息和错误输出到控制台 |
-d | 作为daemon在后台启动 |
上面四个是常用的启动选项,其他还有很多,通过