Linux下memcached安装和启动方法

一、安装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.24.tar.gz

# cd memcached-1.4.24

#./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/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更新一下配置即可。

五、启动和查看

cd /usr/local/memcached/bin

./memcached -d -m 1024 -u root -l 192.168.1.38 -p 12677 -c 256 -P /tmp/chenxinhan/memcached.pid 
参数说明: 
-d 选项是启动一个守护进程, 
-m 是分配给Memcache使用的内存数量,单位是MB,这里是1GB, 
-u 是运行Memcache的用户,这里是root, 
-l 是监听的服务器IP地址,如果有多个地址的话,以逗号隔开。这里指定了服务器的IP地址192.168.13.236, 
-p 是设置Memcache监听的端口,我这里设置了12001,最好是1024以上的端口, 
-c 选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定, 
-P 是设置保存Memcache的pid文件,我这里是保存在 /tmp/chenxinhan/memcached.pid, 

查看memcache进程

ps -ef |grep memcache

六、测试

 安装 telnet yum -y install telnet

# telnet 127.0.0.1 12677

出现以下信息表示启动成功
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.


你可能感兴趣的:(Linux下memcached安装和启动方法)