大型网站架构设计-消息系统ActiveMQ &JMS (1)

文章标签: 大型网站架构设计
2014-12-20 5:44:36     26 人阅读    

memcache1是danga.com的一个项目,它是一款开源的高性能的分布式内存对象缓存系统, 最早是给LiveJournal2提供服务的,后来逐渐被越来越多的大型网站所采用,用于在应用中减少 对数据库的访问,提高应用的访问速度,并降低数据库的负载。
为了在内存中提供数据的高速查找能力,memcache使用key-value形式存储和访问数据, 在内存中维护一张巨大的HashTable,使得对数据查询的时间复杂度降低到0(1),保证了对数 据的高性能访问。内存的空间总是有限的,当内存没有更多的空间来存储新的数据时,memcache 就会使用LRU (LeastRecently Used)算法,将最近不常访问的数据淘汰掉,以腾出空间来存放 新的数据。memcache存储支持的数据格式也是灵活多样的,通过对象的序列化机制,可以将更 高层抽象的对象转换成为二进制数据,存储在缓存服务器中,当前端应用需要时,又可以通过 二进制内容反序列化,将数据还原成原有对象。
memcache 的安装
由于memcache使用了 libevent来进行高效的网络连接处理,因此在安装memcache之前, 需要先安装libevent。
下载libevent3,这里采用的是1.4.14版本的libevent。
wget https://github.com/downloads/libevent/libevent/libevent-1.4.14b-
stable.tar.gz  
https://gtthub.con/downloads/ltbevent/llbevent/libe vent-1.4.14b-stable.tar.gz
--2014-03-19 04:52:41-- https://glthub*con/downloads/libevent/llbevent/libevent -1.4.14b- stable.ta r.gz
Resolving glthub*con (glthub.con)... 192.30.252.129
Connecting to glthub.com (github.com)f192.30.252.129|:443... connected*
HTTP request sent, awaiting response... 302 Found
Locationr http://cloud.github*corn/downloads/llbevent/libevent/libevent-l.4*14b-s table.tar.gz [following]
--2014-03-19 04:52:55-- http://cloud.github*cam/downloads/libevent/libevent/lib event-1.4*14b-stable.tar.gz
Resolving cloud.github.com (cloud.github.con)* 205.251.212.145, 205.251.212.82 ,54.230.126.248, ...
Connecting to cloud,glthub.con Ccloud.github.com)]265.251.212.145]:80... connect ed.
HTTP request sent, awaiting response... 302 Found
Location: httpI//218.108.192.119:80/lQ2W3E4R5T6Y7U8I9O0PlZ2X3C4V5B/cl〇ud.glthub. con/downloads/llbevent/libevent/llbevent-1»4.14b-stable.tar.gz [following] ”2014-03-19 04:53:04-- http://218.108.192.119/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/C loud,glthub.con/downloads/ltbevent/libevent/llbevent-1 * 4.14b-stable.tar.gz Connecting to 218*108*192.119:80…connected.
HTTP request sent, awaiting response... 200 OK Length: 474874 (464K) [application/gzip]
Saving to: 'llbevent-1.4*14b-stable.tar*gz'
解压:
tar -xf libevent-1.4.14b-stable.tar.gz


配置、编译、安装libevent:
./configure
longlong@ubuntu:-/temp/llbevent-1.4.14b-stable? ./configure
checking for a BSD-compatible install.* * /usr/btn/lnstall -c
checking whether build environment is sane*., yes
checking for a thread-safe nkdir -p*.. /bin/mkdir -p
checking for gawk... no
checking for nawk.,. nawk
checking whether make sets $(NAKE)**. yes
checking build system type.* * i686-pc-linux-gnu
checking host system type..* 1686-pc-linux-gnu
checking for gcc.“ gcc
checking whether the C compiler works.* * yes
checking for C compiler default output file nane... a.out
make
make all-recursive 
sudo make install
/usr/bin/lnstall -c event_rpcgen.py '/usr/local/bin* test -z "/usr/local/lib" || /bln/mkdlr -p "/usr/local/lib"
/bin/bash ./libtool --node=install /usr/bin/install -c llbevent.la libeven _core.la libevent_extra.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libevent-1.4.so.2.2.0 /usr/local/lil /llbevent-1.4.so.2.2.0
libtool: Install: (cd /usr/local/lib && { In -s -f libevent-1.4.so.2.2.0 libevei t-1.4.so.2 || { rn -f llbevent-1.4.so.2 && In -s llbevent-1.4.so.2.2.0 llbevent 1.4.so.2; }; })
libtool: install: (cd /usr/local/lib && { In -s -f libevent-1.4.so.2.2.0 libevei t.so || { rn -f llbevent.so && In -s libevent-1.4.so.2.2.0 llbevent.so; }; }) libtool: Install: /usr/bin/install -c .llbs/libevent«lal /usr/local/lib/llbeven
下载memcache,并解压:
wget
http://www.memcached.Org/files/memcached-1.4.17.tar.gz
http://www.nencached.org/ftles/nencached-l.4.17.tar
• gz
--2014-03-19 05:02:12-- http://www.mencached.Org/flles/memcached-l.4.17.tar.gz
Resolving www.nencached.org (www.nencached.org)... 69.46.88.68
Connecting to www.memcached.org (www.memcached.org)|69.46.88.68|:80... connected
HTTP request sent, awaiting response... 302 Found
Location: http://218.108.192.145:80/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/www.memcached .org/flles/memcached-1.4.17.tar.gz [following]
--2014-03-19 05:02:24-- http://218.108.192.145/1Q2W3E4R5T6Y7U8I906P1Z2X3C4V5B/W ww.memcached.org/flles/memcached-1.4.17.tar.gz Connecting to 218.108.192.145:80... connected.
HTTP request sent, awaiting response... 266 OK Length: 326970 (319K) [applicatlon/x-tar]
Saving to: 'memcached-1.4.17.tar.gz'
100%[======================================>] 326,970 1.78M/S in 0.2s
2014-03-19 05:02:24 (1.78 MB/s) - nencached-1.4.17.tar.gz' saved [326970/326970
tar -xf memcached-1.4.17.tar.gz


