repcached安装配置及复制实验

来源:互联网 发布:淘宝网地垫 编辑:程序博客网 时间:2024/06/01 07:59

repcached介绍
repcached是日本人开发的实现memcached复制功能,它是一个单 master单 slave的方案,但它的 master/slave都是可读写的,而且可以相互同步,如果 master坏掉, slave侦测到连接断了,它会自动 listen而成为 master;而如果 slave坏掉, master也会侦测到连接断,它就会重新 listen等待新的 slave加入。

安装步骤

1.安装libevent-devel包
因为repcached依赖于libevent-devel包,所以首先安装libevent-devel包
下载地址:http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
--尝试使用yum安装失败
[root@njdyw memcached-1.2.8-repcached-2.2]# yum install libevent-devel
Loaded plugins: rhnplugin, security
This system is not registered with ULN.
ULN support will be disabled.
Setting up Install Process
No package libevent-devel available.
Nothing to do

--下载再安装
[root@njdyw ~]# wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
[root@njdyw ~]# tar zxvf libevent-1.4.13-stable.tar.gz
[root@njdyw ~]# cd libevent-1.4.13-stable
[root@njdyw libevent-1.4.13-stable]# ./configure --prefix=/usr/local/libevent
[root@njdyw libevent-1.4.13-stable]# make && make install

2.安装repcached

(1).下载对应的repcached版本(里面已经包含了memcached)

[root@njdyw ~]# wget http://downloads.sourceforge.net/repcached/memcached-1.2.8-repcached-2.2.tar.gz
--2012-12-30 22:44:28--  http://downloads.sourceforge.net/repcached/memcached-1.2.8-repcached-2.2.tar.gz
正在解析主机 downloads.sourceforge.net... 216.34.181.59
Connecting to downloads.sourceforge.net|216.34.181.59|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 301 Moved Permanently
位置:http://downloads.sourceforge.net/project/repcached/repcached/2.2-1.2.8/memcached-1.2.8-repcached-2.2.tar.gz [跟随至新的 URL]
--2012-12-30 22:44:28--  http://downloads.sourceforge.net/project/repcached/repcached/2.2-1.2.8/memcached-1.2.8-repcached-2.2.tar.gz
Reusing existing connection to downloads.sourceforge.net:80.
已发出 HTTP 请求,正在等待回应... 302 Found
位置:http://jaist.dl.sourceforge.net/project/repcached/repcached/2.2-1.2.8/memcached-1.2.8-repcached-2.2.tar.gz [跟随至新的 URL]
--2012-12-30 22:44:29--  http://jaist.dl.sourceforge.net/project/repcached/repcached/2.2-1.2.8/memcached-1.2.8-repcached-2.2.tar.gz
正在解析主机 jaist.dl.sourceforge.net... 150.65.7.130, 2001:200:141:feed::feed
Connecting to jaist.dl.sourceforge.net|150.65.7.130|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:227510 (222K) [application/x-gzip]
Saving to: `memcached-1.2.8-repcached-2.2.tar.gz'
100%[==========================================================================================>] 227,510      104K/s   in 2.1s   
2012-12-30 22:44:32 (104 KB/s) - `memcached-1.2.8-repcached-2.2.tar.gz' saved [227510/227510]

(2).解压下载文件
[root@njdyw ~]# tar zxvf memcached-1.2.8-repcached-2.2.tar.gz
[root@njdyw ~]# cd memcached-1.2.8-repcached-2.2/
[root@njdyw memcached-1.2.8-repcached-2.2]# ls
aclocal.m4         ChangeLog.repcached  configure.ac  items.c             memcached_dtrace.h  replication.c  stats.h
assoc.c            compile              COPYING       items.h             memcached.h         replication.h  t
assoc.h            config.guess         daemon.c      Makefile.am         memcached.spec      scripts        thread.c
AUTHORS            config.h.in          depcomp       Makefile.in         missing             slabs.c        TODO
AUTHORS.repcached  config.sub           doc           memcached.c         NEWS                slabs.h        t.rep
ChangeLog          configure            install-sh    memcached_dtrace.d  README              stats.c

