安装
Linux:CentOS 5.4
安装libevent库
- cd /usr/local/src
- wget http://monkey.org/~provos/libevent-1.3b.tar.gz
- tar zxvf libevent-1.3b.tar.gz
- cd libevent-1.3b
- ./configure
- make && make install
安装memcache
- cd /usr/local/src
- wget http://danga.com/memcached/dist/memcached-1.2.5.tar.gz
- tar zxvf memcached-1.2.5.tar.gz
- cd memcached-1.2.5
- ./configure
- make && make install
- cd usr/local/bin
- bin] # memcached –h
- 出错
- memcached: error while loading shared libraries: libevent-1.3b.so.1: cannot open shared object file: No such file or directory
则运行 LD_DUBUG=libs 就可以知道memcached启动时库的加载路径。具体如下
- [root@www.linuxidc.com usr/local/bin]# LD_DEBUG=libs memcached –v
- 5112: find library=libevent-1.3b.so.1 [0]; searching
- 5112: search cache=/etc/ld.so.cache
- 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)
- 5112: trying file=/lib/tls/i686/sse2/libevent-1.3b.so.1
- 5112: trying file=/lib/tls/i686/libevent-1.3b.so.1
- 5112: trying file=/lib/tls/sse2/libevent-1.3b.so.1
- 5112: trying file=/lib/tls/libevent-1.3b.so.1
- 5112: trying file=/lib/i686/sse2/libevent-1.3b.so.1
- 5112: trying file=/lib/i686/libevent-1.3b.so.1
- 5112: trying file=/lib/sse2/libevent-1.3b.so.1
- 5112: trying file=/lib/libevent-1.3b.so.1
- 5112: trying file=/usr/lib/tls/i686/sse2/libevent-1.3b.so.1
- 5112: trying file=/usr/lib/tls/i686/libevent-1.3b.so.1
- 5112: trying file=/usr/lib/tls/sse2/libevent-1.3b.so.1
- 5112: trying file=/usr/lib/tls/libevent-1.3b.so.1
- 5112: trying file=/usr/lib/i686/sse2/libevent-1.3b.so.1
- 5112: trying file=/usr/lib/i686/libevent-1.3b.so.1
- 5112: trying file=/usr/lib/sse2/libevent-1.3b.so.1
- 5112: trying file=/usr/lib/libevent-1.3b.so.1
- [root@www.linuxidc.com ~]# sudo ln -s /usr/local/lib/libevent-1.3b.so.1 /lib/libevent-1.3b.so.1
检查是否建立成功
- [root@www.linuxidc.com ~]# ls -al /lib|grep libevent
- lrwxrwxrwx 1 root root 33 Aug 25 19:52 libevent-1.3b.so.1 -> /usr/local/lib/libevent-1.3b.so.1
- bin] # memcached –h
- memcached 1.2.5
- -p <num> TCP port number to listen on (default: 11211)
- -U <num> UDP port number to listen on (default: 0, off)
- -s <file> unix socket path to listen on (disables network support)
- -a <mask> access mask for unix socket, in octal (default 0700)
- -l <ip_addr> interface to listen on, default is INDRR_ANY
- -d run as a daemon
- -r maximize core file limit
- -u <username> assume identity of <username> (only when run as root)
- -m <num> max memory to use for items in megabytes, default is 64 MB
- -M return error on memory exhausted (rather than removing items)
- -c <num> 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 <username> 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 <file> save PID in <file>, only used with -d option
- -f <factor> chunk size growth factor, default 1.25
- -n <bytes> minimum space allocated for key+value+flags, default 48
默认情况下memcached安装到/usr/local/bin下。
启动:
- [root@www.linuxidc.com bin]# memcached -d -m 128 -u root -p 11211
- [root@www.linuxidc.com bin]# telnet 127.0.0.1 11211
- Trying 127.0.0.1…
- Connected to localhost.localdomain (127.0.0.1).
- Escape character is ‘^]’.
选项说明
p 使用的TCP端口。默认为11211
m 最大内存大小。默认为64M
vv 用very vrebose模式启动,调试信息和错误输出到控制台
d 作为daemon在后台启动
查看memcached的内部状态
- [root@www.linuxidc.com bin]# cd /usr/local/bin
- [root@www.linuxidc.com bin]# telnet 127.0.0.1 11211
- Trying 127.0.0.1…
- Connected to localhost.localdomain (127.0.0.1).
- Escape character is ‘^]’.
- stats
- STAT pid 6779
- STAT uptime 14217
- STAT time 1314343512
- STAT version 1.2.5
- STAT pointer_size 32
- STAT rusage_user 0.002999
- STAT rusage_system 0.027995
- STAT curr_items 0
- STAT total_items 0
- STAT bytes 0
- STAT curr_connections 3
- STAT total_connections 4
- STAT connection_structures 4
- STAT cmd_get 0
- STAT cmd_set 0
- STAT get_hits 0
- STAT get_misses 0
- STAT evictions 0
- STAT bytes_read 56
- STAT bytes_written 482
- STAT limit_maxbytes 134217728
- STAT threads 1
- END
- Quit