Memcache是danga.com的一个开源项目,它是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的 Hash 表,能够用来存储各种格式的数据。可以类比于MySQL 这样的服务,而PHP扩展的Memcache实际上是连接 Memcache的方式。
memcached的安装与配置:
[
root@vm4 lnmp]# tar zxf libevent-2.0.22-stable.tar.gz
[
root@vm4 lnmp]# cd libevent-2.0.22-stable
[
root@vm4 libevent-2.0.22-stable]# ./configure --prefix=/usr/local/lnmp/phpmodule/libevent
[
root@vm4 libevent-2.0.22-stable]# make && make install
[
root@vm4 lnmp]# tar zxf memcached-1.4.15.tar.gz
[
root@vm4 memcached-1.4.15]# ./configure --with-libevent=/usr/local/lnmp/phpmodule/libevent/
[
root@vm4 memcached-1.4.15]# make && make install
关于memcache启动的一些参数说明:
memcached命令参数解释:
-p 监听的端口
-l 连接的IP地址, 默认是本机
-d start 启动memcached 服务
-d restart 重起memcached 服务
-d stop|shutdown 关闭正在运行的memcached 服务
-d install 安装memcached 服务
-d uninstall 卸载memcached 服务
-u 以的身份运行 (仅在以root运行的时候有效)
-m 最大内存使用,单位MB。默认64MB
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时连接数,默认是1024
-f 块大小增长因子,默认是1.25
-n 最小分配空间,key+value+flags默认是48
-h 显示帮助
然后执行命令启动memcached
#/usr/local/bin/memcached -d -m 1024 -u root -p 11211 -P /tmp/memcached.pid
然后就可以使用telnet,来测试memcache的连接状态,
如果没有安装telnet服务,可以执行
yum install telnet-server telnet -y
vim /etc/xinetd.d/telnet
/etc/init.d/xinetd restart
[
root@vm4 ~]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stats 进入查看信息
STAT pid 1528 memcached进程ID
STAT uptime 32
STAT time 1434922425
STAT version 1.4.15
STAT libevent 2.0.22-stable
STAT pointer_size 64
STAT rusage_user 0.001999
STAT rusage_system 0.002999
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 1073741824
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
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
退出telnet,执行quit命令即可
安装memcache:
yum install autoconf -y
tar zxf memcache-2.2.5.tgz
cd memcache-2.2.5
phpize
./configure --prefix=/usr/local/lnmp/phpmodule/memcache --with-php-config=/usr/local/lnmp/php/bin/php-config
make && make install
Installing shared extensions: /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20100525/
[
root@vm4 memcache-2.2.5]# ll /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20100525/
total 1764
-rwxr-xr-x 1 root root 259088 Jun 22 06:44 memcache.so 我们可以看到这个文件存在的路径
vim /usr/local/lnmp/php/etc/php.ini 将它加入到php的扩张中
extension=/usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20100525/memcache.so
/etc/init.d/php-fpm reload
cp memcache.php /usr/local/lnmp/nginx/html/
vim /usr/local/lnmp/nginx/html/memcache.php
define('ADMIN_USERNAME','admin'); // Admin Username
define('ADMIN_PASSWORD','westos'); // Admin Password
$MEMCACHE_SERVERS[] = '192.168.1.126:11211'; // add more as an array
在浏览器输入: 然后输入用户名密码登陆
阅读(991) | 评论(0) | 转发(0) |