`
a387776286
  • 浏览: 11469 次
  • 性别: Icon_minigender_1
  • 来自: 太原
社区版块
存档分类
最新评论

安装和使用memcached

 
阅读更多
1简介:
高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载
示例图:

2运行方式:
读取:
读取操作的顺序是从 Web 层获取请求(需要执行一次数据库查询)并检查之前在缓存中存储的查询结果。如果我找到所需的值,则返回它。如果未找到,则执行查询并将结果存储在缓存中,然后再将结果返回给 Web 层。
写入:
将数据写入到数据库中时,首先需要执行数据库写入操作,然后将之前缓存的任何受此写入操作影响的结果设定为无效。此过程有助于防止缓存和数据库之间出现数据不一致性。
3安装:
异步事件通知库 libevent: http://libevent.org/
缓存系统 memcached: http://www.memcached.org/

[root@localhost libevent-2.0.21-stable]# ./configure 
[root@localhost libevent-2.0.21-stable]# make
[root@localhost libevent-2.0.21-stable]# make install

[root@localhost memcached-1.4.20]# chmod +x configure
[root@localhost memcached-1.4.20]# ./configure 
[root@localhost memcached-1.4.20]# make
[root@localhost memcached-1.4.20]# make install


4启动命令:
./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查看监听

[root@localhost memcached]# 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


5关闭命令:
kill them

5问题:
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

方案:做个软链接
[root@localhost lib]# ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5

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监控http://livebookmark.net/memcachephp/memcachephp.zip
Memcached-Java-Client https://github.com/gwhalin/Memcached-Java-Client/downloads
  • 大小: 265.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics