linux下Memcached的安装和启动
原帖地址:http://dapeng725.blog.sohu.com/136682788.html
下载libevent、memcached
wget http://www.danga.com/memcached/dist/memcached-1.4.0.tar.gz
wget http://www.monkey.org/~provos/libevent-1.2.tar.gz
解包
cd /usr/local
tar -xzvf libevent-1.4.tar.gz
tar -xzvf memcached-1.2.5.tar.gz
处理libevent
cd /usr/local/libevent-1.2/
./configure --prefix=/usr/local/libevent
make
make install
处理memcached
cd /usr/local/memcached-1.2.5/
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
make
make install
ll/usr/local/libevent/lib/
存在类似如下文件
libevent-1.4.so.1 -> libevent-1.4.so.1.0.3
libevent-1.4.so.1.0.3
libevent.a
libevent.la
libevent.so -> libevent-1.4.so.1.0.3
添加memcached lib
利用 LD_DEBUG=libs bin/memcached –v 确定lib
32位机
ln -s /usr/local/libevent/lib/libevent-1.4.so.1 /usr/lib
ln -s /usr/local/libevent/lib/libevent-1.4.so.2 /usr/lib
64位机
ln -s /usr/local/libevent/lib/libevent-1.2.so.1 /usr/lib64
cd /usr/local/memcached
/usr/local/memcached/bin/memcached -h
-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
出现如上信息是,表明安装正常
注意:查看需要加的lib文件夹,当出现:
memcached: error while loading shared libraries: libevent-1.3c.so.1: cannot open shared object file: No such file or directory
时,利用 LD_DEBUG=libs bin/memcached –v 调试
启动memcache:
./memcached -help
./memcached -d -m 1024 -u root -p 11211 -c 1024 -p /tmp/memcached.pid
开机启动
echo /usr/local/memcached/bin/memcached -d -m 10 -u root -l 218.16.118.105 -p 11211 -c 256 -P /tmp/memcached.pid >> /etc/rc.local
启动参数说明:
-d 选项是启动一个守护进程,
-m 是分配给Memcache使用的内存数量,单位是MB,默认64MB
-M return error on memory exhausted (rather than removing items)
-u 是运行Memcache的用户,如果当前为root 的话,需要使用此参数指定用户。
-l 是监听的服务器IP地址,默认为所有网卡。
-p 是设置Memcache的TCP监听的端口,最好是1024以上的端口
-c 选项是最大运行的并发连接数,默认是1024