1. 程式人生 > >centos7.4搭建Memcached(1)

centos7.4搭建Memcached(1)

memcached 反向代理

memcahced是一種基於內存的反向代理系統。
是典型的C/S架構:分為服務端memcached和客戶端memchched API 。


本例:
服務端192.168.80.81
需要安裝libevent-2.1.8-stable.tar.gz(跨平臺的事件處理接口的封裝,memcached安裝需要依賴)
memcached-1.5.6.tar.gz 服務端軟件

客戶端192.168.80.82
需要安裝lamp架構(mysql可不裝)
memcache-2.2.7.tgz 客戶端軟件

win10測試機192.168.80.79


1.首先進行服務端的配置:
tar xf memcached-1.5.6.tar.gz -C /opt/

tar xf libevent-2.1.8-stable.tar.gz -C /opt/

cd /opt/libevent-2.1.8-stable
./configure --prefix=/usr/local/libevent

make && make install

cd /opt/memcached-1.5.6

./configure \
--prefix=/usr/local/memcached \
--with-libevent=/usr/local/libevent/

make && make install

ln -s /usr/local/libevent/lib/libevent-1.4.so.2.1.2 /usr/lib64/libevent-1.4.so.2 //不可缺少

cd /usr/local/memcached/bin/

./memcached -d -m 32m -p 11211 -u root

netstat -anpt | grep memc

service firewalld stop
setenforce 0

telnet 127.0.0.1 11211

set userid 0 0 5 //不進行壓縮和序列化標識 數據過期時間為永不過期 標識號是5就需要輸入5位數。

12345 //輸入5位數

get userid //獲取數據

stats //顯示狀態信息

quit //退出

2.客戶端配置:
安裝lap 不需要裝mysql php5.6(php不能裝高版本,否則不兼容)

yum install autoconf -y

tar xf memcache-2.2.7.tgz -C /opt/

cd /opt/memcache-2.2.7

/usr/local/php5/bin/phpize //增加為PHP的模塊後再對memcache進行配置編譯

./configure \
--enable-memcache \
--with-php-config=/usr/local/php5/bin/php-config

make && make install

/usr/local/php5/lib/php/extensions/no-debug-zts-20131226/ //記錄此行下面用到

vi /usr/local/php5/php.ini //搜索並修改下面一行,再新增一行

extension_dir = "/usr/local/php5/lib/php/extensions/no-debug-zts-20131226/"
extension = memcache.so

vi /usr/local/httpd/htdocs/index.php

<?php
$memcache = new Memcache();
$memcache->connect(‘192.168.80.81‘,11211);
$memcache->set(‘key‘,‘Memcache test Successfull!‘,0,60);
$result = $memcache->get(‘key‘);
unset($memcache);
echo $result;
?>
//編寫測試頁面,測試memcached工作是否正常,若正常,則顯示Memcache test Successfull!
service httpd restart

3.測試:
win10訪問客戶端http://192.168.80.82/index.php //輸入客戶端地址測試是否成功
從而實現了訪問客戶端httpd,調用API,連接到memcached服務端

centos7.4搭建Memcached(1)