(3).编译repcached程序文件
[root@njdyw memcached-1.2.8-repcached-2.2]# ./configure --enable-replication --program-transform-name=s/memcached/repcached/ --with-libevent=/usr/local/libevent
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking whether gcc and cc understand -c and -o together... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for libevent directory... /usr/local/libevent/
checking for library containing socket... none required
checking for library containing gethostbyname... none required
checking for library containing mallinfo... none required
checking for daemon... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
checking for an ANSI C-conforming const... yes
checking malloc.h usability... yes
checking malloc.h presence... yes
checking for malloc.h... yes
checking for struct mallinfo.arena... yes
checking for socklen_t... yes
checking for endianness... little
checking for mlockall... yes
checking for getpagesizes... no
checking for memcntl... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating config.h
config.status: executing depfiles commands

[root@njdyw memcached-1.2.8-repcached-2.2]# make && make install
make  all-recursive
make[1]: Entering directory `/root/memcached-1.2.8-repcached-2.2'
Making all in doc
make[2]: Entering directory `/root/memcached-1.2.8-repcached-2.2/doc'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/memcached-1.2.8-repcached-2.2/doc'
make[2]: Entering directory `/root/memcached-1.2.8-repcached-2.2'
gcc -DHAVE_CONFIG_H -I.  -DNDEBUG -I/usr/local/libevent//include   -g -O2 -MT memcached-memcached.o -MD -MP -MF .deps/memcached-memcached.Tpo -c -o memcached-memcached.o `test -f 'memcached.c' || echo './'`memcached.c
mv -f .deps/memcached-memcached.Tpo .deps/memcached-memcached.Po
..........

(4).按前3步配置其它slave节点
--因本实验master,slave在同一台机器上,固省去此步。

(5).启动repcached
--启动master节点
[root@njdyw memcached-1.2.8-repcached-2.2]# /usr/local/bin/repcached -p 11211 -v -d
can't run as root without the -u switch
[root@njdyw memcached-1.2.8-repcached-2.2]# su - oracle
[oracle@njdyw ~]$ /usr/local/bin/repcached -p 11211 -v -d
replication: listen

--启动slave节点
[oracle@njdyw ~]$ /usr/local/bin/repcached -p 11212 -x localhost -v -d
[oracle@njdyw ~]$ replication: connect (peer=127.0.0.1:11212)
replication: marugoto copying
replication: accept
replication: start
注意:启动repcached要用非root用户,不然会启动失败,如上面所示

3.repcached复制实验

--master->slave复制
[oracle@njdyw ~]$ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
set licz 0 0 5
zai
STORED
get licz
VALUE licz 0 5
zai
END
quit
Connection closed by foreign host.

----数据已经同步到slave
[oracle@njdyw ~]$ telnet localhost 11212
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
get licz
VALUE licz 0 5
zai
END

--slave->master复制
[oracle@njdyw ~]$ telnet localhost 11212
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
set hello2
ERROR
set hello2 0 0 4
ruby
STORED
quit
Connection closed by foreign host.
----数据已经同步到master
[oracle@njdyw ~]$ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
get hello2
VALUE hello2 0 4
ruby
END
--看到repcached可以成功的做到数据的双向复制

4.监控memcached
[oracle@njdyw ~]$ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
stats cachedump 1 10
ITEM hello2 [4 b; 1356885605 s]
ITEM licz [5 b; 1356885605 s]
END
stats items
STAT items:1:number 2
STAT items:1:age 1067
STAT items:1:evicted 0
STAT items:1:evicted_time 0
STAT items:1utofmemory 0
STAT items:1:tailrepairs 0
END


遇到的问题:
1.编译repcached失败
现象:
[root@njdyw ~]# cd memcached-1.2.8-repcached-2.2
[root@njdyw memcached-1.2.8-repcached-2.2]# ./configure --enable-replication --program-transform-name=s/memcached/repcached/
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking whether gcc and cc understand -c and -o together... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for libevent directory... configure: error: libevent is required.  You can get it fromhttp://www.monkey.org/~provos/libevent/
      If it's already installed, specify its path using --with-libevent=/dir/
      
解决:
加上--with-libevent=/dir/
如下:
./configure --enable-replication --program-transform-name=s/memcached/repcached/ --with-libevent=/usr/local/libevent
2.memcached找不到-x参数
现象:
[oracle@njdyw ~]$ /usr/local/memcache/bin/memcached -p 11212 -x localhost -v -d
/usr/local/memcache/bin/memcached: invalid option -- x
Illegal argument "?"
[oracle@njdyw ~]$  
解决:
根据问题1方法操作,重新make,再次执行正常
/usr/local/bin/repcached -p 11212 -x localhost -v -d

 

参考:

http://code.google.com/p/memcached/wiki/NewInstallFromSource

http://blog.csdn.net/wyzxg/article/details/6086523

原创粉丝点击