Linux下的Memcache安裝

Linux下的Memcache安裝
記錄下Memcache安裝的過程。

 

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/bin/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

 

安裝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

發佈了20 篇原創文章 · 獲贊 10 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章