1.安裝之前,需要先確認系統中是否有libevent,因爲memcached依賴這個包。
查看:
命令: rpm -qa|grep libevent
顯示的包:libevent-1.4.13-4.el6.x86_64
此時,系統已經安裝過了,需要卸載重新下載安裝。
卸載:rpm -e libevent-1.4.13-4.el6.x86_64
2.下載libevent,並安裝
下載地址:https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
解壓:
tar -zxvf libevent-2.0.21-stable.tar.gz
安裝:
./configure --prefix=/usr/local/libevent (指定安裝到/usr/local/libevent目錄下)
編譯:make
make install
安裝完成!
3.下載memcached,並解壓
命令: tar -zxvf memcached-1.4.17.tar.gz
安裝:
./configure --prefix=/usr/local/memcached-1.4.17
若安裝過程中提示找不到libevent路徑時,使用--with-libevent=libevent安裝的目錄
./configure --prefix=/usr/local/memcached-1.4.17 --with-libevent=/usr/local/libevent/
編譯:make
make install
安裝完成!
4.啓動
/usr/local/memcached-1.4.17/bin/memcached -d -m 128 -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文件。
5.停止
先查看進程的id
ps -ef|grep memcached
root 15144 1 0 08:43 ? 00:00:00 /usr/local/memcached-1.4.17/bin/memcached -d -m 128 -u root -p 11211 -c 1024 -P /tmp/memcached.pid
15144爲pid
停止命令爲:kill -9 15144