How to use memcached with replication on CentOS


Repcached is memcached which implemented multi master asynchronous replication feature. Download source code.

Repcached key features

  • Multi master replication.
  • Asynchronous data repliacation.
  • Support all memcached command (set, add, delete, incr/decr, flush_all, cas)

Suppose you have 2 servers with IP are 11.11.11.11 and 22.22.22.22
Step 1: Install on each node:
Step 1.1: Install requirement

yum install libevent-dev -y

Step 1.2: install repcached
Install repcached 2.2.1 for memcached 1.2.8
Method 1:

 wget http://jaist.dl.sourceforge.net/project/repcached/repcached/2.2.1-1.2.8/memcached-1.2.8-repcached-2.2.1.tar.gz
tar xvzf memcached-1.2.8-repcached-2.2.1.tar.gz
cd memcached-1.2.8-repcached-2.2.1
./configure --enable-replication
make
make install

For CentOS 64 bits

./configure --enable-64bit --enable-replication

Method 2:

git clone https://github.com/yokogawa-k/repcached.git
cd repcached
./configure --enable-64bit --enable-replication
make
make install

Instal repcached 2.3.1 for Memcached 1.4.13
Method 1:

git clone https://github.com/kspe/repcached.git
cd repcached
./configure --enable-64bit --enable-replication
make
make install

result:

[root@tutorialspots ~]# yum install git libevent-devel -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                     |  23 kB     00:01
 * base: ftp.plusline.net
 * epel: ftp.plusline.net
 * extras: mirror.ratiokontakt.de
 * ius: mirror.ehv.weppel.nl
 * updates: mirror.checkdomain.de
base                                                     | 3.6 kB     00:00
epel                                                     | 3.2 kB     00:00
extras                                                   | 3.4 kB     00:00
ius                                                      | 2.3 kB     00:00
nodesource                                               | 2.5 kB     00:00
updates                                                  | 3.4 kB     00:00
(1/4): epel/x86_64/updateinfo                              | 942 kB   00:00
(2/4): nodesource/x86_64/primary_db                        |  28 kB   00:00
(3/4): epel/x86_64/primary                                 | 3.6 MB   00:03
(4/4): ius/x86_64/primary_db                               | 442 kB   00:03
epel                                                                12776/12776
Resolving Dependencies
--> Running transaction check
---> Package git.x86_64 0:1.8.3.1-20.el7 will be installed
--> Processing Dependency: perl-Git = 1.8.3.1-20.el7 for package: git-1.8.3.1-20.el7.x86_64
--> Processing Dependency: perl(Term::ReadKey) for package: git-1.8.3.1-20.el7.x86_64
--> Processing Dependency: perl(Git) for package: git-1.8.3.1-20.el7.x86_64
--> Processing Dependency: perl(Error) for package: git-1.8.3.1-20.el7.x86_64
---> Package libevent-devel.x86_64 0:2.0.21-4.el7 will be installed
--> Processing Dependency: libevent = 2.0.21-4.el7 for package: libevent-devel-2.0.21-4.el7.x86_64
--> Processing Dependency: libevent_pthreads-2.0.so.5()(64bit) for package: libevent-devel-2.0.21-4.el7.x86_64
--> Processing Dependency: libevent_openssl-2.0.so.5()(64bit) for package: libevent-devel-2.0.21-4.el7.x86_64
--> Processing Dependency: libevent_extra-2.0.so.5()(64bit) for package: libevent-devel-2.0.21-4.el7.x86_64
--> Processing Dependency: libevent_core-2.0.so.5()(64bit) for package: libevent-devel-2.0.21-4.el7.x86_64
--> Processing Dependency: libevent-2.0.so.5()(64bit) for package: libevent-devel-2.0.21-4.el7.x86_64
--> Running transaction check
---> Package libevent.x86_64 0:2.0.21-4.el7 will be installed
---> Package perl-Error.noarch 1:0.17020-2.el7 will be installed
---> Package perl-Git.noarch 0:1.8.3.1-20.el7 will be installed
---> Package perl-TermReadKey.x86_64 0:2.30-20.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch         Version                Repository     Size
================================================================================
Installing:
 git                    x86_64       1.8.3.1-20.el7         updates       4.4 M
 libevent-devel         x86_64       2.0.21-4.el7           base           85 k
