安装&使用memcached小记
需要首先安装 libevent
libevent:程序地址:http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.17-stable.tar.gz
memcached下载地址:http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
1、安装libevent
假定安装文件所在目录为:/usr/software
进入文件所在目录:
[root@localhost ~]# cd /usr/software
解压并安装文件:
[root@localhost software]# tar zxvf libevent-2.0.10-stable.tar.gz
[root@localhost software]# cd libevent-2.0.10-stable
[root@localhost libevent-2.0.10-stable]# ./configure -–prefix=/usr
[root@localhost libevent-2.0.10-stable]# make && make install
2、安装memcached
将定安装文件所在目录为:/usr/software
进入文件所在目录:
[root@localhost ~]# cd /usr/software
解压文件并安装(安装路径为:/usr/apps/memcached)
[root@localhost software]# tar zxvf memcached-1.4.5.tar.gz
[root@localhost software]# cd memcached-1.4.5
[root@localhost memcached-1.4.5]# ./configure -–prefix=/usr/apps/memcached -–with-libevent=/usr
[root@localhost memcached-1.4.5]# make && make install
3、启动memcached
/usr/apps/memcached/bin/memcached –d –u root –p 11211 –m 512
参数说明:
-d启动一个守护进程
-u指运行memcached的用户
-p设置memcached的监听端口
-m指分配给memcached使用的内存数量,单位M
-l监听服务器的IP地址
-c最大运行的并发连接数,默认为1024
-P设置保存memcached的pid(进程)文件
4、将memcached设置为开机启动
在/etc/rc.local中加入以下命令:
/usr/apps/memcached/bin/memcached –d –u root –p 11211 –m 512
测试是否安装成功:
# ls -al /usr/lib | grep libevent
# ls -al /usr/local/bin/mem*
如果libevent的安装目录为/usr/local/lib下,则还需要建立 libevent-1.4.so.2 到 /usr/lib 的软连接,这样其他程序运行时才能找到libevent库:ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib/libevent-1.4.so.2