Apache+php+memcache集群搭建

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Apache+php+memcache集群搭建相关的知识,希望对你有一定的参考价值。

实验环境:RHEL7.0  server1.example.com  172.25.254.1

                                server2.example.com  172.25.254.2

实验前提:已经编译安装完成phpnginx,具体内容可参考博客前边内容:。

实验内容:1.memcache安装

                 2.编译安装memcache使其支持php

                 3.修改php配置文件并配置memcache的测试页

                 4.测试

安装包:memcache-2.2.5.tgz 


1.memcache安装(memcache的端口号是11211)

[[email protected] ~]# yum install memcached -y

[[email protected] ~]# /etc/init.d/httpd start

[[email protected] ~]# /etc/init.d/memcached start

[[email protected] ~]# curl -I localhost

HTTP/1.1 200 OK

Date: Sun, 11 Sep 2016 16:31:52 GMT

Server: Apache/2.2.15 (Red Hat)

Last-Modified: Sun, 11 Sep 2016 16:15:02 GMT

ETag: "1fca9-8-53c3dae8ae0cf"

Accept-Ranges: bytes

Content-Length: 8

Connection: close

Content-Type: text/html; charset=UTF-8

[[email protected] ~]# telnet 127.0.0.1 11211

Trying 127.0.0.1...

Connected to 127.0.0.1.

Escape character is ‘^]‘.

stats

STAT pid 2759

STAT uptime 14

STAT time 1473611553

STAT version 1.4.4

........................

STAT total_items 0

STAT evictions 0

END


2.编译安装memcache使其支持php

[[email protected] mnt]# php -m |grep memcache     ###  可以看到php不支持memcached

[[email protected] ~]# cd /mnt/

[[email protected] mnt]# ls

memcache-2.2.5.tgz

[[email protected] mnt]# tar -zxf memcache-2.2.5.tgz   ###解压tar zxf  memcache-2.2.5.tgz

[[email protected] mnt]# cd memcache-2.2.5     ###进入解压目录

[[email protected] memcache-2.2.5]# ls

[[email protected] memcache-2.2.5]# phpize    ##会自动生成configure

Configuring for:

PHP Api Version:         20131106

Zend Module Api No:      20131226

Zend Extension Api No:   220131226

[[email protected] memcache-2.2.5]# yum install libtool -y

[[email protected] memcache-2.2.5]# ./configure \

> --prefix=/usr/local/lnmp/php/modules \

> --enable-memcache

[[email protected] memcache-2.2.5]# make             ##编译

[[email protected] memcache-2.2.5]# make install   ###安装

Installing shared extensions:     /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226/

[[email protected] memcache-2.2.5]# cd /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226/

[[email protected] no-debug-non-zts-20131226]# ls

memcache.so  opcache.a  opcache.so

[[email protected] no-debug-non-zts-20131226]# /etc/init.d/memcached restart


3.编译PHP配置文件并配置memcache的测试页

[[email protected] ~]# vim /usr/local/lnmp/php/etc/php.ini 

    863     extension=memcache.so

[[email protected] ~]# /etc/init.d/fpm restart

[[email protected] ~]# php -m |grep mem        ###查看php是否支持memcached

memcache

[[email protected] ~]# cd /mnt/memcache-2.2.5 

[[email protected] memcache-2.2.5]# cp example.php memcache.php /usr/local/lnmp/nginx/html/

[[email protected] memcache-2.2.5]# cd /usr/local/lnmp/nginx/html/

[[email protected] html]# vim example.php   ##分析信息不做修改

 22 define(‘ADMIN_USERNAME‘,‘memcache‘);    // Admin Username

 23 define(‘ADMIN_PASSWORD‘,‘willis‘);      // Admin Password   ##willis为密码


 28 $MEMCACHE_SERVERS[] = ‘127.0.0.1:11211‘; // add more as an array

 29 #$MEMCACHE_SERVERS[] = ‘mymemcache-server2:11211‘; // add more as an array

[[email protected] html]# nginx -s reload


4.测试

http://172.25.6.10/example.php##访问网站并多次刷新

http://172.25.6.10/memcache.php##查看命中率


技术分享


技术分享




技术分享


技术分享


技术分享


技术分享



本文出自 “技术人生,简单不简单” 博客,请务必保留此出处http://willis.blog.51cto.com/11907152/1853588

以上是关于Apache+php+memcache集群搭建的主要内容,如果未能解决你的问题,请参考以下文章

nginx+apache+php+mysql服务器集群搭建

Linux下安装搭建Memcached集群环境

超简单的memcached集群搭建

Memcached集群/分布式/高可用 及 Magent缓存代理搭建过程 详解

Memcached集群/分布式/高可用 及 Magent缓存代理搭建过程 详解

Memcached集群原理以及搭建