Linux下的Memcache安裝及安裝Memcache的PHP擴充安裝

來源:互聯網
上載者:User

Linux下Memcache伺服器端的安裝
伺服器端主要是安裝memcache伺服器端,目前的最新版本是 memcached-1.3.0 。
下載:http://www.danga.com/memcached/dist/memcached-1.2.5.tar.gz
另外,Memcache用到了libevent這個庫用於Socket的處理,所以還需要安裝libevent,libevent的最新版本是libevent-1.3。(如果你的系統已經安裝了libevent,可以不用安裝)
官網:http://www.monkey.org/~provos/libevent/
下載:http://www.monkey.org/~provos/libevent-1.3.tar.gz

用wget指令直接下載這兩個東西.下載回源檔案後。
1.先安裝libevent。這個東西在配置時需要指定一個安裝路徑,即./configure –prefix=/usr;然後make;然後make install;
2.再安裝memcached,只是需要在配置時需要指定libevent的安裝路徑即./configure –with-libevent=/usr;然後make;然後make install;
這樣就完成了Linux下Memcache伺服器端的安裝。詳細的方法如下:


1.分別把memcached和libevent下載回來,放到 /tmp 目錄下:
# cd /tmp
# wget http://www.danga.com/memcached/dist/memcached-1.2.5.tar.gz
# wget http://www.monkey.org/~provos/libevent-1.2.tar.gz

 

2.先安裝libevent:
# tar zxvf libevent-1.2.tar.gz
# cd libevent-1.2
# ./configure –prefix=/usr
# make
# make install

 

3.測試libevent是否安裝成功:
# ls -al /usr/lib | grep libevent
lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent-1.2.so.1 -> libevent-1.2.so.1.0.3
-rwxr-xr-x 1 root root 263546 11?? 12 17:38 libevent-1.2.so.1.0.3
-rw-r–r– 1 root root 454156 11?? 12 17:38 libevent.a
-rwxr-xr-x 1 root root 811 11?? 12 17:38 libevent.la
lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent.so -> libevent-1.2.so.1.0.3
還不錯,都安裝上了。

 

4.安裝memcached,同時需要安裝中指定libevent的安裝位置:
# cd /tmp
# tar zxvf memcached-1.2.0.tar.gz
# cd memcached-1.2.0
# ./configure –with-libevent=/usr
# make
# make install
如果中間出現報錯,請仔細檢查錯誤資訊,按照錯誤資訊來配置或者增加相應的庫或者路徑。
安裝完成後會把memcached放到 /usr/local/bin/memcached ,

 

5.測試是否成功安裝memcached:
# ls -al /usr/local/mem*
-rwxr-xr-x 1 root root 137986 11?? 12 17:39 /usr/local/bin/memcached
-rwxr-xr-x 1 root root 140179 11?? 12 17:39 /usr/local/bin/memcached-debug


查看狀態:service memcached status/restart/stop

查看進程:ps -ef | grep memcached

《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《

http://php.net/manual/zh/memcached.add.php

安裝Memcache的PHP擴充
1.在http://pecl.php.net/package/memcache 選擇相應想要下載的memcache版本。
2.安裝PHP的memcache擴充

tar vxzf memcache-2.2.1.tgz
cd memcache-2.2.1
/usr/local/php/bin/phpize
./configure –enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
make
make install

3.上述安裝完後會有類似這樣的提示:

Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/

4.把php.ini中的extension_dir = “./”修改為

extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/”

5.添加一行來載入memcache擴充:extension=memcache.so

 

 

memcached的基本設定:

1.啟動Memcache的伺服器端:
# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.0.200 -p 12000 -c 256 -P /tmp/memcached.pid

-d選項是啟動一個守護進程,
-m是分配給Memcache使用的記憶體數量,單位是MB,我這裡是10MB,
-u是運行Memcache的使用者,我這裡是root,
-l是監聽的伺服器IP地址,如果有多個地址的話,我這裡指定了伺服器的IP地址192.168.0.200,
-p是設定Memcache監聽的連接埠,我這裡設定了12000,最好是1024以上的連接埠,
-c選項是最大啟動並執行並發串連數,預設是1024,我這裡設定了256,按照你伺服器的負載量來設定,
-P是設定儲存Memcache的pid檔案,我這裡是儲存在 /tmp/memcached.pid,

 

2.如果要結束Memcache進程,執行:

# kill `cat /tmp/memcached.pid`

也可以啟動多個守護進程,不過連接埠不能重複。

 

3.重啟apache,service httpd restart

Memcache環境測試:
運行下面的php檔案,如果有輸出This is a test!,就表示環境搭建成功。開始領略Memcache的魅力把。
< ?php
$mem = new Memcache;
$mem->connect(”127.0.0.1″, 11211);
$mem->set(’key’, ‘This is a test!’, 0, 60);
$val = $mem->get(’key’);
echo $val;
?>

 

-----------------------------

用yum來裝

在CentOS5下為PHP安裝memcache支援

--------------------------------------------------------------------------------
裝了CentOS5之後,由於有了yum這個非常有用的包管理器,我們基本不用親自手動一步步去configure,make,make install了。
只要簡單的運行yum命令就可以搞定,如果你還是需要自己手動編譯,請參閱文末所附參考文檔。

