標籤: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)
[[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##查看命中率
650) this.width=650;" src="http://s5.51cto.com/wyfs02/M02/87/5B/wKiom1feHw_T1_49AABJ6N0Rd3k727.png" style="width:700px;height:79px;" title="Screenshot from 2016-09-15 23:43:56.png" width="700" height="79" border="0" hspace="0" vspace="0" alt="wKiom1feHw_T1_49AABJ6N0Rd3k727.png" />
650) this.width=650;" src="http://s1.51cto.com/wyfs02/M02/87/58/wKioL1feHxCxiodGAAA2_iwLyFE937.png" style="width:500px;height:189px;" title="Screenshot from 2016-09-15 23:44:39.png" width="500" height="189" border="0" hspace="0" vspace="0" alt="wKioL1feHxCxiodGAAA2_iwLyFE937.png" />
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/87/5B/wKiom1feHxGx3krkAAERJFXkOfM028.png" style="width:700px;height:422px;" title="Screenshot from 2016-09-15 23:50:03.png" width="700" height="422" border="0" hspace="0" vspace="0" alt="wKiom1feHxGx3krkAAERJFXkOfM028.png" />
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/87/58/wKioL1feHxGx7X2AAAA3Zv1FvqQ300.png" style="width:500px;height:270px;" title="Screenshot from 2016-09-15 23:50:30.png" width="500" height="270" border="0" hspace="0" vspace="0" alt="wKioL1feHxGx7X2AAAA3Zv1FvqQ300.png" />
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/87/58/wKioL1feHxLQLtRAAAC_Ei-MgW4823.png" style="width:700px;height:253px;" title="Screenshot from 2016-09-15 23:50:44.png" width="700" height="253" border="0" hspace="0" vspace="0" alt="wKioL1feHxLQLtRAAAC_Ei-MgW4823.png" />
650) this.width=650;" src="http://s2.51cto.com/wyfs02/M01/87/5B/wKiom1feHxOyaL-jAAA2uxe4c80661.png" style="width:500px;height:269px;" title="Screenshot from 2016-09-15 23:50:49.png" width="500" height="269" border="0" hspace="0" vspace="0" alt="wKiom1feHxOyaL-jAAA2uxe4c80661.png" />
本文出自 “技術人生,簡單不簡單” 部落格,請務必保留此出處http://willis.blog.51cto.com/11907152/1853588
Apache+php+memcache叢集搭建