memcached 以及 php用戶端 安裝

來源:互聯網
上載者:User
web2.0和web1.0不一樣,web1.0以內容為中心,所以web1.0做負載只需緩衝內容就可以了,使用反向 Proxy快取頁面面就可以解決大部分問題了。而web2.0鼓勵使用者互動,內容都是動態,只做反向 Proxy命的話中率低,而且對資料庫進行頻繁的寫,對資料庫壓力大。所以,web2.0對web1.0更需要使用記憶體緩衝。

memcached高效能的,分布式的記憶體對象緩衝系統,在Live App中減少資料庫負載,提升訪問速度。memcached已經被廣泛應用在各種軟體中,例如,nginx、mysql

一、服務端安裝
使用weget下載libevent和memcached
libevent: http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz
memcached: http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz

1.先安裝libevent Java代碼

  1. tar zxvf libevent-1.4.9-stable.tar.gz    
  2. cd libevent-1.4.9-stable   
  3. ./configure   
  4. make   
  5. make install  
tar zxvf libevent-1.4.9-stable.tar.gz cd libevent-1.4.9-stable./configuremakemake install

2.安裝memcached Java代碼

  1. tar zxvf memcached-1.2.6.tar.gz   
  2. cd memcached-1.2.6  
  3. ./configure --enable-threads   
  4. make   
  5. make install  
tar zxvf memcached-1.2.6.tar.gzcd memcached-1.2.6./configure --enable-threadsmakemake install

註:如果啟動時出現“memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open
shared object file: No such file or directory”之類的資訊,表示memcached找不到libevent的位置
所以,請先使用whereis libevent得到位置,然後串連到memcached所尋找的路徑 Java代碼

  1. [root@localhost tools]# whereis libevent   
  2. libevent: /usr/local/lib/libevent.la /usr/local/lib/libevent.so /usr/local/lib/libevent.a   
  3. [root@localhost tools]# LD_DEBUG=libs memcached -v 2>&1 > /dev/null | less   
  4.       3848:     find library=libevent-1.4.so.2 [0]; searching   
  5.       3848:      search cache=/etc/ld.so.cache   
  6.       3848:      search path=/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/   
  7. usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64                   
  8. (system search path)   
  9.       3848:       trying file=/lib64/tls/x86_64/libevent-1.4.so.2  
  10.       3848:       trying file=/lib64/tls/libevent-1.4.so.2  
  11.       3848:       trying file=/lib64/x86_64/libevent-1.4.so.2  
  12.       3848:       trying file=/lib64/libevent-1.4.so.2  
  13.       3848:        
  14.       3848:     find library=libc.so.6 [0]; searching   
  15.       3848:      search cache=/etc/ld.so.cache   
  16.       3848:       trying file=/lib64/libc.so.6  
  17.       3848:        
  18.       3848:     find library=libnsl.so.1 [0]; searching   
  19.       3848:      search cache=/etc/ld.so.cache   
  20.       3848:       trying file=/lib64/libnsl.so.1  
  21.       3848:        
  22.       3848:     find library=librt.so.1 [0]; searching   
  23.       3848:      search cache=/etc/ld.so.cache   
  24.       3848:       trying file=/lib64/librt.so.1  
  25.       3848:        
  26.       3848:     find library=libresolv.so.2 [0]; searching   
  27.       3848:      search cache=/etc/ld.so.cache   
  28. [root@localhost tools]# ln -s /usr/local/lib/libevent-1.4.so.2 /lib64/  
[root@localhost tools]# whereis libeventlibevent: /usr/local/lib/libevent.la /usr/local/lib/libevent.so /usr/local/lib/libevent.a[root@localhost tools]# LD_DEBUG=libs memcached -v 2>&1 > /dev/null | less      3848:     find library=libevent-1.4.so.2 [0]; searching      3848:      search cache=/etc/ld.so.cache      3848:      search path=/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64                (system search path)      3848:       trying file=/lib64/tls/x86_64/libevent-1.4.so.2      3848:       trying file=/lib64/tls/libevent-1.4.so.2      3848:       trying file=/lib64/x86_64/libevent-1.4.so.2      3848:       trying file=/lib64/libevent-1.4.so.2      3848:           3848:     find library=libc.so.6 [0]; searching      3848:      search cache=/etc/ld.so.cache      3848:       trying file=/lib64/libc.so.6      3848:           3848:     find library=libnsl.so.1 [0]; searching      3848:      search cache=/etc/ld.so.cache      3848:       trying file=/lib64/libnsl.so.1      3848:           3848:     find library=librt.so.1 [0]; searching      3848:      search cache=/etc/ld.so.cache      3848:       trying file=/lib64/librt.so.1      3848:           3848:     find library=libresolv.so.2 [0]; searching      3848:      search cache=/etc/ld.so.cache[root@localhost tools]# ln -s /usr/local/lib/libevent-1.4.so.2 /lib64/

