关于MemCached在Linux下的安装方法有很多,本文章只是对自己安装的过程进行一个梳理总结。
一、Linux系统:CentOS Release 6.3(Final)
安装软件:libevent-2.0.21-stable.tar.gz 和 memcached-1.4.15.tar.gz
二、安装过程
1、下载软件包
[root@localhost ~]# cd /tmp
[root@localhost tmp]# wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
[root@localhost tmp]# wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
2、安装libevent(MemCached依赖与libevent)
①安装:
[root@localhost tmp]# tar zxvf libevent-2.0.21-stable.tar.gz
[root@localhost tmp]# cd libevent-2.0.21-stable
[root@localhost libevent-2.0.21-stable]# ./configure --prefix=/usr
[root@localhost libevent-2.0.21-stable]# make && make install
说明:安装libevent的时候最好指定--prefix=/usr, 不然在安装memcached的时候可能会报找不到libevent的错误
②测试是否安装成功:[root@localhost libevent-2.0.21-stable]# ls -al /usr/lib | grep libevent
说明:不同版本libevent安装后的文件可能有出入。
3、安装MemCached
①安装:
[root@localhost tmp]# tar zxvf memcached-1.4.15.tar.gz
[root@localhost tmp]# cd memcached-1.4.15
[root@localhost memcached-1.4.15]# ./configure --with-libevent=/usr
[root@localhost memcached-1.4.15]# make && make install
②测试是否安装成功:
[root@localhost memcached-1.4.15]# ls -al /usr/local/bin/memcached
三、MemCached服务器的启动与关闭
1、命令行方式
①启动
[root@localhost ~]# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.138.128 -p 12000 -c 256 -P /tmp/memcached.pid
查看是否启动:
方法1:
[root@localhost ~]# ps aux|grep memcached
方法2:
[root@localhost memcached-1.4.15]# netstat -anp|grep 12000
②关闭
[root@localhost ~]# kill `cat /tmp/memcached.pid`
查看是否关闭:
[root@localhost ~]# ps aux|grep memcached
2、服务方式
①复制启动关闭脚本到初始化目录,并修改权限
[root@localhost memcached-1.4.15]# cp /tmp/memcached-1.4.15/scripts/memcached.sysv /etc/init.d/memcached
[root@localhost memcached-1.4.15]# chmod 755 /etc/init.d/memcached
②修改/etc/init.d/memcached文件
[root@localhost ~]# vi /etc/init.d/memcached
③加入系统服务;启动MemCached服务;查看MemCached服务是否启动成功。
[root@localhost ~]# chkconfig --add memcached
[root@localhost ~]# chkconfig --level 235 memcached on
[root@localhost ~]# chkconfig --list memcached
④启动MemCached服务器;查看MemCached服务器是否启动;关闭MemCached服务器。
[root@localhost ~]# service memcached start
[root@localhost ~]# ps aux | grep memchaced
[root@localhost ~]# service memcached stop
四、如何外部不能进行访问,则修改centos防火墙
[root@hxqlinux ~]# iptables -I INPUT -p tcp --dport 12000 -j ACCEPT
[root@hxqlinux ~]# iptables -I OUTPUT -p tcp --sport 12000 -j ACCEPT
[root@hxqlinux ~]# iptables-save
[root@hxqlinux ~]# service iptables save