为了账号安全,请及时绑定邮箱和手机立即绑定

Apache+php+memcache集群搭建

标签:
PHP

实验环境: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



点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消