Linux下安装配置Memcached

Linux下安装配置Memcached

首页
http://www.danga.com/memcached

下载地址:
http://danga.com/memcached/download.bml

下载文件
memcached-1.2.6.tar.gz
tar zxvf memcached-1.2.6.tar.gz
./configure --prefix=/usr/local/memcached-1.2.6
make
make install

注意:

memcache需要这个包libevent,不然安装时要报错:

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/

下载得到文件libevent-1.4.9-stable.tar.gz

tar zxvf libevent-1.4.9-stable.tar.gz

./configure --prefix=/usr/local/libevent-1.4.9-stable.tar.gz
make
make install

由于我安装没有安装在usr下面,所以最后启动memcache报错:

[root@localhost bin]# ./memcached -d -m 10 -p 11211 -u root -l 0.0.0.0
./memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

检查libevent安装情况:

ls -al /usr/lib | grep libevent
把 libevent-1.4.so.2 拷贝/链接到 /usr/lib 中,否则 memcached 无法正常加载。

cp libevent-1.4.so.2 /usr/lib/

文章出处:http://www.diybl.com/course/6_system/linux/linuxjq/20071010/77432.html


安装完之后要启动服务
cd /usr/local/memcached-1.2.6/bin
./memcached -d -m 50 -p 11211 -u root -l 0.0.0.0
参数说明
-m 指定使用多少兆的缓存空间;
-p 指定要监听的端口;
-u 指定以哪个用户来运行



Ubuntu下安装配置memcached

安装
sudo apt-get install memcached

启动
memcached -d -m 50 -p 11211 -u root -l 0.0.0.0
参数说明
-m 指定使用多少兆的缓存空间;
-p 指定要监听的端口;
-u 指定以哪个用户来运行

发现在 ubuntu下机器会自启动,启动的配置位置在

/etc/memcached.conf

如果有需要可以自行更改

telnet localhost 11211
//保存
set good 32 0 10
helloworld
STORED

//取回
gets good
VALUE good 32 10 10
helloworld
END

//替换
replace good 32 0 10
worldhello
STORED
get good
VALUE good 32 10
worldhello
END

//尾部添加
append good 32 0 5
after
STORED
get good
VALUE good 32 15
worldhelloafter
END

//头部添加
prepend good 32 0 6
before
STORED
get good
VALUE good 32 21
beforeworldhelloafter
END

//删除
delete good
DELETED
get good
END


delete good
NOT_FOUND


cas good 32 0 10 hel
helloworld
EXISTS

gets good
VALUE good 32 10 10
helloworld
END


cas bad 32 0 10 good
worldhello
NOT_FOUND


//统计
stats items
STAT items:1:number 1
STAT items:1:age 24
STAT items:1:evicted 0
STAT items:1:outofmemory 0
END


stats sizes
96 1
END

stats slabs
STAT 1:chunk_size 88
STAT 1:chunks_per_page 11915
STAT 1:total_pages 1
STAT 1:total_chunks 11915
STAT 1:used_chunks 11914
STAT 1:free_chunks 1
STAT 1:free_chunks_end 11913
STAT 2:chunk_size 112
STAT 2:chunks_per_page 9362
STAT 2:total_pages 1
STAT 2:total_chunks 9362
STAT 2:used_chunks 9361
STAT 2:free_chunks 1
STAT 2:free_chunks_end 9361
STAT 5:chunk_size 232
STAT 5:chunks_per_page 4519
STAT 5:total_pages 1
STAT 5:total_chunks 4519
STAT 5:used_chunks 4518
STAT 5:free_chunks 1
STAT 5:free_chunks_end 4518
STAT active_slabs 3
STAT total_malloced 3145472
END


stats items
STAT items:1:number 1
STAT items:1:age 1768
STAT items:1:evicted 0
STAT items:1:outofmemory 0
END

stats
STAT pid 18261
STAT uptime 528593
STAT time 1237277383
STAT version 1.2.6
STAT pointer_size 32
STAT rusage_user 0.004999
STAT rusage_system 0.015997
STAT curr_items 1
STAT total_items 2
STAT bytes 66
STAT curr_connections 2
STAT total_connections 13
STAT connection_structures 3
STAT cmd_get 11
STAT cmd_set 8
STAT get_hits 2
STAT get_misses 9
STAT evictions 0
STAT bytes_read 1342
STAT bytes_written 8752
STAT limit_maxbytes 134217728
STAT threads 1
END


使用usr/bin/perl /root/memcached-1.2.6/scripts/memcached-tool localhost:11211
output
# Item_Size   Max_age 1MB_pages Count   Full?
1      88 B     1531 s       1       1      no
2     112 B        0 s       1       0      no
5     232 B        0 s       1       0      no

# slab class编号
Item_Size Chunk大小
Max_age LRU内最旧的记录的生存时间
1MB_pages 分配给Slab的页数
Count Slab内的记录数
Full? Slab内是否含有空闲chunk

猜你喜欢

转载自zhangnet1.iteye.com/blog/898364