Installing for dependencies:
 libevent               x86_64       2.0.21-4.el7           base          214 k
 perl-Error             noarch       1:0.17020-2.el7        base           32 k
 perl-Git               noarch       1.8.3.1-20.el7         updates        55 k
 perl-TermReadKey       x86_64       2.30-20.el7            base           31 k

Transaction Summary
================================================================================
Install  2 Packages (+4 Dependent packages)

Total download size: 4.8 M
Installed size: 23 M
Downloading packages:
(1/6): libevent-2.0.21-4.el7.x86_64.rpm                    | 214 kB   00:00
(2/6): perl-Error-0.17020-2.el7.noarch.rpm                 |  32 kB   00:00
(3/6): perl-TermReadKey-2.30-20.el7.x86_64.rpm             |  31 kB   00:00
(4/6): libevent-devel-2.0.21-4.el7.x86_64.rpm              |  85 kB   00:00
(5/6): perl-Git-1.8.3.1-20.el7.noarch.rpm                  |  55 kB   00:00
(6/6): git-1.8.3.1-20.el7.x86_64.rpm                       | 4.4 MB   00:08
--------------------------------------------------------------------------------
Total                                              560 kB/s | 4.8 MB  00:08
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:perl-Error-0.17020-2.el7.noarch                            1/6
  Installing : libevent-2.0.21-4.el7.x86_64                                 2/6
  Installing : perl-TermReadKey-2.30-20.el7.x86_64                          3/6
  Installing : perl-Git-1.8.3.1-20.el7.noarch                               4/6
  Installing : git-1.8.3.1-20.el7.x86_64                                    5/6
  Installing : libevent-devel-2.0.21-4.el7.x86_64                           6/6
  Verifying  : perl-TermReadKey-2.30-20.el7.x86_64                          1/6
  Verifying  : git-1.8.3.1-20.el7.x86_64                                    2/6
  Verifying  : 1:perl-Error-0.17020-2.el7.noarch                            3/6
  Verifying  : libevent-2.0.21-4.el7.x86_64                                 4/6
  Verifying  : perl-Git-1.8.3.1-20.el7.noarch                               5/6
  Verifying  : libevent-devel-2.0.21-4.el7.x86_64                           6/6

Installed:
  git.x86_64 0:1.8.3.1-20.el7        libevent-devel.x86_64 0:2.0.21-4.el7

Dependency Installed:
  libevent.x86_64 0:2.0.21-4.el7       perl-Error.noarch 1:0.17020-2.el7
  perl-Git.noarch 0:1.8.3.1-20.el7     perl-TermReadKey.x86_64 0:2.30-20.el7

