1. 下载, memcached需要先安装libevent
memcached的下载地址:http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gzs
http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz最新版
libevent的下载地址 :http://www.monkey.org/~provos/libevent-1.2.tar.gz
http://www.monkey.org/~provos/libevent/
#cd /usr/local
#mkdir memcached
#mkdir libevent
2. 安装libevent
# tar xzvf libevent-1.2.tar.gz
# cd libevent-1.2
# ./configure --prefix=/usr/local/libevent
# make
# make install
检查是否安装成功:
#cd /usr/local/libevent/lib
如果有libevent-1.3c.so.1 libevent-1.3c.so.1.0.3 libevent.a libevent.la libevent.so 这几个文件存在,说明安装成功
3.安装memcached
# tar xzvf memcached-1.2.6.tar.gz
# cd memcached-1.2.6
# ./configure --with-libevent=/usr/local/libevent --prefix=/usr/local/memcached
# make
# make install
检查是否安装成功:
#cd /usr/local/memcached/bin
如果memcached memcached-debug这2个文件存在,说明安装成功
4.执行
#cd /usr/local/memcached/bin
# ./memcached -h
如果出现:
1. memcached 1.2.6
2. -p TCP port number to listen on (default: 11211)
3. -U UDP port number to listen on (default: 0, off)
4. -s unix socket path to listen on (disables network support)
5. -l interface to listen on, default is INDRR_ANY
6. -d run as a daemon
7. -r maximize core file limit
8. -u assume identity of (only when run as root)
9. -m max memory to use for items in megabytes, default is 64 MB
10. -M return error on memory exhausted (rather than removing items)
11. -c max simultaneous connections, default is 1024
12. -k lock down all paged memory
13. -v verbose (print errors/warnings while in event loop)
14. -vv very verbose (also print client commands/reponses)
15. -h print this help and exit
16. -i print memcached and libevent license
17. -b run a managed instanced (mnemonic: buckets)
18. -P save PID in , only used with -d option
19. -f chunk size growth factor, default 1.25
20. -n minimum space allocated for key+value+flags, default 48
说明安装成功,并且路径配置正确。
有可能会出现:
memcached: error while loading shared libraries: libevent-1.2.so.1: cannot open shared object file: No such file or directory
说明 没有找到文件:libevent-1.2.so.1
解决办法:
第一步. 查看下lib路径:
[farman@localhost bin]$ LD_DEBUG=libs /usr/local/memcached/bin/memcached -v
31386: find library=libevent-1.2.so.1 [0]; searching
31386: search cache=/etc/ld.so.cache
31386: 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)
31386: trying file=/lib/tls/i686/sse2/libevent-1.2.so.1
31386: trying file=/lib/tls/i686/libevent-1.2.so.1
31386: trying file=/lib/tls/sse2/libevent-1.2.so.1
31386: trying file=/lib/tls/libevent-1.2.so.1
31386: trying file=/lib/i686/sse2/libevent-1.2.so.1
31386: trying file=/lib/i686/libevent-1.2.so.1
31386: trying file=/lib/sse2/libevent-1.2.so.1
31386: trying file=/lib/libevent-1.2.so.1
31386: trying file=/usr/lib/tls/i686/sse2/libevent-1.2.so.1
31386: trying file=/usr/lib/tls/i686/libevent-1.2.so.1
31386: trying file=/usr/lib/tls/sse2/libevent-1.2.so.1
31386: trying file=/usr/lib/tls/libevent-1.2.so.1
31386: trying file=/usr/lib/i686/sse2/libevent-1.2.so.1
31386: trying file=/usr/lib/i686/libevent-1.2.so.1
31386: trying file=/usr/lib/sse2/libevent-1.2.so.1
31386: trying file=/usr/lib/libevent-1.2.so.1
31386:
/home/farman/cacheinstall/bin/memcached: error while loading shared libraries: libevent-1.2.so.1: cannot open shared object file: No such file or directory
第二步. 将libevent-1.3c.so.1拷贝到任何一个列出的lib 下就可以了。
或者 软链接
[farman@localhost lib]$ su root
Password:
[root@localhost lib]# ln -s /home/farman/install/lib/libevent-1.2.so.1 /usr/lib/libevent-1.2.so.1
启动服务 :
[root@localhost lib]# exit
不能用root启动
前台启动测试
[farman@localhost bin]#./memcached -m 10 -p 12000 -c 256 -vv
后台启动
[farman@localhost bin]#./memcached -d -m 10 -p 12000 -c 256 -P /tmp/memcached.pid
./memcached -d -m 128 -u root -l 127.0.0.1 -p 11211 -c 64 -P /tmp/memcached.pid
参数说明:
-d选项是启动一个守护进程
-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB
-u是运行Memcache的用户,我这里是root
-l是监听的服务器IP地址
-p是设置Memcache监听的端口,最好是1024以上的端口
-c选项是最大运行的并发连接数,默认是1024,按照你服务器的负载量来设定
-P是设置保存Memcache的pid文件