1. 环境
2. 安装(下载源码包全部放至/usr/local/src目录下,先cd切换到/usr/local/src目录下工作)
-
安装libevent(memcache网络库部分基于libevent库开发,解决了不同平台的差异性)
-
下载:wget https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz
-
解压: tar xf libevent-2.1.8-stable.tar.gz
-
进入目录: cd libevent-2.1.8-stable
-
安装: ./configure --prefix=/usr/local/libevent-2.1.8 && make && make install
-
做软链接 ln -s /usr/local/libevent-2.1.8 /usr/local/libevent
-
-
安装memcached
-
下载: wget http://www.memcached.org/files/memcached-1.4.35.tar.gz
-
解压: tar xf memcached-1.4.35.tar.gz
-
进入目录: cd memcached-1.4.35
-
编译安装:./configure --prefix=/usr/local/memcached-1.4.35 --with-libevent=/usr/local/libevent && make && make install
-
做软链接: ln -s /usr/local/memcached-1.4.35 /usr/local/memcached
-
-
创建系统用户, 并且不创建家目录
-
useradd -r -s /sbin/nologin -M memcached
-
-
编辑并添加memcached启动脚本(当前路径还在memcached-1.4.35源码包目录里)
-
-
进入脚本目录: cd scripts
-
复制脚本至init.d目录下: cp memcached.sysv /etc/init.d/memcached
-
创建memcached运行目录, 并改变其用户与用户组为memcached
-
mkdir /var/run/memcached
-
chown memcached.memcached /var/run/memcached
-
-
编辑脚本: (/etc/init.d/memcached)
-
daemon memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcached/memcached.pid $OPTIONS 改为 daemon /usr/local/memcached/bin/memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcached/memcached.pid $OPTIONS
-
-
(可选)删除脚本中以下内容
-
PORT=11211
USER=nobody
MAXCONN=1024
CACHESIZE=64
OPTIONS=""
-
-
创建参数脚本并添加参数
-
-
-
-
创建touch /etc/sysconfig/memcached
-
更改用户与用户组 chown memcached.memcached /etc/sysconfig/memcached
-
添加内容
-
-
PORT=11211
USER=memcached
MAXCONN=1024
CACHESIZE=64
OPTIONS="-l 0.0.0.0,::1"
-
-
将memcached添加进service管理,并开机启动
-
-
-
-
chkconfig --add memcached
-
chkconfig memcached on
-
-
3. 测试
-
启动: /etc/init.d/memcached start 或者 service memcached start
启动成功
4. 连接(通过telnet测试连接)
telnet 127.0.0.1 11211
为PHP安装Memcached扩展连接Memcached http://www.linuxidc.com/Linux/2016-05/131690.htm
Linux下Memcached安装与启用 http://www.linuxidc.com/Linux/2016-07/133423.htm
Memcached构建缓存加速集群部署 http://www.linuxidc.com/Linux/2017-02/140656.htm
Linux CentOS 7 下通过Memcached实现Session共享 http://www.linuxidc.com/Linux/2016-09/135552.htm
Memcached的安装配置及将PHP的session保存在Memcached中 http://www.linuxidc.com/Linux/2017-02/140679.htm
Linux CentOS 7 下通过Memcached实现Session共享 http://www.linuxidc.com/Linux/2016-09/135552.htm
CentOS 6.6下Memcached 源码安装配置 http://www.linuxidc.com/Linux/2015-09/123019.htm
Linux CentOS 7下Memcached 安装与配置 http://www.linuxidc.com/Linux/2016-09/135553.htm