Memcache是一個高性能的分布式的記憶體對象緩存系統,通過在記憶體裡維護一個統一的巨大的hash表,它能夠用來存儲各種格式的資料.簡單的說就是将資料調用到記憶體中,然後從記憶體中讀取,進而大大提高讀取速度。
安裝平台:centos4.7虛拟機
環境:mysql+apache+PHP5
所用到的安裝包:
Libevent(memcached用到了libevent這個庫,在編譯時用到)下載下傳:https://github.com/downloads/libevent/libevent/libevent-2.0.19-stable.tar.gz
memcache下載下傳:http://www.danga.com/memcached/dist/
Libevent安裝:
[[email protected] soft]# tar -zxf libevent-2.0.19-stable.tar.gz
[[email protected] soft]]# cd libevent-2.0.19-stable
[[email protected] libevent-2.0.19-stable]# ./configure --prefix=/usr
[[email protected] libevent-2.0.19-stable]# make
[[email protected] libevent-2.0.19-stable]# make install
安裝後使用ls -al /usr/lib |grep libevent檢視一下是否存在libevent。
memcache安裝:
[[email protected] soft]# tar -zxf memcached-1.4.15.tar.gz
[[email protected] soft]]# cd memcached-1.4.15
[[email protected] memcached-1.4.15]# ./configure --with-libevent=/usr/
[[email protected] memcached-1.4.15]# make && make install
驗證memcached是否安裝成功:
[[email protected] memcached-1.4.15]# ls -al /usr/local/bin/mem*
-rwxr-xr-x 1 root root 244827 11-05 21:45 /usr/local/bin/memcached
[[email protected] memcached-1.4.15]# which memcached
/usr/local/bin/memcached
[[email protected] memcached-1.4.15]#
啟動memcache:
[[email protected] bin]# memcached -d -u root //開啟memcache指令
[[email protected] bin]# netstat -anp //檢視memcache的預設端口11211是否啟動
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 8031/mysqld
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 20849/memcached
通過telnet連接配接memcache:
[[email protected] bin]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to localhost (127.0.0.1).
Escape character is '^]'.
stats
STAT pid 20849
STAT uptime 182
STAT time 1352123775
STAT version 1.4.15
STAT libevent 2.0.19-stable
STAT pointer_size 32
STAT rusage_user 0.000000
STAT rusage_system 0.005999
STAT curr_connections 10
STAT total_connections 11
STAT connection_structures 11
STAT reserved_fds 20
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 7
STAT bytes_written 0
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 262144
STAT hash_is_expanding 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT evictions 0
STAT reclaimed 0
END