歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux管理 >> Linux配置

CentOS下repcached的安裝及雙向復制

測試環境:
系統:CentOS release 5.8 (Final)
repcached:memcached-1.2.8-repcached-2.2.tar.gz
libevent-devel:libevent-devel-1.4.13-1
repcached下載地址:http://downloads.sourceforge.net/repcached/memcached-1.2.8-repcached-2.2.tar.gz
libevent-devel使用yum安裝的。

一、安裝
1、下載repcached
[root@biao ~]# wget http://downloads.sourceforge.net/repcached/memcached-1.2.8-repcached-2.2.tar.gz
 --2013-01-05 00:58:28--  http://downloads.sourceforge.net/repcached/memcached-1.2.8-repcached-2.2.tar.gz
 Resolving downloads.sourceforge.net... 216.34.181.59
 Connecting to downloads.sourceforge.net|216.34.181.59|:80... connected.
 HTTP request sent, awaiting response... 301 Moved Permanently
 Location: http://downloads.sourceforge.net/project/repcached/repcached/2.2-1.2.8/memcached-1.2.8-repcached-2.2.tar.gz [following]
 --2013-01-05 00:58:49--  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 request sent, awaiting response... 302 Found
 Location: http://nchc.dl.sourceforge.net/project/repcached/repcached/2.2-1.2.8/memcached-1.2.8-repcached-2.2.tar.gz [following]
 --2013-01-05 00:58:50--  http://nchc.dl.sourceforge.net/project/repcached/repcached/2.2-1.2.8/memcached-1.2.8-repcached-2.2.tar.gz
 Resolving nchc.dl.sourceforge.net... 211.79.60.17, 2001:e10:ffff:1f02::17
 Connecting to nchc.dl.sourceforge.net|211.79.60.17|:80... connected.
 HTTP request sent, awaiting response... 200 OK
 Length: 227510 (222K) [application/x-gzip]
 Saving to: memcached-1.2.8-repcached-2.2.tar.gz

100%[===================================================================================>] 227,510     9.79K/s   in 24s

