MEMCACHED-服务部署搭建

系统环境:

  • Cento7.2.1511
  • Memcache1.5.8

部署安装:

安装依赖服务:

yum install gcc -y
wget https://down.niknk.com/MEMCACHED/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/
make && make install
ls /usr/lib
cd ..
  • 编译安装MEMCACHE服务:
wget https://down.niknk.com/MEMCACHED/memcached-1.5.8.tar.gz
tar xf memcached-1.5.8.tar.gz
cd memcached-1.5.8
./configure --with-libevent=/usr
make && make install
cd ..
  • 启动MEMCACHED服务:
memcached -p 11211 -u root -m 512m -c 10240 -l 127.0.0.1  -d

PHP扩展插件:

以下是针对PHP7.1来安装memcache扩展。
memcache 扩展分为memcache.so扩展及memcached.so扩展两个扩展不一样。

  • memcache 扩展依赖安装
yum install m4 autoconf git -y
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
tar -zxf libmemcached-1.0.18.tar.gz
cd libmemcached-1.0.18/
./configure
make && make install
cd ..
  • memcache.so 扩展安装
git clone https://github.com/websupport-sk/pecl-memcache memcache
cd memcache/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config 
make && make install
cat >>  /usr/local/php/etc/php.ini <<EOF
extension = memcache.so
EOF
/etc/init.d/php-fpm restart
  • memcached.so 扩展安装
git clone https://github.com/php-memcached-dev/php-memcached.git
cd php-memcached/
git checkout php7
/usr/local/php/bin/phpize
./configure --disable-memcached-sasl
make install
cat >>  /usr/local/php/etc/php.ini <<EOF
extension = memcached.so
EOF
/etc/init.d/php-fpm restart

以下是针对PHP5来安装memcache扩展

wget https://down.niknk.com/MEMCACHED/memcache-2.2.5.tgz
tar xf memcache-2.2.5.tgz
cd memcache-2.2.5 && ./config &&
/usr/local/php/bin/phpize  ./configure
./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config \
--with-zlib-dir
make && make install
  • Session 会话使用memcache
vim /application/php/etc/php.ini
session.save_handler = memcache
session.save_path = "tcp://IP"

参数详解:

-p 指定启动服务端口
-u 指定启动用户
-m 指定memcahce分配内存大小
-c 并发连接数默认是1024
-l 监听服务器IP地址
-P 指定memcache的pid文件位置
-v 输出警告和错误信息
-vv 打印客户端的请求和返回信息

点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注