Twemproxy安裝配置

簡介:

簡單來說,twemproxy是twitter開發的一個redis代理proxy。

通過Twemproxy可以使用多臺服務器來水平擴張redis服務,可以有效的避免單點故障問題。

雖然使用Twemproxy需要更多的硬件資源和在redis性能有一定的損失(twitter測試約20%),

但是能夠提高整個系統的HA也是相當划算的。

Twemproxy可以把數據sharding到多臺服務器的上,每臺服務器存儲着整個數據集的一部分。

因而,當某一臺redis服務器宕機了,那麼也就失去了一部分數據。如果藉助於redis的master-slave replication,

能保證在任何一臺redis不能工作情況下,仍然能夠保證能夠存在一個整個數據集的完全覆蓋,

那麼整個redis  group(或者稱作cluster)仍然能夠正常工作。



安裝配置:

autoconf下載地址:http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz

twemproxy的安裝要求autoconf的版本在2.64以上,否則提示”error: Autoconf version 2.64 or higher is required“。autoconf直接make和make install即可。


twemproxy下載地址:https://codeload.github.com/twitter/twemproxy/zip/master


下載完成後進入twemproxy-master目錄

[root@redis-server twemproxy-master]# autoreconf --install

libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `config'.

libtoolize: copying file `config/ltmain.sh'

libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.

libtoolize: copying file `m4/libtool.m4'

libtoolize: copying file `m4/ltoptions.m4'

libtoolize: copying file `m4/ltsugar.m4'

libtoolize: copying file `m4/ltversion.m4'

libtoolize: copying file `m4/lt~obsolete.m4'

libtoolize: `AC_PROG_RANLIB' is rendered obsolete by `LT_INIT'

configure.ac:36: installing 'config/config.guess'

configure.ac:36: installing 'config/config.sub'

configure.ac:16: installing 'config/install-sh'

configure.ac:16: installing 'config/missing'

src/Makefile.am: installing 'config/depcomp'



[root@redis-server twemproxy-master]# autoconf -f -i -v

autoconf: running /usr/local/bin/autom4te -f --melt -v --language=autoconf --output=configure configure.ac

autom4te: the trace request object is:

