一、 安裝文件
Linux系統安裝memcached,首先要先安裝libevent庫。
下載memcached與libevent的安裝文件
http://memcached.org/files/memcached-1.5.12.tar.gz(memcached下載地址)
https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz(libevent下載地址)
二、具體安裝步驟
由於memcached依賴於libevent,因此需要安裝libevent。由於linux系統可能默認已經安裝libevent,執行命令:
rpm -qa|grep libevent
查看系統是否帶有該安裝軟件,如果有執行命令:
rpm -e libevent-1.4.13-4.el6.x86_64 --nodeps(由於系統自帶的版本舊,忽略依賴刪除)
安裝libevent命令
tar -zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix=/usr/local/libevent
make
make install
至此libevent安裝完畢;
ps:若安裝過程中出現configure: error : no acceptable C compiler found in $PATH錯誤時是沒有安裝gcc,運行如下命令:
yum install gcc* make*
安裝memcached命令:
tar -zxvf memcached-1.4.2.tar.gz
cd memcached-memcached-1.4.2
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
make
make install
至此memcached安裝完畢;
三、啟動memcached
/usr/local/memcached/bin/memcached -d -m 256 -u root -p 11211 -c 1024 –P /tmp/memcached.pid
啟動參數說明:
-d 選項是啟動一個守護進程。 -u root 表示啟動memcached的用戶為root。 -m 是分配給Memcache使用的內存數量,單位是MB,默認64MB。 -M return error on memory exhausted (rather than removing items)。 -u 是運行Memcache的用戶,如果當前為root 的話,需要使用此參數指定用戶。 -p 是設置Memcache的TCP監聽的端口,最好是1024以上的端口。 -c 選項是最大運行的並發連接數,默認是1024。 -P 是設置保存Memcache的pid文件。
也可以啟動多個守護進程,但是端口不能重復。
查看memcached啟動命令
ps aux|grep memcached
當啟動memcached時經常不能發現libevent.so;可以通過以下命令檢查:
進入/usr/local/memcached/bin目錄
LD_DEBUG=help./memcached -v
LD_DEBUG=libs ./ memcached-v
解決方法:
ln-s /usr/local/libevent/lib/libevent-2.0.so.5/lib64/libevent-2.0.so.5
四、停止Memcache進程
查找允許 memcached 的進程 id:
# ps -ef|grep memcached root 9662 1 0 10:13 ? 00:00:00 /usr/bin/memcached -d -m 1024 -u root -l 127.0.0.1 -p 11211 -c 1024 -P /tmp/memcached.pid root 10155 8703 0 10:14 pts/0 00:00:00 grep memcached
第一行的第二個就是進程 id,使用 kill 命令停止進程:
# kill -9 9662