#首先安裝 libevent
wget http://www.monkey.org/~provos/libevent-1.4.2-rc.tar.gz
tar zxvf libevent-1.4.2-rc.tar.gz
cd libevent-1.4.2-rc
./configure --prefix=/usr/local/
make
make install
### [*1] ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib64/libevent-1.4.so.2 原因見後面
wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
tar zxf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure --prefix=/usr/local/memcached --enable-64bit --with-libevent=/usr/lib64/
### 如果此時沒有進行 *1 操作,make test會報錯,但不影響安裝
make
make install
cp memcached /usr/local/bin/
cp memcached-debug /usr/local/bin/
#啓動
memcached -d -m 1024 -u root -t 64 -r -c 16382 -p 11211
### *1裏所說的情況:會遇到問題 error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
#使用LD_DEBUG=libs /usr/local/memcached/bin/memcached -v 進行檢查
# 3566: find library=libevent-1.4.so.2 [0]; searching
# 3566: search cache=/etc/ld.so.cache
# 3566: 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)
# 3566: trying file=/lib64/tls/x86_64/libevent-1.4.so.2
# 3566: trying file=/lib64/tls/libevent-1.4.so.2
# 3566: trying file=/lib64/x86_64/libevent-1.4.so.2
# 3566: trying file=/lib64/libevent-1.4.so.2
# 3566: trying file=/usr/lib64/tls/x86_64/libevent-1.4.so.2
# 3566: trying file=/usr/lib64/tls/libevent-1.4.so.2
# 3566: trying file=/usr/lib64/x86_64/libevent-1.4.so.2
# 3566: trying file=/usr/lib64/libevent-1.4.so.2
# 3566:
#/usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
#我裝的是最新版(貌似只去找lib64)
#解決辦法:
ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib64/libevent-1.4.so.2
memcached -d -m 1024 -u root -t 64 -r -c 16382 -p 11211
#啓動成功
#--------------------------------------------------
#安裝memcache module for php
#我下載的是穩定版本
wget http://pecl.php.net/get/memcache-2.2.5.tgz
tar zxf memcache-2.2.5.tgz
cd memcached-2.2.5
#這命令沒有加在bin裏邊-。-,直接用運行了
/usr/local/php5/bin/phpize
#這裏的--with-php-config需要指定一下,否則可能會提示找不到路徑
./configure --enable-memcache --with-php-config=/usr/local/php5/bin/php-config --with-zlib-dir
make
make install
#提示/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/
#之前安裝eaccelerator.so的時候遇到過,而且在php.ini裏邊也修改過模塊的路徑
vi /usr/local/Zend/etc/php.ini
#在最後添加
[memcache]
extension=memcache.so
#重啓apache
#加大同時打開文件數
ulimit -n 10240
#memcached啓動參數
#開啓了64位參數,可以分配4G以上的內存,如:memcached -d -m 6144 -u root -t 64 -r -c 16382 -p 11211
memcached -d -m 1024 -u root -t 64 -r -c 16382 -p 11211
#memcached -d -m 1024 -u root -t 64 -r -c 16382 -p 11212
#memcached -d -m 1024 -u root -t 64 -r -c 16382 -p 11213
# -d 啓動deamon模式
# -m 最大佔用內存,單位爲M
# -u 運行賬戶
# -t 併發線程數,最好不超過cpu數
# -r maximize core file limit
# -c 最大可接受併發連接數
# -p 監聽端口
# -l 監聽ip
#memcached進程管理
# -d start 啓動memcached服務
# -d restart 重起memcached服務
# -d stop|shutdown 關閉正在運行的memcached服務
# -d install 安裝memcached服務
# -d uninstall 卸載memcached服務