1.安装所需依赖
yum install wget gcc gcc-c++
2.源码编译安装libevent库
创建并进入源码存放目录
mkdir -p /usr/local/src
cd /usr/local/src
下载,解压
wget -c https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz
tar -zxvf libevent-2.1.8-stable.tar.gz
配置,编译,安装
cd libevent-2.1.8-stable
./configure --prefix=/usr/local/libevent-2.1.8
make -j4
make install
3.安装memcached
进入源码目录,下载,解压
cd /usr/local/src
wget -c http://www.memcached.org/files/memcached-1.5.12.tar.gz
tar -zxvf memcached-1.5.12.tar.gz
配置,编译,安装
cd memcached-1.5.12
./configure --prefix=/usr/local/memcached \
--with-libevent=/usr/local/libevent-2.1.8
make -j4
make install
4.设置启动脚本
创建系统用户,不允许登陆和不创建主目录
useradd -r -s /sbin/nologin -M memcached
复制脚本至init.d目录下
cp /usr/local/src/memcached-1.5.12/scripts/memcached.sysv /etc/init.d/memcached
编辑脚本
vim /etc/init.d/memcached
注释以下配置
#PORT=11211
#USER=nobody
#MAXCONN=1024
#CACHESIZE=64
#OPTIONS=""
找到
......
start () {
echo -n $"Starting $prog: "
# insure that /var/run/memcached has proper permissions
chown $USER /var/run/memcached
daemon memcached
......
#将daemon memcached更改为daemon /usr/local/memcached/bin/memcached
创建并编辑配置文件
vim /etc/sysconfig/memcached
写入配置信息
PORT=11211
USER=memcached
MAXCONN=1024
CACHESIZE=64
OPTIONS="-l 0.0.0.0,::1"
设置权限
chown memcached.memcached /etc/sysconfig/memcached
创建memcached进程文件目录,并设置权限
mkdir -p /var/run/memcached
chown memcached.memcached /var/run/memcached
加入服务
chkconfig --add memcached
开机启动
chkconfig memcached on
启动
[root@jmsite init.d]# service memcached start
正在启动 memcached: [确定]
memcached服务管理
service memcached start
service memcached stop
service memcached restart
service memcached reload
5.使用telnet测试
telnet 127.0.0.1 11211
如果提示-bash: telnet: command not found,则安装:yum install telnet telnet-server,没有则忽略该步骤
[root@jmsite init.d]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
set a 0 0 4
1234
STORED
get a
VALUE a 0 4
1234
END
quit
Connection closed by foreign host.
[root@jmsite init.d]#
memcached常用配置参数和命令请移步memcached常用配置参数和命令说明
原文地址:https://www.jmsite.cn/blog-194.html