歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> CentsOS(Linux) Memcache 安裝教程

CentsOS(Linux) Memcache 安裝教程

日期:2017/2/28 15:54:39   编辑:Linux教程

安裝

Linux:CentOS 5.4

安裝libevent庫

  1. cd /usr/local/src
  2. wget http://monkey.org/~provos/libevent-1.3b.tar.gz
  3. tar zxvf libevent-1.3b.tar.gz
  4. cd libevent-1.3b
  5. ./configure
  6. make && make install
安裝成功
安裝memcache
  1. cd /usr/local/src
  2. wget http://danga.com/memcached/dist/memcached-1.2.5.tar.gz
  3. tar zxvf memcached-1.2.5.tar.gz
  4. cd memcached-1.2.5
  5. ./configure
  6. make && make install
啟動
  1. cd usr/local/bin
  2. bin] # memcached –h
  3. 出錯
  4. memcached: error while loading shared libraries: libevent-1.3b.so.1: cannot open shared object file: No such file or directory
google解決方法: http://bbs.yiwz.net/archiver/?tid-86.html

則運行 LD_DUBUG=libs 就可以知道memcached啟動時庫的加載路徑。具體如下

  1. [root@www.linuxidc.com usr/local/bin]# LD_DEBUG=libs memcached –v
  2. 5112: find library=libevent-1.3b.so.1 [0]; searching
  3. 5112: search cache=/etc/ld.so.cache
  4. 5112: 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)
  5. 5112: trying file=/lib/tls/i686/sse2/libevent-1.3b.so.1
  6. 5112: trying file=/lib/tls/i686/libevent-1.3b.so.1
  7. 5112: trying file=/lib/tls/sse2/libevent-1.3b.so.1
  8. 5112: trying file=/lib/tls/libevent-1.3b.so.1
  9. 5112: trying file=/lib/i686/sse2/libevent-1.3b.so.1
  10. 5112: trying file=/lib/i686/libevent-1.3b.so.1
  11. 5112: trying file=/lib/sse2/libevent-1.3b.so.1
  12. 5112: trying file=/lib/libevent-1.3b.so.1
  13. 5112: trying file=/usr/lib/tls/i686/sse2/libevent-1.3b.so.1
  14. 5112: trying file=/usr/lib/tls/i686/libevent-1.3b.so.1
  15. 5112: trying file=/usr/lib/tls/sse2/libevent-1.3b.so.1
  16. 5112: trying file=/usr/lib/tls/libevent-1.3b.so.1
  17. 5112: trying file=/usr/lib/i686/sse2/libevent-1.3b.so.1
  18. 5112: trying file=/usr/lib/i686/libevent-1.3b.so.1
  19. 5112: trying file=/usr/lib/sse2/libevent-1.3b.so.1
  20. 5112: trying file=/usr/lib/libevent-1.3b.so.1
然後給libevent-1.3b.so.1建立一個鏈接:
  1. [root@www.linuxidc.com ~]# sudo ln -s /usr/local/lib/libevent-1.3b.so.1 /lib/libevent-1.3b.so.1

檢查是否建立成功

  1. [root@www.linuxidc.com ~]# ls -al /lib|grep libevent
  2. lrwxrwxrwx 1 root root 33 Aug 25 19:52 libevent-1.3b.so.1 -> /usr/local/lib/libevent-1.3b.so.1
此時在
  1. bin] # memcached –h
  1. memcached 1.2.5
  2. -p <num> TCP port number to listen on (default: 11211)
  3. -U <num> UDP port number to listen on (default: 0, off)
  4. -s <file> unix socket path to listen on (disables network support)
  5. -a <mask> access mask for unix socket, in octal (default 0700)
  6. -l <ip_addr> interface to listen on, default is INDRR_ANY
  7. -d run as a daemon
  8. -r maximize core file limit
  9. -u <username> assume identity of <username> (only when run as root)
  10. -m <num> max memory to use for items in megabytes, default is 64 MB
  11. -M return error on memory exhausted (rather than removing items)
  12. -c <num> max simultaneous connections, default is 1024
  13. -k lock down all paged memory. Note that there is a
  14. limit on how much memory you may lock. Trying to
  15. allocate more than that would fail, so be sure you
  16. set the limit correctly for the user you started
  17. the daemon with (not for -u <username> user;
  18. under sh this is done with 'ulimit -S -l NUM_KB').
  19. -v verbose (print errors/warnings while in event loop)
  20. -vv very verbose (also print client commands/reponses)
  21. -h print this help and exit
  22. -i print memcached and libevent license
  23. -b run a managed instanced (mnemonic: buckets)
  24. -P <file> save PID in <file>, only used with -d option
  25. -f <factor> chunk size growth factor, default 1.25
  26. -n <bytes> minimum space allocated for key+value+flags, default 48
現在memcache成功搞定

默認情況下memcached安裝到/usr/local/bin下。

啟動:

  1. [root@www.linuxidc.com bin]# memcached -d -m 128 -u root -p 11211
檢查是否已經啟動
  1. [root@www.linuxidc.com bin]# telnet 127.0.0.1 11211
  2. Trying 127.0.0.1...
  3. Connected to localhost.localdomain (127.0.0.1).
  4. Escape character is '^]'.
這裡使用的memcached啟動選項的內容如下。
選項說明
p 使用的TCP端口。默認為11211
m 最大內存大小。默認為64M
vv 用very vrebose模式啟動,調試信息和錯誤輸出到控制台
d 作為daemon在後台啟動

查看memcached的內部狀態

  1. [root@www.linuxidc.com bin]# cd /usr/local/bin
  2. [root@www.linuxidc.com bin]# telnet 127.0.0.1 11211
  3. Trying 127.0.0.1...
  4. Connected to localhost.localdomain (127.0.0.1).
  5. Escape character is '^]'.
  6. stats
  7. STAT pid 6779
  8. STAT uptime 14217
  9. STAT time 1314343512
  10. STAT version 1.2.5
  11. STAT pointer_size 32
  12. STAT rusage_user 0.002999
  13. STAT rusage_system 0.027995
  14. STAT curr_items 0
  15. STAT total_items 0
  16. STAT bytes 0
  17. STAT curr_connections 3
  18. STAT total_connections 4
  19. STAT connection_structures 4
  20. STAT cmd_get 0
  21. STAT cmd_set 0
  22. STAT get_hits 0
  23. STAT get_misses 0
  24. STAT evictions 0
  25. STAT bytes_read 56
  26. STAT bytes_written 482
  27. STAT limit_maxbytes 134217728
  28. STAT threads 1
  29. END
  30. Quit
到此為止說明你的memcached安裝成功了
Copyright © Linux教程網 All Rights Reserved