在Linux環境上安裝memcached手冊

由於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啓動參數說明:

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.
發佈了61 篇原創文章 · 獲贊 0 · 訪問量 5135
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章