二、php安裝對memcached的支援
php有兩個版本的memcached用戶端

1.memcached
這個是新版的用戶端基於libmemcached,所以必須要安裝libmemcached

先安裝libmemcached
:http://download.tangent.org/libmemcached-0.26.tar.gz

Java代碼
  1. [root@localhost tools]# tar zxvf libmemcached-0.26.tar.gz   
  2. [root@localhost tools]# cd libmemcached-0.26  
  3. [root@localhost libmemcached-0.26]# ./configure --prefix=/usr/local/libmemcached/ --with-libmemcached-dir=/usr/local/libmemcached/   
  4. [root@localhost libmemcached-0.26]# make   
  5. [root@localhost libmemcached-0.26]# make install  
[root@localhost tools]# tar zxvf libmemcached-0.26.tar.gz[root@localhost tools]# cd libmemcached-0.26[root@localhost libmemcached-0.26]# ./configure --prefix=/usr/local/libmemcached/ --with-libmemcached-dir=/usr/local/libmemcached/[root@localhost libmemcached-0.26]# make[root@localhost libmemcached-0.26]# make install

安裝php memcached用戶端
:http://pecl.php.net/get/memcached

Java代碼
  1. [root@localhost tools]# tar zxvf memcached-0.1.4.tgz   
  2. [root@localhost tools]# cd memcached-0.1.4  
  3. [root@localhost memcached-0.1.4]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/   
  4. [root@localhost memcached-0.1.4]# make   
  5. [root@localhost memcached-0.1.4]# make install  
[root@localhost tools]# tar zxvf memcached-0.1.4.tgz[root@localhost tools]# cd memcached-0.1.4[root@localhost memcached-0.1.4]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/[root@localhost memcached-0.1.4]# make[root@localhost memcached-0.1.4]# make install

修改php.ini添加extension = "memcached.so"就可以了。

如果出現錯誤

Java代碼
  1. checking for libmemcached location... configure: error: memcached support requires libmemcached. Use --with-libmemcached-dir=<DIR> to specify the prefix where libmemcached headers and library are located  
checking for libmemcached location... configure: error: memcached support requires libmemcached. Use --with-libmemcached-dir=<DIR> to specify the prefix where libmemcached headers and library are located

請先用whereis libmemcached找到路徑,然後添加選項--with-libmemcached-dir=libmemcached路徑

2.memcache
:http://pecl.php.net/get/memcache Java代碼

  1. [root@localhost tools]# tar zxvf memcache-3.0.3.tgz    
  2. [root@localhost tools]# cd memcache-3.0.3  
  3. [root@localhost tools]# /usr/local/php/bin/phpize   
  4. [root@localhost tools]# ./configure --with-php-config=/usr/local/php/bin/php-config   
  5. [root@localhost tools]# make   
  6. [root@localhost tools]# make install  
[root@localhost tools]# tar zxvf memcache-3.0.3.tgz [root@localhost tools]# cd memcache-3.0.3[root@localhost tools]# /usr/local/php/bin/phpize[root@localhost tools]# ./configure --with-php-config=/usr/local/php/bin/php-config[root@localhost tools]# make[root@localhost tools]# make install

修改php.ini添加extension = "memcache.so"就可以了。

提示:如果php找不到so檔案,請設定extension_dir。

ps:這篇東西在草稿箱裡呆很久了,最後還是決定把一篇分多篇發吧,這樣感覺快多了。

參考資料:
http://www.danga.com/memcached/ http://willko.javaeye.com/blog/332993

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.