Apache+php+memcache集群搭建

简介:

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

                                server2.example.com  172.25.254.2

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

实验内容:1.memcache安装

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

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

                 4.测试

安装包:memcache-2.2.5.tgz 


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

[root@server1 ~]# yum install memcached -y

[root@server1 ~]# /etc/init.d/httpd start

[root@server1 ~]# /etc/init.d/memcached start

[root@server1 ~]# 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

[root@server1 ~]# 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

[root@server1 mnt]# php -m |grep memcache     ###  可以看到php不支持memcached

[root@server1 ~]# cd /mnt/

[root@server1 mnt]# ls

memcache-2.2.5.tgz

[root@server1 mnt]# tar -zxf memcache-2.2.5.tgz   ###解压tar zxf  memcache-2.2.5.tgz

[root@server1 mnt]# cd memcache-2.2.5     ###进入解压目录

[root@server1 memcache-2.2.5]# ls

[root@server1 memcache-2.2.5]# phpize    ##会自动生成configure

Configuring for:

PHP Api Version:         20131106

Zend Module Api No:      20131226

Zend Extension Api No:   220131226

[root@server1 memcache-2.2.5]# yum install libtool -y

[root@server1 memcache-2.2.5]# ./configure \

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

> --enable-memcache

[root@server1 memcache-2.2.5]# make             ##编译

[root@server1 memcache-2.2.5]# make install   ###安装

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


[root@server1 memcache-2.2.5]# cd /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226/

[root@server1 no-debug-non-zts-20131226]# ls

memcache.so  opcache.a  opcache.so

[root@server1 no-debug-non-zts-20131226]# /etc/init.d/memcached restart


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

[root@server1 ~]# vim /usr/local/lnmp/php/etc/php.ini 

    863     extension=memcache.so

[root@server1 ~]# /etc/init.d/fpm restart

[root@server1 ~]# php -m |grep mem        ###查看php是否支持memcached

memcache

[root@server1 ~]# cd /mnt/memcache-2.2.5 

[root@server1 memcache-2.2.5]# cp example.php memcache.php /usr/local/lnmp/nginx/html/

[root@server1 memcache-2.2.5]# cd /usr/local/lnmp/nginx/html/

[root@server1 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

[root@server1 html]# nginx -s reload


4.测试

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

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


wKiom1feHw_T1_49AABJ6N0Rd3k727.png


wKioL1feHxCxiodGAAA2_iwLyFE937.png




wKiom1feHxGx3krkAAERJFXkOfM028.png


wKioL1feHxGx7X2AAAA3Zv1FvqQ300.png


wKioL1feHxLQLtRAAAC_Ei-MgW4823.png


wKiom1feHxOyaL-jAAA2uxe4c80661.png



本文转自willis_sun 51CTO博客,原文链接:http://blog.51cto.com/willis/1853588,如需转载请自行联系原作者

相关文章
|
消息中间件 存储 监控
构建高可用性Apache Kafka集群:从理论到实践
【10月更文挑战第24天】随着大数据时代的到来,数据传输与处理的需求日益增长。Apache Kafka作为一个高性能的消息队列服务,因其出色的吞吐量、可扩展性和容错能力而受到广泛欢迎。然而,在构建大规模生产环境下的Kafka集群时,保证其高可用性是至关重要的。本文将从个人实践经验出发,详细介绍如何构建一个高可用性的Kafka集群,包括集群规划、节点配置以及故障恢复机制等方面。
396 4
|
8月前
|
Ubuntu PHP
Ubuntu下使用apt为Apache2编译PHP7.1
以上就是在Ubuntu系统下,使用apt为Apache2编译PHP7.1的过程。希望这个过程对你有所帮助,如果你在执行过程中遇到任何问题,都可以在网上找到相关的解决方案。
160 25
|
8月前
|
Ubuntu PHP Apache
在Ubuntu系统中为apt的apache2编译PHP 7.1的方法
以上就是在Ubuntu系统中为apt的apache2编译PHP 7.1的方法。希望这个指南能帮助你成功编译PHP 7.1,并在你的Apache服务器上运行PHP应用。
195 28
|
8月前
|
关系型数据库 MySQL Linux
查看Linux、Apache、MySQL、PHP版本的技巧
以上就是查看Linux、Apache、MySQL、PHP版本信息的方法。希望这些信息能帮助你更好地理解和使用你的LAMP技术栈。
396 17
|
存储 分布式计算 druid
大数据-152 Apache Druid 集群模式 配置启动【下篇】 超详细!(一)
大数据-152 Apache Druid 集群模式 配置启动【下篇】 超详细!(一)
186 1
大数据-152 Apache Druid 集群模式 配置启动【下篇】 超详细!(一)
|
数据库连接 PHP Apache
PHP在Apache中如何运行?
PHP在Apache中如何运行?
431 5
|
分布式计算 大数据 分布式数据库
大数据-158 Apache Kylin 安装配置详解 集群模式启动(一)
大数据-158 Apache Kylin 安装配置详解 集群模式启动(一)
246 5
|
资源调度 大数据 分布式数据库
大数据-158 Apache Kylin 安装配置详解 集群模式启动(二)
大数据-158 Apache Kylin 安装配置详解 集群模式启动(二)
224 2
apache+tomcat配置多站点集群的方法
apache+tomcat配置多站点集群的方法
157 4
|
消息中间件 分布式计算 druid
大数据-152 Apache Druid 集群模式 配置启动【下篇】 超详细!(二)
大数据-152 Apache Druid 集群模式 配置启动【下篇】 超详细!(二)
147 2

推荐镜像

更多