一 、安装
[root@master opt]# tar -zxvf memcached-1.4.25.tar.gz
[root@master opt]# mv memcached-1.4.25 memcached
[root@master opt]# cd memcached
[root@master memcached]# ./configure
checking for library containing gethostbyname... none required
checking for libevent directory... configure: error: libevent is required.? You can get it from http://www.monkey.org/~provos/libevent/
If it‘s already installed, specify its path using --with-libevent=/dir/
解决方案:
[root@master opt]# wget http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz
[root@master opt]# tar -zxvf libevent-1.4.14b-stable.tar.gz
[root@master opt]# cd libevent-1.4.14b-stable
[root@master libevent-1.4.14b-stable]# #./configure --prefix=/usr?
[root@master libevent-1.4.14b-stable]# make?? && make install
重新编译配置memcached
[root@master memcached]#? ./configure --with-libevent=/usr
[root@master memcached]#? make?? && make install
?
二 、启动
1.启动Memcache的服务器端:
# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.0.200 -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,
2.如果要结束Memcache进程,执行:
# kill `cat /tmp/memcached.pid`
也可以启动多个守护进程,不过端口不能重复。
验证是否启动成功
[root@master memcached]# netstat -tnpl |grep 11211
tcp??????? 0????? 0 127.0.0.1:11211???????????? 0.0.0.0:*?????????????????? LISTEN????? 19061/memcached????
?
三?、测试
[root@master ~]#? telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is ‘^]‘.
stats
STAT pid 19061
STAT uptime 586
STAT time 1451687276
STAT version 1.4.25
STAT libevent 1.4.14b-stable
STAT pointer_size 64
STAT rusage_user 0.008998
STAT rusage_system 0.046992
STAT curr_connections 6
STAT total_connections 7
STAT connection_structures 7
STAT reserved_fds 20
STAT cmd_get 2
STAT cmd_set 0
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 0
STAT get_misses 2
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 193
STAT bytes_written 108
STAT limit_maxbytes 134217728
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT time_in_listen_disabled_us 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT malloc_fails 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
STAT crawler_reclaimed 0
STAT crawler_items_checked 0
STAT lrutail_reflocked 0
END
>>set key 33 0 4 \r\n
1234
STORED
>>get key 33
VALUE key 33 4
1234
END
quit
Connection closed by foreign host.
[root@master ~]#
原文:http://gaojingsong.iteye.com/blog/2268059