CentsOS(Linux) Memcache 安装教程


安装

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.bkjia.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.bkjia.com ~]# sudo ln -s /usr/local/lib/libevent-1.3b.so.1 /lib/libevent-1.3b.so.1  

检查是否建立成功

  1. [root@www.bkjia.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 (default11211)  
  3. -U <num>      UDP port number to listen on (default0, 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.bkjia.com bin]# memcached -d -m 128 -u root -p 11211  
检查是否已经启动
  1. [root@www.bkjia.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.bkjia.com bin]# cd /usr/local/bin  
  2. [root@www.bkjia.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安装成功了

相关内容