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安裝:
[root@localhost soft]# tar -zxf libevent-2.0.19-stable.tar.gz[root@localhost soft]]# cd libevent-2.0.19-stable[root@localhost libevent-2.0.19-stable]# ./configure --prefix=/usr[root@localhost libevent-2.0.19-stable]# make[root@localhost libevent-2.0.19-stable]# make install
安裝後使用ls -al /usr/lib |grep libevent查看一下是否存在libevent。
memcache安裝:
[root@localhost soft]# tar -zxf memcached-1.4.15.tar.gz[root@localhost soft]]# cd memcached-1.4.15[root@localhost memcached-1.4.15]# ./configure --with-libevent=/usr/[root@localhost memcached-1.4.15]# make && make install
驗證memcached是否安裝成功:
[root@localhost 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[root@localhost memcached-1.4.15]# which memcached/usr/local/bin/memcached[root@localhost memcached-1.4.15]#
啟動memcache:
[root@localhost bin]# memcached -d -u root //開啟memcache命令[root@localhost 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:
[root@localhost bin]# telnet 127.0.0.1 11211Trying 127.0.0.1...Connected to localhost (127.0.0.1).Escape character is '^]'.statsSTAT pid 20849STAT uptime 182STAT time 1352123775STAT version 1.4.15STAT libevent 2.0.19-stableSTAT pointer_size 32STAT rusage_user 0.000000STAT rusage_system 0.005999STAT curr_connections 10STAT total_connections 11STAT connection_structures 11STAT reserved_fds 20STAT cmd_get 0STAT cmd_set 0STAT cmd_flush 0STAT cmd_touch 0STAT get_hits 0STAT get_misses 0STAT delete_misses 0STAT delete_hits 0STAT incr_misses 0STAT incr_hits 0STAT decr_misses 0STAT decr_hits 0STAT cas_misses 0STAT cas_hits 0STAT cas_badval 0STAT touch_hits 0STAT touch_misses 0STAT auth_cmds 0STAT auth_errors 0STAT bytes_read 7STAT bytes_written 0STAT limit_maxbytes 67108864STAT accepting_conns 1STAT listen_disabled_num 0STAT threads 4STAT conn_yields 0STAT hash_power_level 16STAT hash_bytes 262144STAT hash_is_expanding 0STAT bytes 0STAT curr_items 0STAT total_items 0STAT expired_unfetched 0STAT evicted_unfetched 0STAT evictions 0STAT reclaimed 0END