Complete!
[root@tutorialspots ~]# git clone https://github.com/kspe/repcached.git
Cloning into 'repcached'...
remote: Enumerating objects: 193, done.
remote: Total 193 (delta 0), reused 0 (delta 0), pack-reused 193
Receiving objects: 100% (193/193), 482.41 KiB | 57.00 KiB/s, done.
Resolving deltas: 100% (39/39), done.
[root@tutorialspots ~]# cd repcached
[root@tutorialspots repcached]# ./configure --enable-64bit --enable-replication
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... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
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 how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for icc in use... no
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 whether __SUNPRO_C is declared... no
checking for gcc option to accept ISO C99... -std=gnu99
checking whether gcc -std=gnu99 and cc understand -c and -o together... yes
checking sasl/sasl.h usability... no
checking sasl/sasl.h presence... no
checking for sasl/sasl.h... no
checking for gcov... /usr/bin/gcov
checking for main in -lgcov... yes
checking for library containing clock_gettime... none required
checking for library containing socket... none required
checking for library containing gethostbyname... none required
checking for libevent directory... (system)
checking for library containing umem_cache_create... no
checking for library containing gethugepagesizes... no
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
checking for inttypes.h... (cached) yes
checking for sasl_callback_ft... no
checking for print macros for integers (C99 section 7.8.1)... yes
checking for an ANSI C-conforming const... yes
checking for socklen_t... yes
checking for endianness... little
checking for htonll... no
checking for library containing pthread_create... none required
checking for mlockall... yes
checking for getpagesizes... no
checking for memcntl... no
checking for sigignore... yes
checking for clock_gettime... yes
checking for alignment... need
checking for GCC atomics... yes
checking for setppriv... no
checking umem.h usability... no
checking umem.h presence... no
checking for umem.h... no
checking for xml2rfc... no
checking for xsltproc... /usr/bin/xsltproc
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
[root@tutorialspots repcached]# make
CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /root/repcached/missing --run aclocal-1.11
/root/repcached/missing: line 52: aclocal-1.11: command not found
WARNING: `aclocal-1.11' is missing on your system.  You should only need it if
         you modified `acinclude.m4' or `configure.ac'.  You might want
         to install the `Automake' and `Perl' packages.  Grab them from
         any GNU archive site.
 cd . && /bin/sh /root/repcached/missing --run automake-1.11 --foreign
/root/repcached/missing: line 52: automake-1.11: command not found
WARNING: `automake-1.11' is missing on your system.  You should only need it if
         you modified `Makefile.am', `acinclude.m4' or `configure.ac'.
         You might want to install the `Automake' and `Perl' packages.
         Grab them from any GNU archive site.
CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /root/repcached/missing --run autoconf
aclocal.m4:17: warning: this file was generated for autoconf 2.68.
You have another version of autoconf.  It may work, but is not guaranteed to.
If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically `autoreconf'.
/bin/sh ./config.status --recheck
running CONFIG_SHELL=/bin/sh /bin/sh ./configure --enable-64bit --enable-replication --no-create --no-recursion
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... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
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 how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for icc in use... no
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 whether __SUNPRO_C is declared... no
checking for gcc option to accept ISO C99... -std=gnu99
checking whether gcc -std=gnu99 and cc understand -c and -o together... yes
checking sasl/sasl.h usability... no
checking sasl/sasl.h presence... no
checking for sasl/sasl.h... no
checking for gcov... /usr/bin/gcov
checking for main in -lgcov... yes
checking for library containing clock_gettime... none required
checking for library containing socket... none required
checking for library containing gethostbyname... none required
checking for libevent directory... (system)
checking for library containing umem_cache_create... no
checking for library containing gethugepagesizes... no
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
checking for inttypes.h... (cached) yes
checking for sasl_callback_ft... no
checking for print macros for integers (C99 section 7.8.1)... yes
checking for an ANSI C-conforming const... yes
checking for socklen_t... yes
checking for endianness... little
checking for htonll... no
checking for library containing pthread_create... none required
checking for mlockall... yes
checking for getpagesizes... no
checking for memcntl... no
checking for sigignore... yes
checking for clock_gettime... yes
checking for alignment... need
checking for GCC atomics... yes
checking for setppriv... no
checking umem.h usability... no
checking umem.h presence... no
checking for umem.h... no
checking for xml2rfc... no
checking for xsltproc... /usr/bin/xsltproc
configure: creating ./config.status
 /bin/sh ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
(CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /root/repcached/missing --run autoheader)
rm -f stamp-h1
touch config.h.in
cd . && /bin/sh ./config.status config.h
config.status: creating config.h
config.status: config.h is unchanged
make  all-recursive
make[1]: Entering directory `/root/repcached'
Making all in doc
make[2]: Entering directory `/root/repcached/doc'
make  all-am
make[3]: Entering directory `/root/repcached/doc'
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/root/repcached/doc'
make[2]: Leaving directory `/root/repcached/doc'
make[2]: Entering directory `/root/repcached'
gcc -std=gnu99 -DHAVE_CONFIG_H -I.  -DNDEBUG   -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -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 -std=gnu99 -DHAVE_CONFIG_H -I.  -DNDEBUG   -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached-hash.o -MD -MP -MF .deps/memcached-hash.Tpo -c -o memcached-hash.o `test -f 'hash.c' || echo './'`hash.c
mv -f .deps/memcached-hash.Tpo .deps/memcached-hash.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.  -DNDEBUG   -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -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 -std=gnu99 -DHAVE_CONFIG_H -I.  -DNDEBUG   -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -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 -std=gnu99 -DHAVE_CONFIG_H -I.  -DNDEBUG   -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -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 -std=gnu99 -DHAVE_CONFIG_H -I.  -DNDEBUG   -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -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 -std=gnu99 -DHAVE_CONFIG_H -I.  -DNDEBUG   -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached-daemon.o -MD -MP -MF .deps/memcached-daemon.Tpo -c -o memcached-daemon.o `test -f 'daemon.c' || echo './'`daemon.c
mv -f .deps/memcached-daemon.Tpo .deps/memcached-daemon.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.  -DNDEBUG   -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -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 -std=gnu99 -DHAVE_CONFIG_H -I.  -DNDEBUG   -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached-util.o -MD -MP -MF .deps/memcached-util.Tpo -c -o memcached-util.o `test -f 'util.c' || echo './'`util.c
mv -f .deps/memcached-util.Tpo .deps/memcached-util.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.  -DNDEBUG   -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached-cache.o -MD -MP -MF .deps/memcached-cache.Tpo -c -o memcached-cache.o `test -f 'cache.c' || echo './'`cache.c
mv -f .deps/memcached-cache.Tpo .deps/memcached-cache.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.  -DNDEBUG   -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -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 -std=gnu99  -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls   -o memcached memcached-memcached.o memcached-hash.o memcached-slabs.o memcached-items.o memcached-assoc.o memcached-thread.o memcached-daemon.o memcached-stats.o memcached-util.o memcached-cache.o   memcached-replication.o  -levent
gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -fprofile-arcs -ftest-coverage -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached_debug-memcached.o -MD -MP -MF .deps/memcached_debug-memcached.Tpo -c -o memcached_debug-memcached.o `test -f 'memcached.c' || echo './'`memcached.c
mv -f .deps/memcached_debug-memcached.Tpo .deps/memcached_debug-memcached.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -fprofile-arcs -ftest-coverage -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached_debug-hash.o -MD -MP -MF .deps/memcached_debug-hash.Tpo -c -o memcached_debug-hash.o `test -f 'hash.c' || echo './'`hash.c
mv -f .deps/memcached_debug-hash.Tpo .deps/memcached_debug-hash.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -fprofile-arcs -ftest-coverage -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached_debug-slabs.o -MD -MP -MF .deps/memcached_debug-slabs.Tpo -c -o memcached_debug-slabs.o `test -f 'slabs.c' || echo './'`slabs.c
mv -f .deps/memcached_debug-slabs.Tpo .deps/memcached_debug-slabs.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -fprofile-arcs -ftest-coverage -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached_debug-items.o -MD -MP -MF .deps/memcached_debug-items.Tpo -c -o memcached_debug-items.o `test -f 'items.c' || echo './'`items.c
mv -f .deps/memcached_debug-items.Tpo .deps/memcached_debug-items.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -fprofile-arcs -ftest-coverage -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached_debug-assoc.o -MD -MP -MF .deps/memcached_debug-assoc.Tpo -c -o memcached_debug-assoc.o `test -f 'assoc.c' || echo './'`assoc.c
mv -f .deps/memcached_debug-assoc.Tpo .deps/memcached_debug-assoc.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -fprofile-arcs -ftest-coverage -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached_debug-thread.o -MD -MP -MF .deps/memcached_debug-thread.Tpo -c -o memcached_debug-thread.o `test -f 'thread.c' || echo './'`thread.c
mv -f .deps/memcached_debug-thread.Tpo .deps/memcached_debug-thread.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -fprofile-arcs -ftest-coverage -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached_debug-daemon.o -MD -MP -MF .deps/memcached_debug-daemon.Tpo -c -o memcached_debug-daemon.o `test -f 'daemon.c' || echo './'`daemon.c
mv -f .deps/memcached_debug-daemon.Tpo .deps/memcached_debug-daemon.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -fprofile-arcs -ftest-coverage -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached_debug-stats.o -MD -MP -MF .deps/memcached_debug-stats.Tpo -c -o memcached_debug-stats.o `test -f 'stats.c' || echo './'`stats.c
mv -f .deps/memcached_debug-stats.Tpo .deps/memcached_debug-stats.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -fprofile-arcs -ftest-coverage -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached_debug-util.o -MD -MP -MF .deps/memcached_debug-util.Tpo -c -o memcached_debug-util.o `test -f 'util.c' || echo './'`util.c
mv -f .deps/memcached_debug-util.Tpo .deps/memcached_debug-util.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -fprofile-arcs -ftest-coverage -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached_debug-cache.o -MD -MP -MF .deps/memcached_debug-cache.Tpo -c -o memcached_debug-cache.o `test -f 'cache.c' || echo './'`cache.c
mv -f .deps/memcached_debug-cache.Tpo .deps/memcached_debug-cache.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -fprofile-arcs -ftest-coverage -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached_debug-replication.o -MD -MP -MF .deps/memcached_debug-replication.Tpo -c -o memcached_debug-replication.o `test -f 'replication.c' || echo './'`replication.c
mv -f .deps/memcached_debug-replication.Tpo .deps/memcached_debug-replication.Po
gcc -std=gnu99 -fprofile-arcs -ftest-coverage -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls   -o memcached-debug memcached_debug-memcached.o memcached_debug-hash.o memcached_debug-slabs.o memcached_debug-items.o memcached_debug-assoc.o memcached_debug-thread.o memcached_debug-daemon.o memcached_debug-stats.o memcached_debug-util.o memcached_debug-cache.o   memcached_debug-replication.o -lgcov  -levent
gcc -std=gnu99 -DHAVE_CONFIG_H -I.     -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT sizes.o -MD -MP -MF .deps/sizes.Tpo -c -o sizes.o sizes.c
mv -f .deps/sizes.Tpo .deps/sizes.Po
gcc -std=gnu99  -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls   -o sizes sizes.o  -levent
gcc -std=gnu99 -DHAVE_CONFIG_H -I.     -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT testapp.o -MD -MP -MF .deps/testapp.Tpo -c -o testapp.o testapp.c
mv -f .deps/testapp.Tpo .deps/testapp.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.     -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT util.o -MD -MP -MF .deps/util.Tpo -c -o util.o util.c
mv -f .deps/util.Tpo .deps/util.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.     -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT cache.o -MD -MP -MF .deps/cache.Tpo -c -o cache.o cache.c
mv -f .deps/cache.Tpo .deps/cache.Po
gcc -std=gnu99  -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls   -o testapp testapp.o util.o cache.o  -levent
gcc -std=gnu99 -DHAVE_CONFIG_H -I.     -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT timedrun.o -MD -MP -MF .deps/timedrun.Tpo -c -o timedrun.o timedrun.c
mv -f .deps/timedrun.Tpo .deps/timedrun.Po
gcc -std=gnu99  -m64 -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls   -o timedrun timedrun.o  -levent
make[2]: Leaving directory `/root/repcached'
make[1]: Leaving directory `/root/repcached'
[root@tutorialspots repcached]# make install
make  install-recursive
make[1]: Entering directory `/root/repcached'
Making install in doc
make[2]: Entering directory `/root/repcached/doc'
make  install-am
make[3]: Entering directory `/root/repcached/doc'
make[4]: Entering directory `/root/repcached/doc'
make[4]: Nothing to be done for `install-exec-am'.
test -z "/usr/local/share/man/man1" || /usr/bin/mkdir -p "/usr/local/share/man/man1"
 /usr/bin/install -c -m 644 memcached.1 '/usr/local/share/man/man1'
make[4]: Leaving directory `/root/repcached/doc'
make[3]: Leaving directory `/root/repcached/doc'
make[2]: Leaving directory `/root/repcached/doc'
make[2]: Entering directory `/root/repcached'
make[3]: Entering directory `/root/repcached'
test -z "/usr/local/bin" || /usr/bin/mkdir -p "/usr/local/bin"
  /usr/bin/install -c memcached '/usr/local/bin'
