memcached部署

memcached簡介

memcached是一套分佈式的高速緩存系統,由LiveJournal的Brad Fitzpatrick開發,但被許多網站使用。這是一套開放源代碼軟件,以BSD license授權發佈

特點

  • 協議簡單
  • 基於libevent的事件處理
  • 內置內存存儲方式
  • memcached不互相通信的分佈式

缺點

  • 缺乏認證以及安全管制
  • 不支持持久化

實驗部署memcached

1、部署服務端
(1)安裝環境包

[root@memcached ~]# yum install gcc gcc-c++ make -y

(2)安裝事件庫

[root@memcached memcached]# tar zxvf libevent-2.1.8-stable.tar.gz -C /opt
[root@memcached memcached]# cd /opt/libevent-2.1.8-stable/
[root@memcached libevent-2.1.8-stable]# ./configure --prefix=/usr/local/libevent
[root@memcached libevent-2.1.8-stable]# make && make install

(3)安裝mencached

[root@memcached memcached]# tar zxvf memcached-1.5.6.tar.gz -C /opt
[root@memcached memcached]# cd /opt/memcached-1.5.6/
[root@memcached memcached-1.5.6]# ./configure \
> --prefix=/usr/local/memcached \
> --with-libevent=/usr/local/libevent

[root@memcached memcached-1.5.6]# make && make install
[root@memcached ~]# ln -s /usr/local/memcached/bin/* /usr/local/bin/
[root@90memcached ~]# memcached -d -m 32m -p 11211 -u root

(4)登陸測試

[root@memcached ~]# yum install telnet -y
[root@memcached ~]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
#創建
add username 0 0 7
#add--創建;username--鍵值名稱;0 0 7:0-不設置序列號 0-無時間要求 7-輸入字節長度
1234567
STORED
#查看
get username
VALUE username 0 7
1234567
END
#刪除
delete username 
DELETED
get username
END
#

2、安裝客戶端,使用LAMP架構

[root@lamp memcached]# tar zxvf memcache-2.2.7.tgz -C /opt

在解壓目錄下無配置腳本,需要手動生成
在這裏插入圖片描述

#增加爲PHP的模塊後再對memcache進行配置
[root@lamp memcache-2.2.7]# /usr/local/php5/bin/phpize

在這裏插入圖片描述

[root@lamp memcache-2.2.7]# ./configure \
> --enable-memcache \
> --with-php-config=/usr/local/php5/bin/php-config

[root@lamp memcache-2.2.7]# make && make install
[root@lamp memcache-2.2.7]# vim /usr/local/php5/php.ini
extension_dir="/usr/local/php5/lib/php/extensions/no-debug-zts-20131226/"
extension=memcache.so

3、用客戶端去檢測服務端是否可以連接

[root@lamp memcache-2.2.7]# vim /usr/local/httpd/htdocs/index.php
<?php
$memcache = new Memcache();
$memcache->connect('192.168.7.128',11211);
$memcache->set('key','Memcache test Successfull!',0,60);
$result = $memcache->get('key');
unset($memcache);
echo $result;
?>

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章