2013-01-05 00:59:17 (9.17 KB/s) - `memcached-1.2.8-repcached-2.2.tar.gz' saved [227510/227510]


2、解壓:
[root@biao ~]# tar -zxf memcached-1.2.8-repcached-2.2.tar.gz
 [root@biao ~]# ls memcached-1.2.8-repcached-2.2
 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、安裝libevent-devel包:

[root@biao memcached-1.2.8-repcached-2.2]# yum install libevent-devel
 Loaded plugins: fastestmirror
 Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
 addons                                                                                                | 1.9 kB     00:00
 base                                                                                                  | 1.1 kB     00:00
 epel                                                                                                  | 3.7 kB     00:00
 epel/primary_db                                                                                       | 3.1 MB     00:02
 extras                                                                                                | 2.1 kB     00:00
 update                                                                                                | 1.9 kB     00:00
 update/primary_db                                                                                     | 936 kB     00:00
 Setting up Install Process
 Resolving Dependencies
 --> Running transaction check
 ---> Package libevent-devel.i386 0:1.4.13-1 set to be updated
 --> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================
 Package                             Arch                      Version                       Repository                 Size
 =============================================================================================================================
 Installing:
 libevent-devel                      i386                      1.4.13-1                      base                      373 k

Transaction Summary
 =============================================================================================================================
 Install       1 Package(s)
 Upgrade       0 Package(s)

Total download size: 373 k
 Is this ok [y/N]: y
 Downloading Packages:
 libevent-devel-1.4.13-1.i386.rpm                                                                      | 373 kB     00:00
 Running rpm_check_debug
 Running Transaction Test
 Finished Transaction Test
 Transaction Test Succeeded
 Running Transaction
 Installing     : libevent-devel                                                                                        1/1

Installed:
 libevent-devel.i386 0:1.4.13-1

Complete!

4、config:
[root@biao memcached-1.2.8-repcached-2.2]# ./configure --enable-replication --program-transform-name=s/memcached/repcached/
 checking build system type... i686-pc-linux-gnu
 checking host system type... i686-pc-linux-gnu
 checking target system type... i686-pc-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... (system)
 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
onfig完之後會產生一個Makefile文件:



5、make:

[root@biao memcached-1.2.8-repcached-2.2]# make
 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   -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
 gcc -DHAVE_CONFIG_H -I.  -DNDEBUG   -g -O2 -MT memcached-slabs.o -MD -MP -MF .deps/memcached-slabs.Tpo -c -o memcached-slabs.o `test -f 'slabs.c' || echo './'`slabs.c
 mv -f .deps/memcached-slabs.Tpo .deps/memcached-slabs.Po
 gcc -DHAVE_CONFIG_H -I.  -DNDEBUG   -g -O2 -MT memcached-items.o -MD -MP -MF .deps/memcached-items.Tpo -c -o memcached-items.o `test -f 'items.c' || echo './'`items.c
 mv -f .deps/memcached-items.Tpo .deps/memcached-items.Po
 gcc -DHAVE_CONFIG_H -I.  -DNDEBUG   -g -O2 -MT memcached-assoc.o -MD -MP -MF .deps/memcached-assoc.Tpo -c -o memcached-assoc.o `test -f 'assoc.c' || echo './'`assoc.c
 mv -f .deps/memcached-assoc.Tpo .deps/memcached-assoc.Po
 gcc -DHAVE_CONFIG_H -I.  -DNDEBUG   -g -O2 -MT memcached-thread.o -MD -MP -MF .deps/memcached-thread.Tpo -c -o memcached-thread.o `test -f 'thread.c' || echo './'`thread.c
 mv -f .deps/memcached-thread.Tpo .deps/memcached-thread.Po
 gcc -DHAVE_CONFIG_H -I.  -DNDEBUG   -g -O2 -MT memcached-stats.o -MD -MP -MF .deps/memcached-stats.Tpo -c -o memcached-stats.o `test -f 'stats.c' || echo './'`stats.c
 mv -f .deps/memcached-stats.Tpo .deps/memcached-stats.Po
 gcc -DHAVE_CONFIG_H -I.  -DNDEBUG   -g -O2 -MT memcached-replication.o -MD -MP -MF .deps/memcached-replication.Tpo -c -o memcached-replication.o `test -f 'replication.c' || echo './'`replication.c
 mv -f .deps/memcached-replication.Tpo .deps/memcached-replication.Po
 gcc  -g -O2   -o memcached memcached-memcached.o memcached-slabs.o memcached-items.o memcached-assoc.o memcached-thread.o memcached-stats.o memcached-replication.o  -levent
 gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT memcached.o -MD -MP -MF .deps/memcached.Tpo -c -o memcached.o memcached.c
 mv -f .deps/memcached.Tpo .deps/memcached.Po
 gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT slabs.o -MD -MP -MF .deps/slabs.Tpo -c -o slabs.o slabs.c
 mv -f .deps/slabs.Tpo .deps/slabs.Po
 gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT items.o -MD -MP -MF .deps/items.Tpo -c -o items.o items.c
 mv -f .deps/items.Tpo .deps/items.Po
 gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT assoc.o -MD -MP -MF .deps/assoc.Tpo -c -o assoc.o assoc.c
 mv -f .deps/assoc.Tpo .deps/assoc.Po
 gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT thread.o -MD -MP -MF .deps/thread.Tpo -c -o thread.o thread.c
 mv -f .deps/thread.Tpo .deps/thread.Po
 gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT stats.o -MD -MP -MF .deps/stats.Tpo -c -o stats.o stats.c
 mv -f .deps/stats.Tpo .deps/stats.Po
 gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT replication.o -MD -MP -MF .deps/replication.Tpo -c -o replication.o replication.c
 mv -f .deps/replication.Tpo .deps/replication.Po
 gcc  -g -O2   -o memcached-debug memcached.o slabs.o items.o assoc.o thread.o stats.o replication.o  -levent
 make[2]: Leaving directory `/root/memcached-1.2.8-repcached-2.2'
 make[1]: Leaving directory `/root/memcached-1.2.8-repcached-2.2'

6、make install:
[root@biao memcached-1.2.8-repcached-2.2]# make install
 Making install in doc
 make[1]: Entering directory `/root/memcached-1.2.8-repcached-2.2/doc'
 make[2]: Entering directory `/root/memcached-1.2.8-repcached-2.2/doc'
 make[2]: Nothing to be done for `install-exec-am'.
 test -z "/usr/local/share/man/man1" || /bin/mkdir -p "/usr/local/share/man/man1"
 /usr/bin/install -c -m 644 './memcached.1' '/usr/local/share/man/man1/repcached.1'
 make[2]: Leaving directory `/root/memcached-1.2.8-repcached-2.2/doc'
 make[1]: Leaving directory `/root/memcached-1.2.8-repcached-2.2/doc'
 make[1]: Entering directory `/root/memcached-1.2.8-repcached-2.2'
 make[2]: Entering directory `/root/memcached-1.2.8-repcached-2.2'
 test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin"
 /usr/bin/install -c 'memcached' '/usr/local/bin/repcached'
 /usr/bin/install -c 'memcached-debug' '/usr/local/bin/repcached-debug'
 make[2]: Nothing to be done for `install-data-am'.
 make[2]: Leaving directory `/root/memcached-1.2.8-repcached-2.2'
 make[1]: Leaving directory `/root/memcached-1.2.8-repcached-2.2
/usr/bin/install -c ‘memcached’ ‘/usr/local/bin/repcached’
/usr/bin/install -c ‘memcached-debug’ ‘/usr/local/bin/repcached-debug’

此處表明,程序安裝在/usr/local/bin目錄下。
至此,repcached安裝完成。

二、測試
root用戶啟動要加參數-u root,非root用戶不需要
1、啟動master:
[grid@biao ~]$ /usr/local/bin/repcached -p 11211 -v -d
[grid@biao ~]$ replication: listen

2、啟動slave:
[grid@biao ~]$ /usr/local/bin/repcached -p 11212 -x 127.0.0.1 -v -d
 replication: connect (peer=127.0.0.1:11212)
 replication: marugoto copying
 replication: accept
 replication: start

3、確保repcached進程啟動成功:
[root@biao ~]# ps aux
 ...
 grid      3178  0.0  0.0   2660   928 ?        Ss   01:33   0:00 /usr/local/bin/repcached -p 11211 -v -d
 grid      3236  0.0  0.0   2680   688 ?        Ss   01:34   0:00 /usr/local/bin/repcached -p 11212 -x 127.0.0.1 -v -d
 ...

4、測試操作:
[grid@biao ~]$ telnet localhost 11211
 Trying 127.0.0.1...
 Connected to localhost.localdomain (127.0.0.1).
 Escape character is '^]'.
 set t1 0 0 5
 hello
 STORED
 get t1
 VALUE t1 0 5
 hello
 END
 quit
 Connection closed by foreign host.
 [grid@biao ~]$ telnet localhost 11212
 Trying 127.0.0.1...
 Connected to localhost.localdomain (127.0.0.1).
 Escape character is '^]'.
 get t1
 VALUE t1 0 5
 hello
 END
 set t2 0 0 2
 hi
 STORED
 get t2
 VALUE t2 0 2
 hi
 END
 quit
 Connection closed by foreign host.
 [grid@biao ~]$ telnet localhost 11211
 Trying 127.0.0.1...
 Connected to localhost.localdomain (127.0.0.1).
 Escape character is '^]'.
 get t2
 VALUE t2 0 2
 hi
 END
如結果所示,repcached雙向復制成功。
Copyright © Linux教程網 All Rights Reserved