配置、编译、安装memcache:
./configure
longlong@ubuntu:-/tenp/nencached-1.4.17$ make make all-recursive
nake[l]: Entering directory '/home/longlong/tenp/mencached-1.4.17'
Making all in doc
nake[2]: Entering directory '/home/longlong/tenp/mencached-1.4.17/doc' make all-an
nake[3]: Entering directory '/home/longlong/tenp/mencached-1.4.17/doc' nake[3]: Nothing to be done for %all-an'.
nake[3]: Leaving directory %/h〇ne/longlong/tenp/nemcached-l.4.17/doc'
nake[2]: Leaving directory '/h〇ne/longlong/tenp/nemcached-l.4.17/doc'
nake[2]: Entering directory '/home/longlong/tenp/nencached-1.4.17'
gcc -Std=gnu99 -DHAVE_CONFIG_H -I. -DNDEBUG -g -02 -pthread -pthread -Wall -V
error -pedantic -Wnissing-prototypes -Wnlsslng-declarations -Wredundant-decls •卜
T mencached-memcached.o -MD -MP -MF .deps/nencached-nencached.Tpo -c -o mencachc
d-memcached.o * test -f 'memcached.c' || echo '''nemcached.c
nv -f .deps/mencached-nemcached.Tpo .deps/memcached-nemcached.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I. >DNDEBUG -g -〇2 -pthread -pthread -Wall -V
error -pedantic -Wnissing-prototypes -Wnlsslng-declarations -Wredundant-decls •卜
T memcached-hash.o -MD -MP -MF .deps/memcached-hash.Tpo -c -o memcached-hash.o ’
sudo make install
启动与关闭memcache
启动memcache服务:
/usr/local/bin/memcached -d -m 10 -u root -l 192.168.136.135 -p 11211 -c 32 -P /tmp/memcached.pid
参数的含义如下:
-d表示启动的是一个守护进程;
-m指定分配给memcache的内存数量,单位是MB,这里指定的是10 MB。
-u指定运行memcache的用户,这里指定的是root;
-l指定监听的服务器的IP地址;
-p设置memcache监听的端口,这里指定的是11211;
-c指定最大允许的并发连接数,这里设置为32;
-P指定memcache的pid文件保存的位置。
longlong@ubuntu:~/tenp/mencached-1.4.17$ ps >aux | grep nencached Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.htnl longlong 8132 1.0 0.0 47996 816 ? Ssl 05:57 0:00 /usr/local/bln/
nencached -d -n 10 -u root -1 192.168.136.135 -p 11211 -c 256 -P /tnp/nencached. pid I
关闭memcache服务:
kill 'cat /tmp/memcached.pid
longlong@ubuntu:~/tenp/nencached-1.4.17$ ps -aux | grep nencached
Warning: bad ps syntax, perhaps a bogus •-•? See http://procps.sf.net/faq.htnl

本文出自   《大型分布式网站架构设计与实践试读样章》 试读,如果感觉到对你有帮助可以去购买该书


原文地址:http://www.itmmd.com/201412/348.html
该文章由 萌萌的IT人 整理发布,转载须标明出处。

大型网站架构设计-消息系统ActiveMQ &JMS (2)   上一篇
下一篇  大型网站架构设计-Redis 高性能的key-value数据库

精彩回复
发表评论
姓名:       

《程序员app》专门为程序员量身定做!