1、檢查安裝第三方軟體倉庫
標準的CentOS5軟體倉庫裡面是沒有memcache相應的包的,不信你自己運行 
yum search memcache

看看結果,是不是提示如下。

Loading “installonlyn” plugin

Setting up Install Process

Setting up repositories

Reading repository metadata in from local files

Parsing package install arguments

Nothing to do

所以,我們的第一步就是匯入第三方軟體倉庫,這裡推薦的是 Dag Wieers 庫(現在叫 RPMForge 了),安裝方法如下:


到安裝庫的網頁http://dag.wieers.com/rpm/packages/rpmforge-release/,找到合適的軟體包,事實上很簡單,我們是centos5.0,由於是和紅帽子企業版5.0同樣的源編譯出來的,那麼要的就是rhel5.0的就可以,備選的就只有以下兩個 
rpmforge-release-0.3.6-1.el5.rf.i386.rpm Fri 09 Mar 2007 16 kB Red Hat EL 5 - i386

rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm Fri 09 Mar 2007 16 kB Red Hat EL 5 - x86_64

我的是32位的系統,我就選擇上面那個地址下載,如果是64位的,選下面那個,呵呵。 
[root@localhost src]# wget http://dag.wieers.com/rpm/packages/r...l5.rf.i386.rpm

[root@localhost src]# rpm -ivh rpmforge-release-0.3.6-1.el5.rf.i386.rpm

後面沒有其他提示,那差不多好了。我們就可以安裝我們的memcache相關的模組了。

 

2、尋找相關軟體包

在尋找的時候會自動更新我們的版本庫索引的,這點從下面可以看出來。我們可以發現有兩個包要裝,一個是 memcache ,一個是php-pecl-memecache。還有個新發現,Python 版本的 memcache 用戶端也有了,爽啊。 
[root@localhost src]# yum search memcache

Loading “installonlyn” plugin

Setting up repositories

update 100% |=========================| 951 B 00:00

rpmforge 100% |=========================| 1.1 kB 00:00

base 100% |=========================| 1.1 kB 00:00

addons 100% |=========================| 951 B 00:00

extras 100% |=========================| 1.1 kB 00:00

Reading repository metadata in from local files

primary.xml.gz 100% |=========================| 1.1 MB 02:07

rpmforge : ################################################## 3907/3907

Added 3907 new packages, deleted 0 old in 13.20 seconds

primary.xml.gz 100% |=========================| 37 kB 00:00

extras : ################################################## 145/145

Added 17 new packages, deleted 0 old in 0.16 seconds
php-pecl-memcache.x86_64 2.0.4-1.el5.rf rpmforge

Matched from:

php-pecl-memcache

PECL package to use the memcached distributed caching system

Memcached is a caching daemon designed especially for dynamic web applications

to decrease database load by storing objects in memory. This extension allows

you to work with memcached through handy OO and procedural interfaces.

http://pecl.php.net/package/memcache

php-pecl-memcache.x86_64 2.1.2-1.el5.rf rpmforge

Matched from:

php-pecl-memcache

PECL package to use the memcached distributed caching system

Memcached is a caching daemon designed especially for dynamic web applications

to decrease database load by storing objects in memory. This extension allows

you to work with memcached through handy OO and procedural interfaces.

http://pecl.php.net/package/memcache

python-memcached.noarch 1.31-1.el5.rf rpmforge

Matched from:

python-memcached

Python interface to the memcached memory cache daemon

Python interface to the memcached memory cache daemon.

ftp://ftp.tummy.com/pub/python-memcached/

memcached.x86_64 1.1.13-4.el5.rf rpmforge

Matched from:

memcached

memcached is a high-performance, distributed memory object caching system,

generic in nature, but intended for use in speeding up dynamic web

applications by alleviating database load.

http://www.danga.com/memcached/

memcached.x86_64 1.2.1-3.el5.rf rpmforge

Matched from:

memcached

memcached is a high-performance, distributed memory object caching system,

generic in nature, but intended for use in speeding up dynamic web

applications by alleviating database load.

http://www.danga.com/memcached/

memcached.x86_64 1.1.13-5.el5.rf rpmforge

Matched from:

memcached

memcached is a high-performance, distributed memory object caching system,

generic in nature, but intended for use in speeding up dynamic web

applications by alleviating database load.

http://www.danga.com/memcached/

memcached.x86_64 1.2.1-4.el5.rf rpmforge

Matched from:

memcached

memcached is a high-performance, distributed memory object caching system,

generic in nature, but intended for use in speeding up dynamic web

applications by alleviating database load.

http://www.danga.com/memcached/

memcached.x86_64 1.2.2-1.el5.rf rpmforge

Matched from:

memcached

memcached is a high-performance, distributed memory object caching system,

generic in nature, but intended for use in speeding up dynamic web

applications by alleviating database load.

http://www.danga.com/memcached/

python-openid.noarch 1.2.0-1.el5.rf rpmforge

Matched from:

The OpenID library with batteries included.
The library features:
refined and easy-to-use API,

extensive documentation,

many storage implemetations including file-based, SQL, and memcached,

simple examples to help you get started and

licensed under the LGPL.


3、安裝並驗證 
[root@localhost src]# yum install –enablerepo=rpmforge memcached php-pecl-memcache

[root@localhost src]# memcached -h

memcached 1.2.2

[root@localhost src]# php -m|grep memcache

memcache

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.