标签存档: memcache

memcached配置

1.memcache-client //memcached客户端

$ cd /home/super
$ wget http://pecl.php.net/get/memcached-2.1.0.tgz
$ tar -zxvf memcached-2.1.0.tgz
$ cd memcached-2.1.0
$ /usr/local/bin/phpize #使用phpize建立php扩展
$ ./configure --prefix=/usr/local/memcached --with-php-config=/usr/local/bin/php-config
$ make && make install
#记录下一个很长的路径:/usr/local/lib/php/extensions/no-debug-zts-20090626/

$ vim /usr/local/php/lib/php.ini #配置php.ini
>extension_dir = "/usr/local/lib/php/extensions/no-debug-zts-20090626/"
>extension=memcached.so
$ /usr/local/apache2/bin/apachectl restart

2.memcached //memcache服务端

#安装 libevent
$ cd /home/super
$ wget http://monkey.org/~provos/libevent-1.3b.tar.gz
$ tart -zxvf libevent-1.3b.tar.gz
$ cd libevent-1.3b
$ ./configure
$ make && make install
#安装 memcached
$ cd /home/super
$ wget http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz
$ tar -zxvf memcached-1.2.1.tar.gz
$ cd memcached-1.2.1
$ ./configure
$ make && make install
#测试libevent是否安装成功:
$ ls -al /usr/lib | grep libevent
#启动(安装后位置:/usr/local/bin/memcached)
#$ memcached -d -m 128 -l 0.0.0.0 -p 11211 -u root //0.0.0.0对任何客户端都开放memcache
#memcached的基本设置
#启动Memcache的服务器端:
$ /usr/local/bin/memcached -d -m 10 -u root -l 0.0.0.0 -p 12000 -c 256 -P /tmp/memcached.pid
#-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,
#如果要结束Memcache进程,执行:
#kill cat /tmp/memcached.pid
#也可以启动多个守护进程,不过端口不能重复。

成功截图:
写一个phpinfo();的php文件,成功啦~

$ cd /var/www/html
$ vim memcache.php
>$memcache = new Memcache();
>$memcache->connect('127.0.0.1', 12000);
>$memcache->set('key', 'This is a memcache key!', 0, 60);
>$res = $memcache->get('key');
>echo $res;

3.memcached统计监控

$ telnet 127.0.0.1 12000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stats
STAT pid 1467
STAT uptime 59525
STAT time 1368585692
STAT version 1.4.15
STAT libevent 2.0.21-stable
STAT pointer_size 64
STAT rusage_user 0.196012
STAT rusage_system 0.232014
STAT curr_connections 5
STAT total_connections 51
STAT connection_structures 6
STAT reserved_fds 20
STAT cmd_get 42
STAT cmd_set 20
STAT cmd_flush 6
STAT cmd_touch 0
STAT get_hits 29
STAT get_misses 13
STAT delete_misses 0
STAT delete_hits 5
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 3520
STAT bytes_written 3893
STAT limit_maxbytes 268435456
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 470
STAT curr_items 2
STAT total_items 20
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT evictions 0
STAT reclaimed 3
END

遇到问题:
如果遇到 memcached:error while loading shared libraries:libevent-1.3b.so.1:cannot open shared object file:No such file or directory.
使用 LD_DEBUG=libs /usr/local/bin/memcached -v 查看其启动的时候,加载lib情况;具体的不列出;
执行:ln -s /usr/local/lib/libevent-1.3b.so.1 /lib/libevent-1.3b.so.1问题可以解决;

第 1 页,共 1 页1