Memcached安装并启用PHP扩展支持
环境:Centos 6.6PHP version:5.5.38
memcached version:1.4.33
官网:https://memcached.org/
Memcached Githup:https://github.com/memcached/memcached/wiki
安装libevent:
# ntpdate time.windows.com
# wget https://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
# tar -zxf libevent-2.0.21-stable.tar.gz
# cd libevent-2.0.21-stable
# ./configure --prefix=/usr/local/libevent
# make && make install
# ls /usr/local/libevent/
binincludelib
# 安装Memcached:
# wget https://memcached.org/files/memcached-1.4.33.tar.gz
# tar -zxf memcached-1.4.33.tar.gz
# cd memcached-1.4.33
# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
# make && make install
# ls /usr/local/memcached/
binincludeshare
# 安装php扩展模块memcache:
# yum -y install php55w php55w-cli php55w-common php55w-devel php55w-gd php55w-odbc php55w-mysql php55w-fpm nginx
# wget http://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz
# tar -zxf zlib-1.2.8.tar.gz
# cd zlib-1.2.8
# ./configure --prefix=/usr/local/zlib
# make && make install
# wget http://pecl.php.net/get/memcache-2.2.7.tgz
# tar -xf memcache-2.2.7.tgz
# cd memcache-2.2.7
# phpize //如果没有安装phpize,安装php55w-devel
Configuring for:
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212
#
# ./configure --enable-memcache --with-php-config=/usr/bin/php-config --with-zlib-dir=/usr/local/zlib/
# make && make install
····
Installing shared extensions: /usr/lib64/php/modules/
#
# make test 在php.ini文件,在zend之前加入如下代码:
# head -352 /etc/php.ini | tail -3
extension_dir = "/usr/lib64/php/modules/"
extension = memcache.so
#http://s2.运维网.com/wyfs02/M00/8A/58/wKioL1gubRyRUv24AAAjNrlVJqU556.png
# cd /usr/share/nginx/html
# cat info.php
#
# /etc/init.d/php-fpm start
# /etc/init.d/nginx start
# chkconfig --add php-fpm
# chkconfig --add nginx
# chkconfig php-fpm on
# chkconfig nginx on //启动Memcached
# /usr/local/memcached/bin/memcached -d -u root -m 512 -p 11211 127.0.0.1 -c 10240 -P /usr/local/memcached/memcached.pid //指定启动线程数,默认启动4个线程
启动参数说明:
-d 选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,默认64MB
-Mreturn error on memory exhausted (rather than removing items)
-u是运行Memcache的用户,如果当前为root 的话,需要使用此参数指定用户。
-l 是监听的服务器IP地址,默认为所有网卡。
-p是设置Memcache的TCP监听的端口,最好是1024以上的端口
-c选项是最大运行的并发连接数,默认是1024
-P是设置保存Memcache的pid文件
http://s1.运维网.com/wyfs02/M01/8A/58/wKioL1gubTPgMQW4AAATmh3C_cM015.png
http://s1.运维网.com/wyfs02/M01/8A/58/wKioL1gubTODUp7cAAAZT93CvoI266.png
# php -m | grep memcache
memcache
#
http://s2.运维网.com/wyfs02/M02/8A/58/wKioL1gubUzhw-MRAAAzjDbMYsA456.png
http://s2.运维网.com/wyfs02/M00/8A/5C/wKiom1gubU2yErrtAAAk9dHBXc8665.png
Nginx配置:
# cat /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name192.168.70.188;
charset utf8;
access_log/var/log/nginx/log/host.access.logmain;
location / {
root /usr/share/nginx/html;
indexindex.php index.html index.htm;
}
location ~ ^(.+.php)(.*)$ {
root /usr/share/nginx/html;
fastcgi_split_path_info ^(.+.php)(.*)$;
include fastcgi.conf;
fastcgi_pass127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_paramPATH_INFO $fastcgi_path_info;
}
error_page 500 502 503 504/50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
#
# cat /etc/nginx/fastcgi.conf
fastcgi_paramSCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_paramQUERY_STRING $query_string;
fastcgi_paramREQUEST_METHOD $request_method;
fastcgi_paramCONTENT_TYPE $content_type;
fastcgi_paramCONTENT_LENGTH $content_length;
fastcgi_paramSCRIPT_NAME $fastcgi_script_name;
fastcgi_paramREQUEST_URI $request_uri;
fastcgi_paramDOCUMENT_URI $document_uri;
fastcgi_paramDOCUMENT_ROOT $document_root;
fastcgi_paramSERVER_PROTOCOL $server_protocol;
fastcgi_paramHTTPS $https if_not_empty;
fastcgi_paramGATEWAY_INTERFACECGI/1.1;
fastcgi_paramSERVER_SOFTWARE nginx/$nginx_version;
fastcgi_paramREMOTE_ADDR $remote_addr;
fastcgi_paramREMOTE_PORT $remote_port;
fastcgi_paramSERVER_ADDR $server_addr;
fastcgi_paramSERVER_PORT $server_port;
fastcgi_paramSERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_paramREDIRECT_STATUS 200;
# 成功。
页:
[1]