您好,登錄后才能下訂單哦!
簡介:
簡單來說,twemproxy是twitter開發(fā)的一個(gè)redis代理proxy。
通過Twemproxy可以使用多臺服務(wù)器來水平擴(kuò)張redis服務(wù),可以有效的避免單點(diǎn)故障問題。
雖然使用Twemproxy需要更多的硬件資源和在redis性能有一定的損失(twitter測試約20%),
但是能夠提高整個(gè)系統(tǒng)的HA也是相當(dāng)劃算的。
Twemproxy可以把數(shù)據(jù)sharding到多臺服務(wù)器的上,每臺服務(wù)器存儲著整個(gè)數(shù)據(jù)集的一部分。
因而,當(dāng)某一臺redis服務(wù)器宕機(jī)了,那么也就失去了一部分?jǐn)?shù)據(jù)。如果借助于redis的master-slave replication,
能保證在任何一臺redis不能工作情況下,仍然能夠保證能夠存在一個(gè)整個(gè)數(shù)據(jù)集的完全覆蓋,
那么整個(gè)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
下載完成后進(jìn)入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
報(bào)錯
configure: error: cannot find install-sh, install.sh, or shtool in config "."/config
方法:
automake --add-missing
再來:
./configure --prefix=/export/Server/twemproxy
報(bào)錯
config.status: error: cannot find input file: `Makefile.in'
方法:
automake --add-missing
automake
再來:
./configure --prefix=/export/Server/twemproxy
成功
最后
make -j 8
make install
添加環(huán)境變量
echo "PATH=$PATH:/export/Server/twemproxy/sbin/" >> /etc/profile
source /etc/profile
新建配置文件
創(chuàng)建pid文件目錄
cd /usr/local/twemproxy
mkdir run
創(chuàng)建proxy配置文件
mkdir sbin/conf
cd /sbin/conf
拷貝配置文件
cp /data/packages/twemproxy-master/conf/nutcracker.yml /usr/local/twemproxy/sbin/conf
然后根據(jù)需求修改配置文件
測試配置文件語法正確性
[root@redis-server sbin]# ./nutcracker -t
測試配置文件的時(shí)候報(bào)錯
nutcracker: configuration file 'conf/nutcracker.yml' syntax is invalid
conf下面的nutcracker.yml文件必須放在twemproxy/sbin/目錄下,否則報(bào)上面錯誤
再次測試
[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進(jìn)行簡單的性能測試,測試結(jié)果如下:
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
測試結(jié)果:以基本的set get命令通過twemproxy性能有所下降;通過twemproxy分布基本平均。測試數(shù)據(jù)以業(yè)務(wù)測試為準(zhǔn)。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。