您的位置:首页 > 数据库 > Memcache

Memcache 安装

2016-04-05 10:27 561 查看
Memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检索的结果等。简单的说就是将数据调用到内存中,然后从内存中读取,从而大大提高读取速度。

方法1:使用yum安装

yum search memcached

yum -y install memcached

测试是否安装成功

memcached -h

memcache的基本设置

启动memcache的服务端:

memcached -d -m 100 -u root -l xxx.xxx.xx.xxx -p 11211
-c 512 -P /tmp/memcached.pid

参数说明

-d选项是启动一个守护进程;

-m是分配给memcache使用的内存数量,单位是mB,我这里是100mB;

-u是运行memcache的用户,我这里是root;

-l是监听的服务器IP地址我这里指定了服务器的IP地址192.168.0.100;(也可不设定ip
去掉-l 192.168.0.100)

-p是设置memcache监听的端口,我这里设置了11211,最好是1024以上的端口;

-c选项是最大运行的并发连接数,默认是1024,我这里设置了512,按照你服务器的负载量来设定;

-P是设置保存memcache的pid文件,我这里是保存在 /tmp/memcached.pid;

检查memcached是否启动

netstat -an | more

tcp 0 0 xxx.xxx.xx.xxx:11211 0.0.0.

先查看进程的id

ps
-ef|grep memcached

root
15144 1 0 08:43 ? 00:00:00 /usr/local/memcached-1.4.17/bin/memcached -d -m 128 -u root -p 11211 -c 512 -P /tmp/memcached.pid

15144为pid

停止命令为:kill
-9 15144

设置开机启动

chkconfig memcached on

启动和停止

service memcached start | stop

Or /etc/init.d/memcached start | stop

重启centos

shutdown -r now

Or reboot

方法二:使用非yum安装

1.安装之前,需要先确认系统中是否有libevent,因为memcached依赖这个包。

查看:

命令: rpm -qa|grep libevent

显示的包:libevent-1.4.13-4.el6.x86_64

此时,系统已经安装过了,需要卸载重新下载安装。

卸载:rpm -e libevent-1.4.13-4.el6.x86_64

2.下载libevent,并安装

下载地址:https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

解压:

tar -zxvf libevent-2.0.21-stable.tar.gz

安装:

./configure --prefix=/usr/local/libevent (指定安装到/usr/local/libevent目录下)

编译:make

make install

安装完成!

3.下载memcached,并解压

命令: tar -zxvf memcached-1.4.17.tar.gz

安装:

./configure --prefix=/usr/local/memcached-1.4.17

若安装过程中提示找不到libevent路径时,使用--with-libevent=libevent安装的目录

./configure --prefix=/usr/local/memcached-1.4.17 --with-libevent=/usr/local/libevent/

编译:make

make install

安装完成!

4.启动

/usr/local/memcached-1.4.17/bin/memcached -d -m 128 -u root -p 11211 -c 1024 -P /tmp/memcached.pid

启动参数说明:

-d 选项是启动一个守护进程。

-u root 表示启动memcached的用户为root。

-m 是分配给Memcache使用的内存数量,单位是MB,默认64MB。

-M return error on memory exhausted (rather than removing items)。

-u 是运行Memcache的用户,如果当前为root 的话,需要使用此参数指定用户。

-p 是设置Memcache的TCP监听的端口,最好是1024以上的端口。

-c 选项是最大运行的并发连接数,默认是1024。

-P 是设置保存Memcache的pid文件。

5.停止

先查看进程的id

ps -ef|grep memcached

root 15144 1 0 08:43 ? 00:00:00 /usr/local/memcached-1.4.17/bin/memcached -d -m 128 -u root -p 11211 -c 1024 -P /tmp/memcached.pid

15144为pid

也可以启动多个守护进程,不过端口不能重复。

停止命令为:kill -9 15144

测试:

测试Memcached:

telnet ip 端口

Trying ip...

Connected to ip.

Escape character is '^]'.

set key1 0 60 4

zhou

STORED

get key1

VALUE key1 0 4

zhou

END

成功!
http://www.cnblogs.com/zgx/archive/2011/08/10/2134097.html http://www.linuxidc.com/Linux/2014-02/97329.htm http://www.51itstudy.com/24058.html
非常感谢!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: