由于memcached安裝時,需要使用libevent類庫,所以先安裝libevent
libevent下載網(wǎng)址: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下載網(wǎng)址: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 出現(xiàn) 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
則系統(tǒng)會顯示:
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
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會到很多地方去找,所以根據(jù)其它求,我們只需建一個軟鏈接,指定到我們安裝的類庫上即可
方法如下:
ln -s /usr/local/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2
現(xiàn)在可以正常啟動memcached了
./memcached -d -u nobody -m 512 127.0.0.1 -p 11211
到這里,看到memcached已經(jīng)啟動,說明安裝成功。
memcache啟動參數(shù)說明:
The options for memcached are:
-l <ip_addr>
Listen on <ip_addr>; default to INDRR_ANY. This is an important option to consider as there is no other way to secure the installation. Binding to an internal or firewalled network interface is suggested.
-d
Run memcached as a daemon.
-u <username>
Assume the identity of <username> (only when run as root).
-m <num>
Use <num> MB memory max to use for object storage; the default is 64 megabytes.
-M
Instead of throwing items from the cache when max memory is reached, throw an error
-c <num>
Use <num> max simultaneous connections; the default is 1024.
-k
Lock down all paged memory. This is a somewhat dangerous option with large caches, so consult the README and memcached homepage for configuration suggestions.
-p <num>
Listen on port <num>, the default is port 11211.
-r
Maximize core file limit
-M
Disable automatic removal of items from the cache when out of memory. Additions will not be possible until adequate space is freed up.
-r
Raise the core file size limit to the maximum allowable.
-h
Show the version of memcached and a summary of options.
-v
Be verbose during the event loop; print out errors and warnings.
-vv
Be even more verbose; same as -v but also print client commands and responses.
-i
Print memcached and libevent licenses.
-P <filename>
Print pidfile to <filename>, only used under -d option.
-l <ip_addr>
Listen on <ip_addr>; default to INDRR_ANY. This is an important option to consider as there is no other way to secure the installation. Binding to an internal or firewalled network interface is suggested.
-d
Run memcached as a daemon.
-u <username>
Assume the identity of <username> (only when run as root).
-m <num>
Use <num> MB memory max to use for object storage; the default is 64 megabytes.
-M
Instead of throwing items from the cache when max memory is reached, throw an error
-c <num>
Use <num> max simultaneous connections; the default is 1024.
-k
Lock down all paged memory. This is a somewhat dangerous option with large caches, so consult the README and memcached homepage for configuration suggestions.
-p <num>
Listen on port <num>, the default is port 11211.
-r
Maximize core file limit
-M
Disable automatic removal of items from the cache when out of memory. Additions will not be possible until adequate space is freed up.
-r
Raise the core file size limit to the maximum allowable.
-h
Show the version of memcached and a summary of options.
-v
Be verbose during the event loop; print out errors and warnings.
-vv
Be even more verbose; same as -v but also print client commands and responses.
-i
Print memcached and libevent licenses.
-P <filename>
Print pidfile to <filename>, only used under -d option.
Good Luck!
Yours Matthew!