autom4te: $VAR1 = bless( [

autom4te:                  '4',

autom4te:                  0,

autom4te:                  [

autom4te:                    '/usr/local/share/autoconf'

autom4te:                  ],

autom4te:                  [

autom4te:                    '/usr/local/share/autoconf/m4sugar/m4sugar.m4',

autom4te:                    '/usr/local/share/autoconf/m4sugar/m4sh.m4',

autom4te:                    '/usr/local/share/autoconf/autoconf/autoconf.m4',

autom4te:                    'aclocal.m4',

autom4te:                    'configure.ac'

autom4te:                  ],

autom4te:                  {

autom4te:                    '_LT_AC_TAGCONFIG' => 1,

autom4te:                    'AM_PROG_F77_C_O' => 1,

autom4te:                    'AC_INIT' => 1,

autom4te:                    'm4_pattern_forbid' => 1,

autom4te:                    '_AM_COND_IF' => 1,

autom4te:                    'AC_CANONICAL_TARGET' => 1,

autom4te:                    'AC_SUBST' => 1,

autom4te:                    'AC_CONFIG_LIBOBJ_DIR' => 1,

autom4te:                    'AC_FC_SRCEXT' => 1,

autom4te:                    'AC_CANONICAL_HOST' => 1,

autom4te:                    'AC_PROG_LIBTOOL' => 1,

autom4te:                    'AM_INIT_AUTOMAKE' => 1,

autom4te:                    'AM_PATH_GUILE' => 1,

autom4te:                    'AC_CONFIG_SUBDIRS' => 1,

autom4te:                    'AM_AUTOMAKE_VERSION' => 1,

autom4te:                    'LT_CONFIG_LTDL_DIR' => 1,

autom4te:                    'AC_REQUIRE_AUX_FILE' => 1,

autom4te:                    'AC_CONFIG_LINKS' => 1,

autom4te:                    'm4_sinclude' => 1,

autom4te:                    'LT_SUPPORTED_TAG' => 1,

autom4te:                    'AM_MAINTAINER_MODE' => 1,

autom4te:                    'AM_NLS' => 1,

autom4te:                    'AC_FC_PP_DEFINE' => 1,

autom4te:                    'AM_GNU_GETTEXT_INTL_SUBDIR' => 1,

autom4te:                    'AM_MAKEFILE_INCLUDE' => 1,

autom4te:                    '_m4_warn' => 1,

autom4te:                    'AM_PROG_CXX_C_O' => 1,

autom4te:                    '_AM_COND_ENDIF' => 1,

autom4te:                    '_AM_MAKEFILE_INCLUDE' => 1,

autom4te:                    'AM_ENABLE_MULTILIB' => 1,

autom4te:                    'AM_SILENT_RULES' => 1,

autom4te:                    'AM_PROG_MOC' => 1,

autom4te:                    'AC_CONFIG_FILES' => 1,

autom4te:                    'include' => 1,

autom4te:                    'LT_INIT' => 1,

autom4te:                    'AM_PROG_AR' => 1,

autom4te:                    'AM_GNU_GETTEXT' => 1,

autom4te:                    'AC_LIBSOURCE' => 1,

autom4te:                    'AM_PROG_FC_C_O' => 1,

autom4te:                    'AC_CANONICAL_BUILD' => 1,

autom4te:                    'AC_FC_FREEFORM' => 1,

autom4te:                    'AH_OUTPUT' => 1,

autom4te:                    'AC_FC_PP_SRCEXT' => 1,

autom4te:                    '_AM_SUBST_NOTMAKE' => 1,

autom4te:                    'AC_CONFIG_AUX_DIR' => 1,

autom4te:                    'sinclude' => 1,

autom4te:                    'AM_PROG_CC_C_O' => 1,

autom4te:                    'm4_pattern_allow' => 1,

autom4te:                    'AM_XGETTEXT_OPTION' => 1,

autom4te:                    'AC_CANONICAL_SYSTEM' => 1,

autom4te:                    'AM_CONDITIONAL' => 1,

autom4te:                    'AC_CONFIG_HEADERS' => 1,

autom4te:                    'AC_DEFINE_TRACE_LITERAL' => 1,

autom4te:                    'AM_POT_TOOLS' => 1,

autom4te:                    'm4_include' => 1,

autom4te:                    '_AM_COND_ELSE' => 1,

autom4te:                    'AC_SUBST_TRACE' => 1

autom4te:                  }

autom4te:                ], 'Autom4te::Request' );

