libevent: http://libevent.org/
服務器端:https://code.google.com/archive/p/memcached/downloads
客戶端: http://pecl.php.net/package/memcache 和 http://pecl.php.net/package/memcached 二選一
https://blog.linuxeye.com/345.htmlphp
http://chenzhou123520.iteye.com/blog/1925209html
http://www.cnblogs.com/scotoma/archive/2011/02/15/1955573.htmllinux
最近在公司服務器上安裝memcached安了不少次,每次都得上網來查一下步驟,今天干脆寫個詳細點的步驟記錄一下,留做備忘。shell
1、檢查libevent服務器
首先檢查系統中是否安裝了libevent併發
若是安裝了則查看libevent的安裝路徑,後續安裝時須要用到memcached
若是沒有安裝,則先安裝libeventpost
安裝libevent:google
1.首先下載libevent安裝包url
- wget http://www.monkey.org/~provos/libevent-1.4.12-stable.tar.gz
2.解壓縮安裝包
- tar zxvf libevent-1.4.12-stable.tar.gz -C /usr/local/
3.進入解壓後的目錄
- cd libevent-1.4.12-stable/
4.配置編譯、安裝
- ./configure -prefix=/usr/libevent
- make
- make install
安裝完libevent以後爲了讓動態連接庫爲系統所共享,須要執行如下動態連接庫的管理命令ldconfig
不過在執行ldconfig命令以前須要注意如下libevent的安裝目錄。具體參見:http://chenzhou123520.iteye.com/blog/1925196
安裝完libevent後正式開始安裝memcached
1.首先是下載memcached的安裝包
- wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
2.修改安裝包的執行操做權限
- chmod 777 memcached-1.4.15.tar.gz
3.解壓安裝包到指定目錄
- tar zxvf memcached-1.4.15.tar.gz -C /usr/local
4.進入解壓後的目錄
- cd /usr/local/memcached-1.4.15/
5.配置、編譯、安裝
注:configure時須要指定libevent的安裝路徑
- ./configure -with-libevent=/usr/libevent/ -prefix=/usr/local/memcached
- make
- make install
6.安裝成功後啓動一下看安裝是否成功
- /usr/local/memcached/bin/memcached -d -m 10m -p 11211 -u root
啓動參數介紹以下:和上面的命令不對應
-d選項是啓動一個守護進程,
-m是分配給Memcache使用的內存數量,單位是MB,這裏是10MB,
-u是運行Memcache的用戶,這裏是root,
-l是監聽的服務器IP地址,若是有多個地址的話,這裏指定了服務器的IP地址192.168.0.200,
-p是設置Memcache監聽的端口,這裏設置了12000,最好是1024以上的端口,
-c選項是最大運行的併發鏈接數,默認是1024,這裏設置了256,按照服務器的負載量來設定,
-P是設置保存Memcache的pid文件,我這裏是保存在 /tmp/memcached.pid,也能夠啓動多個守護進程,不過端口不能重複。
若是要給memcached上配置日誌,參見:http://chenzhou123520.iteye.com/blog/1925209
PS:附上一個memcached啓動的shell腳本
- #!/bin/sh
- echo "Start to start memcached server $(date)..."
-
- MEMCACHED=/usr/local/memcached/bin/memcached
-
- usage()
- {
- echo "usage: `basename $0` port"
- }
-
- if [ -n "$1" ]
- then
- {
- pid=`ps aux|grep memcached|grep "$1" |grep -v grep|awk '{print $2}'`
- if [ -n "$pid" ]
- then
- {
- sleep 2
- echo "kill memcached which port is $1 begin"
- echo "pid:$pid"
- kill -9 $pid
- echo "kill memcached which port is $1 end"
- sleep 2
- }
- fi
- echo "begin to start memcached in port $1"
- LOG_FILE=/var/log/memcached/memcached_$1.log
- rm -f $LOG_FILE
- $MEMCACHED -d -m 2048 -p $1 -u root -vv >> $LOG_FILE 2>&1
- echo "start memcached end"
- tail -f $LOG_FILE
- }
- else
- {
- usage
- exit 1
- }
- fi
把該腳本命名爲startup.sh
執行:./startup.sh 11211
其中11211爲memcached的啓動端口,也能夠經過自定義的端口來啓動
查看是否啓動:ps aux|grep memcached
查看版本 :
cd /etc/init.d/
memcached -h
或者:
[nihaoya@SHANGH-39-DX-APP ~]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stats