今天之前同事問我如何在Linux下安裝Memcache,並告訴我從昨天折騰到如今一直沒有安裝成功。之前記得安裝Memcache時好像沒有那麼複雜,今天遠程鏈接了他的機器看了下,開始先安裝libevent,我怕他的版本太舊就給上傳了個最新版本2.0,不過竟然編譯不經過,可是編譯以前的1.4版本能經過。好了,先不糾結在這裏,安裝完libevent後,再次安裝Memcach,執行:
./configure –prefix=/usr/local/memcached –with-event=/usr ---成功
make ---報出以下錯誤:
.deps/testapp.Tpo -c -o testapp.o testapp.c cc1: warnings being treated as errors testapp.c: In function `test_safe_strtoul': testapp.c:166: warning: decimal constant is so large that it is unsigned make[2]: *** [testapp.o] Error 1 make[2]: Leaving directory `/data/memcached-1.4.5' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/data/memcached-1.4.5' make: *** [all] Error 2php
上網查找緣由,最後找到以下解釋:
(http://code.google.com/p/memcached/issues/detail?id=133)
Comment 2 by project member dorma...@rydia.net, Apr 22, 2010
That looks like redhat enterprise linux version 3 (RHEL3)?html
If so, we're sorry but the toolchains on there are simply too old to run a modern
version of memcached. You may try running a very old version of the 1.2 or 1.1
series, but we rely on C99 support now.node
I'm assuming this from your kernel version, if this is wrong let us know.
Status: WontFix
Comment 3 by hzi...@gmail.com, Apr 26, 2010
Think you for your commentslinux
Yes you 're right i succes to install memcached 1.4.5 when i changed my OS to Linux
2.6.18-8.el5PAE i686 athlon i3 86 GNU/Linux. The problem is that i get this error
when i try to get a value from my memcached <<Exception in thread "main"
net.spy.memcached.internal.CheckedOperationTimeoutException: Timed out waiting for
operation - failing node: /xx.xxx.x.xx:11211 >>數據庫
指出致使這種錯誤的緣由是Linux的內核版本太低,查了下朋友的linux內核版本,果然如此,是2.4,換成2.6就ok了。api
附Memcache的安裝步驟:
去官網下載libevent和Memcache
1.安裝libevent:
# tar zxvf ibevent-2.0.10-stable.tar.gz
# cd ibevent-2.0.10-stable
# ./configure –prefix=/usr
# make
# make install
測試libevent是否安裝成功:
# ls -al /usr/lib | grep libevent
lrwxrwxrwx 1 root root 21 Mar 24 20:09 libevent-2.0.so.5 -> libevent-2.0.so.5.0.1
-rwxr-xr-x 1 root root 943520 Mar 24 20:09 libevent-2.0.so.5.0.1
-rw-r--r-- 1 root root 1532186 Mar 24 20:09 libevent.a
lrwxrwxrwx 1 root root 26 Mar 24 20:09 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.0.1
-rwxr-xr-x 1 root root 554374 Mar 24 20:09 libevent_core-2.0.so.5.0.1
-rw-r--r-- 1 root root 927994 Mar 24 20:09 libevent_core.a
-rwxr-xr-x 1 root root 971 Mar 24 20:09 libevent_core.la
。。。緩存
2.安裝memcached,注意要指明libevent的位置
# tar zxvf memcached-1.4.5.tar.gz
# cd memcached-1.4.5
# ./configure—prefix=/usr/local/memcached –with-libevent=/usr
# make
# make install服務器
測試是否成功安裝memcached:
# ls -al /usr/local/memcached/
total 24
drwxr-xr-x 5 root root 4096 Mar 24 20:58 .
drwxr-xr-x 27 root root 4096 Mar 24 20:11 ..
drwxr-xr-x 2 root root 4096 Mar 24 20:11 bin
drwxr-xr-x 3 root root 4096 Mar 24 20:11 include
-rw-r--r-- 1 root root 0 Mar 24 20:58 libevent-2.0.so.5.0.1
-rw-r--r-- 1 root root 0 Mar 24 20:58 libevent_core-2.0.so.5.0.1
-rw-r--r-- 1 root root 0 Mar 24 20:58 libevent_extra-2.0.so.5.0.1
-rw-r--r-- 1 root root 0 Mar 24 20:58 libevent_openssl-2.0.so.5.0.1
-rw-r--r-- 1 root root 0 Mar 24 20:58 libevent_pthreads-2.0.so.5.0.1
drwxr-xr-x 3 root root 4096 Mar 24 20:11 share網絡
memcached的基本使用:
1.啓動Memcache的服務器端:
# /usr/local/memcached/bin/memcached -d -m 100 -u root -l 192.168.1.131 -p 6717 -c 500 -P /tmp/memcached.pid
參數說明:
-d選項是啓動一個守護進程,
-m是分配給Memcache使用的內存數量,單位是MB,這裏是100MB
-u是運行Memcache的用戶,這裏是root
-l是監聽的服務器IP地址,這裏指定服務器的IP地址192.168.1.131
-p是設置Memcache監聽的端口,這裏設置爲6717,最好設置1024以上的端口
-c選項是最大運行的併發鏈接數,默認是1024,這裏設置爲500,要根據服務器的負載量來設定
-P是保存Memcache的pid文件,這裏保存在 /tmp/memcached.pid併發
2.如何結束Memcache進程:
# kill `cat /tmp/memcached.pid`
關於Memcache的基本說明:
(轉自:http://www.ccvita.com/259.html)
Memcache是什麼
Memcache是danga.com的一個項目,最先是爲 LiveJournal 服務的,目前全世界很多人使用這個緩存項目來構建本身大負載的網站,來分擔數據庫的壓力。
它能夠應對任意多個鏈接,使用非阻塞的網絡IO。因爲它的工做機制是在內存中開闢一塊空間,而後創建一個HashTable,Memcached自管理這些HashTable。
Memcache官方網站:http://www.danga.com/memcached,更多詳細的信息能夠來這裏瞭解
爲何會有Memcache和memcached兩種名稱?
其實Memcache是這個項目的名稱,而memcached是它服務器端的主程序文件名,知道個人意思了把~~~~。一個是項目名稱,一個是主程序文件名,在網上看到了不少人不明白,因而混用了。
Memcache的安裝 分爲兩個過程:memcache服務器端的安裝和memcached客戶端的安裝。 所謂服務器端的安裝就是在服務器(通常都是linux系統)上安裝Memcache實現數據的存儲 所謂客戶端的安裝就是指php(或者其餘程序,Memcache還有其餘不錯的api接口提供)去使用服務器端的Memcache提供的函數,須要php添加擴展。