test -z "/usr/local/include/memcached" || /usr/bin/mkdir -p "/usr/local/include/memcached"
 /usr/bin/install -c -m 644 protocol_binary.h '/usr/local/include/memcached'
make[3]: Leaving directory `/root/repcached'
make[2]: Leaving directory `/root/repcached'
make[1]: Leaving directory `/root/repcached'

Done, now you have memcached installed at here: /usr/local/bin/memcached

Method 2:

git clone -b repcached https://github.com/mdounin/memcached.git
cd memcached
./configure --enable-64bit --enable-replication
make
make install

Step 1.3: create file /etc/sysconfig/memcached with content:

PORT="11213"
USER="root"
MAXCONN="4096"
CACHESIZE="4096"
OPTIONS="-P /var/run/memcached.pid -x THIS.IS.MASTER.IP -X masterport"

Use your own master IP and master replication port (default master replication port is 11212)

For server 11.11.11.11 you use:

OPTIONS="-P /var/run/memcached.pid -x 22.22.22.22"

For server 22.22.22.22 you use:

OPTIONS="-P /var/run/memcached.pid -x 11.11.11.11"

Note 1: use PORT different than master replication port
Note 2: The replication port has to be the same on both machines

Step 1.4:create file /usr/lib/systemd/system/memcached.service

[Unit]
Description=Memcached
Before=httpd.service
After=network.target

[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/memcached
ExecStart=/usr/local/bin/memcached -u $USER -p $PORT -m $CACHESIZE -c $MAXCONN $OPTIONS

[Install]
WantedBy=multi-user.target

Step 1.5:

service memcached start

Step 1.6: open port (port replication and port memcached)

iptables -I INPUT -p tcp --dport 11213 -j ACCEPT
iptables -I INPUT -p tcp --dport 11212 -j ACCEPT
service iptables save

or specify ip address of other server

iptables -I INPUT -p tcp -s 22.22.22.22 --dport 11213 -j ACCEPT
iptables -I INPUT -p tcp -s 22.22.22.22 --dport 11212 -j ACCEPT
service iptables save

Step 2: Example of usage:
Server 22.22.22.22:

[root@22.22.22.22 ~]# telnet 127.0.0.1 11213
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
set a 0 0 1
b
STORED
get b
VALUE b 0 1
c
END

Server 11.11.11.11:

[root@11.11.11.11 ~]# telnet 127.0.0.1 11213
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get a
VALUE a 0 1
b
END
set b 0 0 1
c
STORED

More:
1. Build memcached-1.2.8-repcached-2.2.1 for CentOS:
https://github.com/feedforce/repcached

2. Use repcached with docker for Ubuntu 16.04:
https://github.com/herc1/repcached

Leave a Reply