memcached安装
1. 下载, memcached需要先安装libevent
memcached的下载地址:http://danga.com/memcached/download.bml
libevent的下载地址 :http://www.monkey.org/~provos/libevent/
2. 安装libevent
# tar xzvf libevent-1.3c.tar.gz
# cd libevent-1.3c
# ./configure --prefix=/home/mahaibo/install
# make
# make install
检查是否安装成功:
# cd /home/mahaibo/install/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.2.tar.gz
# cd memcached-1.2.2
# ./configure --with-libevent=/home/mahaibo/install --prefix=/home/mahaibo/installmemcache
# make
# make install
检查是否安装成功:
# cd /home/mahaibo/installmemcache/bin
如果memcached memcached-debug这2个文件存在,说明安装成功
4.启动
# cd /home/mahaibo/installmemcache/bin
# ./memcached -h
如果出现:
memcached 1.2.2
-p <num></num> TCP port number to listen on (default: 11211)
-U <num></num> UDP port number to listen on (default: 0, off)
-s <file></file> unix socket path to listen on (disables network support)
-l <ip_addr></ip_addr> interface to listen on, default is INDRR_ANY
-d run as a daemon
-r maximize core file limit
-u <username></username> assume identity of <username></username> (only when run as root)
-m <num></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></num> max simultaneous connections, default is 1024
-k lock down all paged memory
-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></file> save PID in <file></file>, only used with -d option
-f <factor></factor> chunk size growth factor, default 1.25
-n <bytes></bytes> minimum space allocated for key+value+flags, default 48
说明安装成功,并且路径配置正确。
有可能会出现:memcached: error while loading shared libraries: libevent-1.3c.so.1: cannot open shared object file: No such file or directory 说明没有找到文件:libevent-1.3c.so.1
解决办法:
第一步. 查看下lib路径:
LD_DEBUG=libs /home/mahaibo/installmemcache/bin/memcached -v
第二步. 将libevent-1.3c.so.1拷贝到任何一个列出的lib 下就可以了。或者 修改vi /etc/profile文件。
# export LIBRARY_PATH=:/usr/local/lib:"/usr/local/BerkeleyDB.4.3/lib":/usr/local/lib:/opt/Ice-3.1/lib:/usr/lib:/home/mahaibo/install/lib
启动服务:
# ./memcached -d -m 10 -u root -l 192.168.40.4 -p 12000 -c 256 -P /tmp/memcached.pid
参数说明:
-d选项是启动一个守护进程
-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB
-u是运行Memcache的用户,我这里是root
-l是监听的服务器IP地址
-p是设置Memcache监听的端口,最好是1024以上的端口
-c选项是最大运行的并发连接数,默认是1024,按照你服务器的负载量来设定
-P是设置保存Memcache的pid文件