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 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