1、下载memcached服务器端安装文件,版本: memcached-1.4.2.tar.gz。
2、下载libevent,memcached需要用到socked,依赖此安装文件。版本: libevent-1.4.12-stable.tar.gz。
3、由于linux系统可能默认已经安装libevent,执行命令:
rpm -qa|grep libevent
查看系统是否带有该安装软件。如果有执行命令:
rpm -e libevent-1.1a-3.2.1 --nodeps(由于系统自带的版本旧,忽略依赖删除)
4、安装libevent,
tar zxvf libevent-1.4.12-stable.tar.gz
cd libevent-1.4.12-stable
./configure --prefix=/usr/local/libevent-1.4
make && make install
5、安装memcached
tar zxvf memcached-1.4.2.tar.gz
cd memcached-1.4.2
./configure --prefix=/usr/local/memcached-1.4.2 --with-libevent=/usr/local/libevent-1.4/
make && make install
至此memcached安装完毕
6、测试
当启动memcached时经常不能发现libevent.so;可以通过以下命令检查:
进入/usr/local/memcached-1.4.2/bin目录
LD_DEBUG=help ./memcached -v
LD_DEBUG=libs ./ memcached -v
解决方法:
ln -s /usr/local/libevent-1.4/lib/libevent-1.4.so.2 /lib64/libevent-1.4.so.2
7、启动memcache:
./memcached -help
./memcached -d -m 1024 -u root -p 11211 -c 1024 -P /tmp/memcached.pid
启动参数说明:
- -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
- -P 是设置保存Memcache的pid文件
- -fchunk size growth factor (default: 1.25)
- -I Override the size of each slab page. Adjusts max item size(1.4.2版本新增)
也可以启动多个守护进程,但是端口不能重复
8、停止Memcache进程:
kill `cat /tmp/memcached.pid`
一、安装gcc
# yum -y install gcc
二、安装libevent
# wget http://www.monkey.org/~provos/libevent-2.0.12-stable.tar.gz
# tar zxf libevent-2.0.12-stable.tar.gz
# cd libevent-2.0.12-stable
#./configure --prefix=/usr/local/lib
# make && make install
三、安装make
# yum -y install make
四、下载安装最新版本:http://memcached.org/downloads
# wget http://memcached.org/files/memcached-1.4.20.tar.gz
# cd memcached-1.4.20
#./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/lib && make && make install
五、配置启动
# vi /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/usr/sbin/ntpdate ntpupdate.tencentyun.com >/dev/null 2>&1 &
/usr/local/agenttools/agent/startagent.sh /usr/local/agenttools/agent /dev/null
#secu-tcs-agent bootstart, install at Tue Apr 29 17:21:38 CST 2014.
/usr/local/sa/agent/secu-tcs-agent-mon-safe.sh > /dev/null 2>&1
/usr/local/memcached/bin/memcached -p 12677 -U 0 -d -r -u root -m 2040 -c 1024 -t 4
保存后退出,手动启动服务
# /usr/local/memcached/bin/memcached -p 12677 -U 0 -d -r -u root -m 2040 -c 1024 -t 4注:如果出现/usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory异常在/etc/ld.so.conf中加入/usr/local/lib这一行,保存之后,再运行:/sbin/ldconfig –v更新一下配置即可。
# vi /etc/ld.so.conf
# /sbin/ldconfig -V
六、测试memcached
# telnet 127.0.0.1 12677
出现以下信息表示启动成功
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.