autom4te: running: /usr/local/bin/m4 --nesting-limit=1024 --gnu --include=/usr/local/share/autoconf --debug=aflq --fatal-warning --debugfile=autom4te.cache/traces.4t --trace=AC_CANONICAL_BUILD --trace=AC_CANONICAL_HOST --trace=AC_CANONICAL_SYSTEM --trace=AC_CANONICAL_TARGET --trace=AC_CONFIG_AUX_DIR --trace=AC_CONFIG_FILES --trace=AC_CONFIG_HEADERS --trace=AC_CONFIG_LIBOBJ_DIR --trace=AC_CONFIG_LINKS --trace=AC_CONFIG_SUBDIRS --trace=AC_DEFINE_TRACE_LITERAL --trace=AC_FC_FREEFORM --trace=AC_FC_PP_DEFINE --trace=AC_FC_PP_SRCEXT --trace=AC_FC_SRCEXT --trace=AC_INIT --trace=AC_LIBSOURCE --trace=AC_PROG_LIBTOOL --trace=AC_REQUIRE_AUX_FILE --trace=AC_SUBST --trace=AC_SUBST_TRACE --trace=AH_OUTPUT --trace=AM_AUTOMAKE_VERSION --trace=AM_CONDITIONAL --trace=AM_ENABLE_MULTILIB --trace=AM_GNU_GETTEXT --trace=AM_GNU_GETTEXT_INTL_SUBDIR --trace=AM_INIT_AUTOMAKE --trace=AM_MAINTAINER_MODE --trace=AM_MAKEFILE_INCLUDE --trace=AM_NLS --trace=AM_PATH_GUILE --trace=AM_POT_TOOLS --trace=AM_PROG_AR --trace=AM_PROG_CC_C_O --trace=AM_PROG_CXX_C_O --trace=AM_PROG_F77_C_O --trace=AM_PROG_FC_C_O --trace=AM_PROG_MOC --trace=AM_SILENT_RULES --trace=AM_XGETTEXT_OPTION --trace=LT_CONFIG_LTDL_DIR --trace=LT_INIT --trace=LT_SUPPORTED_TAG --trace=_AM_COND_ELSE --trace=_AM_COND_ENDIF --trace=_AM_COND_IF --trace=_AM_MAKEFILE_INCLUDE --trace=_AM_SUBST_NOTMAKE --trace=_LT_AC_TAGCONFIG --trace=_m4_warn --trace=include --trace=m4_include --trace=m4_pattern_allow --trace=m4_pattern_forbid --trace=m4_sinclude --trace=sinclude /usr/local/share/autoconf/m4sugar/m4sugar.m4 /usr/local/share/autoconf/m4sugar/m4sh.m4 /usr/local/share/autoconf/autoconf/autoconf.m4 aclocal.m4 configure.ac > autom4te.cache/output.4t

autom4te: formatting traces for `/tmp/am4tcWNSQj/warnings': _m4_warn

autom4te: reading /tmp/am4tcWNSQj/warnings

autom4te: creating configure

autom4te: formatting traces for `/tmp/am4tcWNSQj/patterns': m4_pattern_allow, m4_pattern_forbid

autom4te: forbidden tokens: ^_?A[CHUM]_|_AC_|^LIBOBJS$|^_?m4_|^dnl$|^_?AS_|^_?LT_[A-Z_]+$

