首先是安装libevent库,执行如下的命令
tar vzxf libevent-2.0.21-stable.tar.gz cd libevent-2.0.21-stable ./configure --prefix=/usr/local/libevent-2.0.21 make && make install echo '/usr/local/libevent-2.0.21/lib'>> /etc/ld.so.conf.d/user-defined.conf ldconfig |
之后是安装memcached可执行文件
tar -xvf memcached-1.4.15.tar.gz cd memcached-1.4.15 ./configure --prefix=/usr/local/memcached-1.4.15 --with-libevent=/usr/local/libevent-2.0.21 make && make install |
最后,安装php的memcached插件所需的libmemcached库
tar -xvf libmemcached-1.0.2.tar.gz cd libmemcached-1.0.2 ./configure --prefix=/usr/local/libmemcached-1.0.2 --with-memcached=/usr/local/memcached-1.4.15/bin --with-libevent-prefix=/usr/local/libevent-2.0.21 make && make install echo '/usr/local/libmemcached-1.0.2/lib'>>/etc/ld.so.conf.d/user-defined.conf ldconfig |
最后是配置memcached,
useradd www -d /data/www cd /usr/local/memcached-1.4.15 mkdir etc touch etc/memcached cd /etc/init.d/ touch memcached chmod +x memcached |
在/usr/local/ memcached-1.4.15/etc/ memcached中添加如下的内容
PORT="11211" #连接端口 USER="www" #执行用户 MAXCONN="1024" #最大连接数 CACHESIZE="64" #内存大小 OPTIONS="-l 127.0.0.1" #其他的所有可用参数可以写在这里 |
在/etc/init.d/memcached文件中的内容,可以从源码包的conf文件夹中获取,记得需要赋予可执行权限。配置之后就可以通过service memcached start启动服务。