memcached 以及 php新用戶端memcached 裝配(參考)

來源:互聯網
上載者:User
memcached 以及 php新用戶端memcached 安裝(參考)
2010-02-23 11:05web2.0和web1.0不一樣,web1.0以內容為中心,所以web1.0做負載只需緩衝內容就可以了,使用反向 Proxy快取頁面面就可以解決大部分問題了。而web2.0鼓勵使用者互動,內容都是動態,只做反向 Proxy命的話中率低,而且對資料庫進行頻繁的寫,對資料庫壓力大。所以,web2.0對 web1.0更需要使用記憶體緩衝。memcached高效能的,分布式的記憶體對象緩衝系統,在Live App中減少資料庫負載,提升訪問速度。memcached已經被廣泛應用在各種軟體中,例如,nginx、mysql一、服務端安裝使用weget下載libevent和memcachedlibevent: http://monkey.org/~provos/libevent-1.4.9-stable.tar.gzmemcached: http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz1.先安裝libeventtar zxvf libevent-1.4.9-stable.tar.gz cd libevent-1.4.9-stable  ./configure  make  make install  tar zxvf libevent-1.4.9-stable.tar.gz cd libevent-1.4.9-stable./configuremakemake install2.安裝memcachedtar zxvf memcached-1.2.6.tar.gz  cd memcached-1.2.6  ./configure --enable-threads  make  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 openshared object file: No such file or directory”之類的資訊,表示memcached找不到libevent的位置所以,請先使用whereis libevent得到位置,然後串連到memcached所尋找的路徑[[email protected] tools]# whereis libevent  libevent: /usr/local/lib/libevent.la /usr/local/lib/libevent.so /usr/local/lib/libevent.a  [[email protected] tools]# LD_DEBUG=libs memcached -v 2>&1 > /dev/null | less  [[email protected] 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[[email protected] tools]# tar zxvf libmemcached-0.26.tar.gz  [[email protected] tools]# cd libmemcached-0.26  [[email protected] libmemcached-0.26]# ./configure --prefix=/usr/local/libmemcached/ --with-libmemcached-dir=/usr/local/libmemcached/  [[email protected] libmemcached-0.26]# make  [[email protected] libmemcached-0.26]# make install  [[email protected] tools]# tar zxvf libmemcached-0.26.tar.gz[[email protected] tools]# cd libmemcached-0.26[[email protected] libmemcached-0.26]# ./configure --prefix=/usr/local/libmemcached/ --with-libmemcached-dir=/usr/local/libmemcached/[[email protected] libmemcached-0.26]# make[[email protected] libmemcached-0.26]# make install安裝php memcached及最新用戶端下載地址:http://pecl.php.net/get/memcached[[email protected] tools]# tar zxvf memcached-0.1.4.tgz  [[email protected] tools]# cd memcached-0.1.4  [[email protected] memcached-0.1.4]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/  [[email protected] memcached-0.1.4]# make  [[email protected] memcached-0.1.4]# make install  [[email protected] tools]# tar zxvf memcached-0.1.4.tgz[[email protected] tools]# cd memcached-0.1.4[[email protected] memcached-0.1.4]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/[[email protected] memcached-0.1.4]# make[[email protected] memcached-0.1.4]# make install修改php.ini添加extension = "memcached.so"就可以了。1. checking for libmemcached location... configure: error: memcached support requires libmemcached. Use --with-libmemcached-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= 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[[email protected] tools]# tar zxvf memcache-3.0.3.tgz [[email protected] tools]# cd memcache-3.0.3  [[email protected] tools]# /usr/local/php/bin/phpize  [[email protected] tools]# ./configure --with-php-config=/usr/local/php/bin/php-config  [[email protected] tools]# make  [[email protected] tools]# make install  [[email protected] tools]# tar zxvf memcache-3.0.3.tgz [[email protected] tools]# cd memcache-3.0.3[[email protected] tools]# /usr/local/php/bin/phpize[[email protected] tools]# ./configure --with-php-config=/usr/local/php/bin/php-config[[email protected] tools]# make[[email protected] tools]# make install修改php.ini添加extension = "memcache.so"就可以了。提示:如果php找不到so檔案,請設定extension_dir。ps:這篇東西在草稿箱裡呆很久了,最後還是決定把一篇分多篇發吧,這樣感覺快多了。來源:http://willko.iteye.com/blog/332993NetSeek (2009-9-10 11:16:40)memcached 的用戶端 libmemcached, 在處理value超過8k的資料時, 速度會直線下降, 在http://lists.tangent.org/piperma ... ovember/000484.html, 可以找到答案, 原因是libmemcached的buf太小了, 找到源檔案memcached_constants.h, 修改#define MEMCACHED_MAX_BUFFER 8196, 改成合適的大小, 重新編譯, 安裝, 就可以了.libmemcached是C用戶端庫的介面到memcached伺服器。它被設計為輕的記憶體使用量情況,安全執行緒,並提供充分獲得伺服器端的方法。它還採用多種命令列工具: memcat , memflush , memrm , memstat ,並memslap (負載代)。圖書館一直在設計,讓不同的散列方法對密鑰,分割的鑰匙,並使用統一的散列分配。 許可: BSD許可證(修訂) 變化:修正遞減的散列關鍵。修正的斷言,是抓不好memset ( )調用的host_reset ( ) 。修正的一個問題,清除阻塞的I / O已經堆疊。增補memstat 。一種新的API沖水。 memcached簡單的使用教程這是工程應用性質的文章:memcached是資料快速存取的工具,wikipedia和facebook就用了它提高速度。具體情況可以wiki.c/c++裡面使用memcached本來是很簡單的事情,但就是沒有人說,非要我去讀libmemcache的執行個體代碼才行,manpage也沒有說清楚(但還不得不看)。如果要使用memcached,步驟如下:1 安裝memcached  你可以去官網上下載,也可以sudo apt-get install memcached2 測試你剛才的安裝,  比如運行 memcached -d -m 64 -l 127.0.0.1 -p 12300  -d表示後台, -m 64表示使用64MB記憶體,-l 127.0.0.1 -p 12300 表示監聽127.0.0.1:12300連接埠  沒有任何訊息就是運行成功3 安裝libmemcached  這個就不要apt了,因為沒有精確的libmemcached包,乖乖去官網下載吧。這個東西還需要libevent,這個沒法apt,libevent安裝的時候最好裝到/usr/lib裡面,不然libmemcached還不能運行。4 測試libmemcached  找一個檔案比如test,然後運行memcp test --servers=127.0.0.1:12300  這樣就把test拷貝到memcached管理的記憶體裡面了。  memcat test --servers=127.0.0.1:12300  看看是不是剛才的那個檔案。 
  • 聯繫我們

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