安装和使用memcached

[color=blue][b]1简介:[/b][/color]
高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载
示例图:
[img]http://dl2.iteye.com/upload/attachment/0099/9196/44aa33f7-73de-30fa-8f08-0271ba29eca9.png[/img]
[color=blue][b]2运行方式:[/b][/color]
读取:
读取操作的顺序是从 Web 层获取请求(需要执行一次数据库查询)并检查之前在缓存中存储的查询结果。如果我找到所需的值,则返回它。如果未找到,则执行查询并将结果存储在缓存中,然后再将结果返回给 Web 层。
写入:
将数据写入到数据库中时,首先需要执行数据库写入操作,然后将之前缓存的任何受此写入操作影响的结果设定为无效。此过程有助于防止缓存和数据库之间出现数据不一致性。
[color=blue][b]3安装:[/b][/color]
[b]异步事件通知库 libevent:[/b] [url]http://libevent.org/[/url]
[b]缓存系统 memcached:[/b] [url]http://www.memcached.org/[/url]

[code="shell"]
# ./configure
# make
# make install

# chmod +x configure
# ./configure
# make
# make install
[/code]

[color=blue][b]4启动命令:[/b][/color]

./memcached -d -m 128 -u root -l 192.168.31.137 -p 11211 -c 256 -P /tmp/memcached.pid


-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是128MB,
-u是运行Memcache的用户,我这里是root,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.31.137(不指定为本机)
-p是设置Memcache监听的端口,我这里设置了11211,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,
使用netstat -tnlp查看监听

[code="shell"]
# ps aux|grep memcached
weblogic 27051 0.0 0.0 54052 844 ? Ssl 14:13 0:00 ./memcached -d -m 1024 -l 192.168.31.137 -p 11211
root 27117 0.0 0.0 5008 652 pts/1 R+ 14:16 0:00 grep memcached
[/code]

[color=blue][b]5关闭命令:[/b][/color]
kill them

[color=blue][b]5问题:[/b][/color]
1 memacheded在make时报错

make[2]: *** [memacheded] Error 1
make[2]: Leaving directory `/data/soft/memcached-1.4.5'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/data/soft/memcached-1.4.5'
make: *** [all] Error 2

方案:版本问题,重新重新选择

make[2]: *** [testapp.o] Error 1
make[2]: Leaving directory `/data/soft/memcached-1.4.5'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/data/soft/memcached-1.4.5'
make: *** [all] Error 2

方案:注视掉testapp.o的200行(未遇到,待验证)
2 memacached在make时找不到libevent-2.0.so.5的所在的目录

./memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

方案:做个软链接
[code="shell"]
# ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5
[/code]
3 无法启动memcached(增加-u root)

can't run as root without the -u switch


./memcached -d -m 1024 -l 192.168.31.137 -p 11211 -u root



5下载
MemcachePHP监控[url]http://livebookmark.net/memcachephp/memcachephp.zip[/url]
Memcached-Java-Client [url]https://github.com/gwhalin/Memcached-Java-Client/downloads[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值