首页 > 代码库 > Memcached安装与部署
Memcached安装与部署
1. 准备工作
- 下载libevent:http://monkey.org/~provos/libevent/ (由于memcached与客户端的通信是借助libevent来实现的,所以此动作必须在memcached安装前完成)
- 下载memcached:http://memcached.org/ (注意:memcache是由服务器端和客户端共同组成,此处指memcache的服务器端,客户端在memcache的官网也提供了下载地址)
- 分别把memcached和libevent下载回来,放到 /tmp 目录下:
#cd /tmp
# wget http://www.danga.com/memcached/dist/memcached-1.2.0.tar.gz
# wget http://www.monkey.org/~provos/libevent-1.2.tar.gz
2. libevent安装:
- 先安装libevent:
#tar zxvf libevent-1.2.tar.gz
# cd libevent-1.2
# ./configure –prefix=/usr
# make
# make install - 测试libevent是否安装成功:
#ls -al /usr/lib | grep libevent
lrwxrwxrwx 1 root root 21 11?? 12 17:38libevent-1.2.so.1 -> libevent-1.2.so.1.0.3
-rwxr-xr-x 1 root root 263546 11?? 12 17:38libevent-1.2.so.1.0.3
-rw-r–r– 1 root root 454156 11?? 12 17:38libevent.a
-rwxr-xr-x 1 root root 811 11?? 12 17:38libevent.la
lrwxrwxrwx 1 root root 21 11?? 12 17:38libevent.so -> libevent-1.2.so.1.0.3
3. Memcached安装:
- 安装memcached,同时需要安装中指定libevent的安装位置:
#cd /tmp
# tar zxvf memcached-1.2.0.tar.gz
# cd memcached-1.2.0
# ./configure –with-libevent=/usr
# make
# make install
- 安装memcached,同时需要安装中指定libevent的安装位置:
如果中间出现报错,请仔细检查错误信息,按照错误信息来配置或者增加相应的库或者路径。
安装完成后会把memcached放到 /usr/local/bin/memcached ,
2. 测试是否成功安装memcached:
# ls -al /usr/local/bin/mem*
-rwxr-xr-x 1 root root 137986 11?? 12 17:39/usr/local/bin/memcached
-rwxr-xr-x 1 root root 140179 11?? 12 17:39/usr/local/bin/memcached-debug
3. 启动Memcache的服务器端:
# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.141.64 -p 12000 -c 256 -P /tmp/memcached.pid
4. 配置Memcached自启动
- 编写memcached自启动脚本或直接使用memcached安装包中的脚本
修改自启动脚本(红色部分标识)
2.将此脚本呢cp到/etc/init.d目录下并改名为memcached,然后执行chmod a+x memcached,如下:
# cp memcached.sysv /etc/init.d/memcached
# chmod 755 /etc/init.d/memcached
3.将memcached加入系统服务:
#chkconfig --add memcached
# chkconfig memcached on
4.以服务方式运行memcached
#service memcached start