autom4te: forbidden token : ^LIBOBJS$ => do not use LIBOBJS directly, use AC_LIBOBJ (see section `AC_LIBOBJ vs LIBOBJS'

autom4te: allowed   tokens: ^AS_FLAGS$|^SHELL$|^PATH_SEPARATOR$|^PACKAGE_NAME$|^PACKAGE_TARNAME$|^PACKAGE_VERSION$|^PACKAGE_STRING$|^PACKAGE_BUGREPORT$|^PACKAGE_URL$|^exec_prefix$|^prefix$|^program_transform_name$|^bindir$|^sbindir$|^libexecdir$|^datarootdir$|^datadir$|^sysconfdir$|^sharedstatedir$|^localstatedir$|^includedir$|^oldincludedir$|^docdir$|^infodir$|^htmldir$|^dvidir$|^pdfdir$|^psdir$|^libdir$|^localedir$|^mandir$|^PACKAGE_NAME$|^PACKAGE_TARNAME$|^PACKAGE_VERSION$|^PACKAGE_STRING$|^PACKAGE_BUGREPORT$|^PACKAGE_URL$|^DEFS$|^ECHO_C$|^ECHO_N$|^ECHO_T$|^LIBS$|^build_alias$|^host_alias$|^target_alias$|^AM_[A-Z]+FLAGS$|^INSTALL_PROGRAM$|^INSTALL_SCRIPT$|^INSTALL_DATA$|^am__isrc$|^CYGPATH_W$|^PACKAGE$|^VERSION$|^PACKAGE$|^VERSION$|^ACLOCAL$|^AUTOCONF$|^AUTOMAKE$|^AUTOHEADER$|^MAKEINFO$|^install_sh$|^STRIP$|^INSTALL_STRIP_PROGRAM$|^MKDIR_P$|^mkdir_p$|^AWK$|^SET_MAKE$|^am__leading_dot$|^AMTAR$|^am__tar$|^am__untar$|^AM_V$|^AM_DEFAULT_V$|^AM_DEFAULT_VERBOSITY$|^AM_BACKSLASH$|^NC_VERSION_MAJOR$|^NC_VERSION_MINOR$|^NC_VERSION_PATCH$|^NC_VERSION_STRING$|^AWK$|^CC$|^CFLAGS$|^LDFLAGS$|^LIBS$|^CPPFLAGS$|^CC$|^CC$|^CC$|^CC$|^ac_ct_CC$|^EXEEXT$|^OBJEXT$|^DEPDIR$|^am__include$|^am__quote$|^AMDEP_TRUE$|^AMDEP_FALSE$|^AMDEPBACKSLASH$|^am__nodep$|^CCDEPMODE$|^am__fastdepCC_TRUE$|^am__fastdepCC_FALSE$|^CPP$|^CPPFLAGS$|^CPP$|^CXX$|^CXXFLAGS$|^LDFLAGS$|^LIBS$|^CPPFLAGS$|^CXX$|^ac_ct_CXX$|^CXXDEPMODE$|^am__fastdepCXX_TRUE$|^am__fastdepCXX_FALSE$|^LN_S$|^SET_MAKE$|^RANLIB$|^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$|^LIBTOOL$|^build$|^build_cpu$|^build_vendor$|^build_os$|^host$|^host_cpu$|^host_vendor$|^host_os$|^SED$|^GREP$|^EGREP$|^FGREP$|^GREP$|^LD$|^DUMPBIN$|^ac_ct_DUMPBIN$|^DUMPBIN$|^NM$|^OBJDUMP$|^OBJDUMP$|^DLLTOOL$|^DLLTOOL$|^AR$|^ac_ct_AR$|^STRIP$|^RANLIB$|LT_OBJDIR|^LT_OBJDIR$|^MANIFEST_TOOL$|^DSYMUTIL$|^NMEDIT$|^LIPO$|^OTOOL$|^OTOOL64$|^STDC_HEADERS$|^HAVE_DLFCN_H$|^CXXCPP$|^CPPFLAGS$|^CXXCPP$|^LD$|^int8_t$|^int16_t$|^int32_t$|^int64_t$|^HAVE_UNSIGNED_LONG_LONG_INT$|^HAVE_LONG_LONG_INT$|^HAVE_INTMAX_T$|^intmax_t$|^HAVE_INTPTR_T$|^intptr_t$|^_UINT8_T$|^uint8_t$|^uint16_t$|^_UINT32_T$|^uint32_t$|^_UINT64_T$|^uint64_t$|^HAVE_UINTMAX_T$|^uintmax_t$|^HAVE_UINTPTR_T$|^uintptr_t$|^off_t$|^pid_t$|^size_t$|^ssize_t$|^WORDS_BIGENDIAN$|^HAVE_LITTLE_ENDIAN$|^HAVE__BOOL$|^HAVE_STDBOOL_H$|^HAVE_EXECINFO_H$|^HAVE_BACKTRACE$|^HAVE_SYS_EPOLL_H$|^HAVE_SYS_EVENT_H$|^HAVE_LIBM$|^HAVE_LIBPTHREAD$|^HAVE_VFORK_H$|^HAVE_WORKING_VFORK$|^vfork$|^HAVE_WORKING_FORK$|^HAVE_STDLIB_H$|^HAVE_MALLOC$|^HAVE_MALLOC$|^LIBOBJS$|^malloc$|^HAVE_STDLIB_H$|^HAVE_REALLOC$|^HAVE_REALLOC$|^LIBOBJS$|^realloc$|^HAVE_SOCKET$|^HAVE_EPOLL$|^HAVE_KQUEUE$|^HAVE_EVENT_PORTS$|^OS_LINUX_TRUE$|^OS_LINUX_FALSE$|^OS_BSD_TRUE$|^OS_BSD_FALSE$|^OS_SOLARIS_TRUE$|^OS_SOLARIS_FALSE$|^OS_FREEBSD_TRUE$|^OS_FREEBSD_FALSE$|^HAVE_ASSERT_PANIC$|^HAVE_DEBUG_LOG$|^HAVE_ASSERT_LOG$|^HAVE_DEBUG_LOG$|^HAVE_DEBUG_LOG$|^HAVE_STATS$|^subdirs$|^LIBOBJS$|^LTLIBOBJS$|^am__EXEEXT_TRUE$|^am__EXEEXT_FALSE$



編譯安裝twemproxy

./configure --prefix=/export/Server/twemproxy

報錯

configure: error: cannot find install-sh, install.sh, or shtool in config "."/config

方法:

automake --add-missing


再來:

./configure --prefix=/export/Server/twemproxy

報錯

config.status: error: cannot find input file: `Makefile.in'

方法:

automake --add-missing

automake


再來:

./configure --prefix=/export/Server/twemproxy

成功


最後

make -j 8

make install


添加環境變量

echo "PATH=$PATH:/export/Server/twemproxy/sbin/" >> /etc/profile

source /etc/profile



新建配置文件

創建pid文件目錄

cd /usr/local/twemproxy

mkdir run 


創建proxy配置文件

mkdir sbin/conf

cd /sbin/conf


拷貝配置文件

cp /data/packages/twemproxy-master/conf/nutcracker.yml /usr/local/twemproxy/sbin/conf

然後根據需求修改配置文件


測試配置文件語法正確性

[root@redis-server sbin]# ./nutcracker -t


測試配置文件的時候報錯

nutcracker: configuration file 'conf/nutcracker.yml' syntax is invalid

conf下面的nutcracker.yml文件必須放在twemproxy/sbin/目錄下,否則報上面錯誤

再次測試

[root@redis-server sbin]# ./nutcracker -t

nutcracker: configuration file 'conf/nutcracker.yml' syntax is ok



啓動

./nutcracker -d -c /export/Server/twemproxy/sbin/conf/nutcracker.yml -p /export/Server/twemproxy/run/redisproxy.pid -o /export/Server/twemproxy/run/redisproxy.log



查看日誌

/export/Server/twemproxy/run/redisproxy.log



性能測試

這裏使用redis自帶的redis-benchmark進行簡單的性能測試,測試結果如下:


Set測試:

通過twemproxy測試:

[root@redis-server src]#redis-benchmark -h 10.23.22.240 -p 22121 -c 100 -t set -d 100 -l –q

SET: 38167.94 requests per second

直接對後端redis測試:

[root@redis-server ~]#redis-benchmark -h 10.23.22.241 -p 6379 -c 100 -t set -d 100 -l –q

SET: 53191.49 requests per second

Get測試:

通過twemproxy測試:

[root@redis-server src]#redis-benchmark -h 10.23.22.240 -p 22121 -c 100 -t get -d 100 -l -q

GET: 37453.18 requests per second

直接對後端redis測試:

[root@redis-server ~]#redis-benchmark -h 10.23.22.241 -p 6379 -c 100 -t get -d 100 -l -q

GET: 62111.80 requests per second

查看鍵值分佈:

[root@redis-server ~]#redis-cli info|grep db0

db0:keys=51483,expires=0,avg_ttl=0


[root@redis-server ~]#redis-cli info|grep db0

db0:keys=48525,expires=0,avg_ttl=0

測試結果:以基本的set get命令通過twemproxy性能有所下降;通過twemproxy分佈基本平均。測試數據以業務測試爲準。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章