Redis叢集方案,Codis安裝測試
1,關於豌豆莢開源的Codis
Codis是豌豆莢使用Go和C語言開發、以代理的方式實現的一個Redis分散式叢集解決方案,且完全相容Twemproxy。Twemproxy對於上一層的應用來說, 連線Codis Proxy(Redis代理服務)和連線原生的Redis伺服器沒有明顯的區別,上一層應用能夠像使用單機的 Redis一樣對待。Codis底層會處理請求的轉發、不停機的資料遷移等工作, 所有底層的一切處理, 對於客戶端來說是透明的。總之,可以簡單的認為後臺連線的是一個記憶體無限大的Redis服務。Codis遵循MIT開源協議釋出,更多關於Codis的資訊請登入其在GitHub的主頁檢視。
Codis 是一個分散式 Redis 解決方案, 對於上層的應用來說, 連線到 Codis Proxy 和連線原生的 Redis Server 沒有明顯的區別 (不支援的命令列表), 上層應用可以像使用單機的 Redis 一樣使用, Codis 底層會處理請求的轉發, 不停機的資料遷移等工作, 所有後邊的一切事情, 對於前面的客戶端來說是透明的, 可以簡單的認為後邊連線的是一個記憶體無限大的 Redis 服務.
Codis 由四部分組成:
Codis Proxy (codis-proxy)
Codis Manager (codis-config)
Codis Redis (codis-server)
ZooKeeper
架構圖:
2,安裝Codis&配置
cd /usr/loca/
wget https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz
tar -zxvf go1.4.2.linux-amd64.tar.gz
設定環境變數,vi /etc/profile
#set go & codis environment
GOROOT=/usr/local/go
PATH=$PATH:$GOROOT/bin
GOPATH=/usr/local/codis
下載codis
cd /usr/local
git clone https ://github.com/wandoulabs/codis.git
#將codis的pkg包拷貝到$GOPATH目錄。
mkdir -p /usr/local/codis/src/github.com/wandoulabs/codis
cp /usr/local/codis/pkg/ /usr/local/codis/cmd/ /usr/local/codis/src/github.com/wandoulabs/codis -R
安裝codis,需要下載依賴包。比較慢,依賴
#安裝編譯工具
yum groupinstall "Development Tools"
#執行編譯測試指令碼,編譯go和reids。
sh /usr/local/codis/bootstrap.sh
go build -o bin/codis-proxy ./cmd/proxy
go build -o bin/codis-config ./cmd/cconfig
make -j4 -C extern/redis-2.8.13/
make[1]: Entering directory `/usr/local/codis/extern/redis-2.8.13'
cd src && make all
make[2]: Entering directory `/usr/local/codis/extern/redis-2.8.13/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-dump redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html
(cd ../deps && make distclean)
make[3]: Entering directory `/usr/local/codis/extern/redis-2.8.13/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
make[3]: Leaving directory `/usr/local/codis/extern/redis-2.8.13/deps'
(rm -f .make-*)
echo STD=-std=c99 -pedantic >> .make-settings
echo WARN=-Wall >> .make-settings
echo OPT=-O2 >> .make-settings
echo MALLOC=jemalloc >> .make-settings
echo CFLAGS= >> .make-settings
echo LDFLAGS= >> .make-settings
echo REDIS_CFLAGS= >> .make-settings
echo REDIS_LDFLAGS= >> .make-settings
echo PREV_FINAL_CFLAGS=-std=c99 -pedantic -Wall -O2 -g -ggdb -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -DUSE_JEMALLOC -I../deps/jemalloc/include >> .make-settings
echo PREV_FINAL_LDFLAGS= -g -ggdb -rdynamic >> .make-settings
(cd ../deps && make hiredis linenoise lua jemalloc)
make[3]: Entering directory `/usr/local/codis/extern/redis-2.8.13/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
(echo "" > .make-cflags)
(echo "" > .make-ldflags)
MAKE hiredis
cd hiredis && make static
MAKE linenoise
cd linenoise && make
make[4]: Entering directory `/usr/local/codis/extern/redis-2.8.13/deps/linenoise'
cc -Wall -Os -g -c linenoise.c
MAKE lua
cd lua/src && make all CFLAGS="-O2 -Wall -DLUA_ANSI " MYLDFLAGS=""
make[4]: Entering directory `/usr/local/codis/extern/redis-2.8.13/deps/hiredis'
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.c
make[4]: Entering directory `/usr/local/codis/extern/redis-2.8.13/deps/lua/src'
cc -O2 -Wall -DLUA_ANSI -c -o lapi.o lapi.c
MAKE jemalloc
cd jemalloc && ./configure --with-jemalloc-prefix=je_ --enable-cc-silence CFLAGS="-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops " LDFLAGS=""
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb hiredis.c
make[4]: Leaving directory `/usr/local/codis/extern/redis-2.8.13/deps/linenoise'
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb sds.c
cc -O2 -Wall -DLUA_ANSI -c -o lcode.o lcode.c
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb async.c
cc -O2 -Wall -DLUA_ANSI -c -o ldebug.o ldebug.c
cc -O2 -Wall -DLUA_ANSI -c -o ldo.o ldo.c
cc -O2 -Wall -DLUA_ANSI -c -o ldump.o ldump.c
ar rcs libhiredis.a net.o hiredis.o sds.o async.o
make[4]: Leaving directory `/usr/local/codis/extern/redis-2.8.13/deps/hiredis'
cc -O2 -Wall -DLUA_ANSI -c -o lfunc.o lfunc.c
cc -O2 -Wall -DLUA_ANSI -c -o lgc.o lgc.c
cc -O2 -Wall -DLUA_ANSI -c -o llex.o llex.c
cc -O2 -Wall -DLUA_ANSI -c -o lmem.o lmem.c
cc -O2 -Wall -DLUA_ANSI -c -o lobject.o lobject.c
checking for xsltproc... /usr/bin/xsltproc
checking for gcc... gcc
cc -O2 -Wall -DLUA_ANSI -c -o lopcodes.o lopcodes.c
cc -O2 -Wall -DLUA_ANSI -c -o lparser.o lparser.c
cc -O2 -Wall -DLUA_ANSI -c -o lstate.o lstate.c
cc -O2 -Wall -DLUA_ANSI -c -o lstring.o lstring.c
checking whether the C compiler works... cc -O2 -Wall -DLUA_ANSI -c -o ltable.o ltable.c
cc -O2 -Wall -DLUA_ANSI -c -o ltm.o ltm.c
cc -O2 -Wall -DLUA_ANSI -c -o lundump.o lundump.c
yes
checking for C compiler default output file name... a.out
checking for suffix of executables... cc -O2 -Wall -DLUA_ANSI -c -o lvm.o lvm.c
cc -O2 -Wall -DLUA_ANSI -c -o lzio.o lzio.c
checking whether we are cross compiling... cc -O2 -Wall -DLUA_ANSI -c -o strbuf.o strbuf.c
cc -O2 -Wall -DLUA_ANSI -c -o lauxlib.o lauxlib.c
no
checking for suffix of object files... cc -O2 -Wall -DLUA_ANSI -c -o lbaselib.o lbaselib.c
o
checking whether we are using the GNU C compiler... cc -O2 -Wall -DLUA_ANSI -c -o ldblib.o ldblib.c
yes
checking whether gcc accepts -g... cc -O2 -Wall -DLUA_ANSI -c -o liolib.o liolib.c
cc -O2 -Wall -DLUA_ANSI -c -o lmathlib.o lmathlib.c
yes
checking for gcc option to accept ISO C89... cc -O2 -Wall -DLUA_ANSI -c -o loslib.o loslib.c
none needed
checking how to run the C preprocessor... cc -O2 -Wall -DLUA_ANSI -c -o ltablib.o ltablib.c
cc -O2 -Wall -DLUA_ANSI -c -o lstrlib.o lstrlib.c
cc -O2 -Wall -DLUA_ANSI -c -o loadlib.o loadlib.c
cc -O2 -Wall -DLUA_ANSI -c -o linit.o linit.c
gcc -E
cc -O2 -Wall -DLUA_ANSI -c -o lua_cjson.o lua_cjson.c
cc -O2 -Wall -DLUA_ANSI -c -o lua_struct.o lua_struct.c
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... cc -O2 -Wall -DLUA_ANSI -c -o lua_cmsgpack.o lua_cmsgpack.c
cc -O2 -Wall -DLUA_ANSI -c -o lua.o lua.c
lua_cmsgpack.c: In function ‘table_is_an_array’:
lua_cmsgpack.c:370:21: warning: variable ‘max’ set but not used [-Wunused-but-set-variable]
long count = 0, max = 0, idx = 0;
^
cc -O2 -Wall -DLUA_ANSI -c -o luac.o luac.c
cc -O2 -Wall -DLUA_ANSI -c -o print.o print.c
ar rcu liblua.a lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o strbuf.o lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o lstrlib.o loadlib.o linit.o lua_cjson.o lua_struct.o lua_cmsgpack.o # DLL needs all object files
ranlib liblua.a
cc -o lua lua.o liblua.a -lm
cc -o luac luac.o print.o liblua.a -lm
yes
make[4]: Leaving directory `/usr/local/codis/extern/redis-2.8.13/deps/lua/src'
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 byte ordering is bigendian... no
checking size of void *... 8
checking size of int... 4
checking size of long... 8
checking size of intmax_t... 8
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking whether pause instruction is compilable... yes
checking whether SSE2 intrinsics is compilable... yes
checking for ar... ar
checking whether __attribute__ syntax is compilable... yes
checking whether compiler supports -fvisibility=hidden... yes
checking whether compiler supports -Werror... yes
checking whether tls_model attribute is compilable... no
checking for a BSD-compatible install... /usr/bin/install -c
checking for ranlib... ranlib
checking for ld... /usr/bin/ld
checking for autoconf... /usr/bin/autoconf
checking for memalign... yes
checking for valloc... yes
checking configured backtracing method... N/A
checking for sbrk... yes
checking whether utrace(2) is compilable... no
checking whether valgrind is compilable... no
checking STATIC_PAGE_SHIFT... 12
checking pthread.h usability... yes
checking pthread.h presence... yes
checking for pthread.h... yes
checking for pthread_create in -lpthread... yes
checking for _malloc_thread_cleanup... no
checking for _pthread_mutex_init_calloc_cb... no
checking for TLS... yes
checking whether a program using ffsl is compilable... yes
checking whether atomic(9) is compilable... no
checking whether Darwin OSAtomic*() is compilable... no
checking whether to force 32-bit __sync_{add,sub}_and_fetch()... no
checking whether to force 64-bit __sync_{add,sub}_and_fetch()... no
checking whether Darwin OSSpin*() is compilable... no
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/html.xsl
config.status: creating doc/manpages.xsl
config.status: creating doc/jemalloc.xml
config.status: creating include/jemalloc/jemalloc_macros.h
config.status: creating include/jemalloc/jemalloc_protos.h
config.status: creating include/jemalloc/internal/jemalloc_internal.h
config.status: creating test/test.sh
config.status: creating test/include/test/jemalloc_test.h
config.status: creating config.stamp
config.status: creating bin/jemalloc.sh
config.status: creating include/jemalloc/jemalloc_defs.h
config.status: creating include/jemalloc/internal/jemalloc_internal_defs.h
config.status: creating test/include/test/jemalloc_test_defs.h
config.status: executing include/jemalloc/internal/private_namespace.h commands
config.status: executing include/jemalloc/internal/private_unnamespace.h commands
config.status: executing include/jemalloc/internal/public_symbols.txt commands
config.status: executing include/jemalloc/internal/public_namespace.h commands
config.status: executing include/jemalloc/internal/public_unnamespace.h commands
config.status: executing include/jemalloc/internal/size_classes.h commands
config.status: executing include/jemalloc/jemalloc_protos_jet.h commands
config.status: executing include/jemalloc/jemalloc_rename.h commands
config.status: executing include/jemalloc/jemalloc_mangle.h commands
config.status: executing include/jemalloc/jemalloc_mangle_jet.h commands
config.status: executing include/jemalloc/jemalloc.h commands
===============================================================================
jemalloc version : 3.6.0-0-g46c0af68bd248b04df75e4f92d5fb804c3d75340
library revision : 1
CC : gcc
CPPFLAGS : -D_GNU_SOURCE -D_REENTRANT
CFLAGS : -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -fvisibility=hidden
LDFLAGS :
EXTRA_LDFLAGS :
LIBS : -lpthread
RPATH_EXTRA :
XSLTPROC : /usr/bin/xsltproc
XSLROOT :
PREFIX : /usr/local
BINDIR : /usr/local/bin
INCLUDEDIR : /usr/local/include
LIBDIR : /usr/local/lib
DATADIR : /usr/local/share
MANDIR : /usr/local/share/man
srcroot :
abs_srcroot : /usr/local/codis/extern/redis-2.8.13/deps/jemalloc/
objroot :
abs_objroot : /usr/local/codis/extern/redis-2.8.13/deps/jemalloc/
JEMALLOC_PREFIX : je_
JEMALLOC_PRIVATE_NAMESPACE
: je_
install_suffix :
autogen : 0
experimental : 1
cc-silence : 1
debug : 0
code-coverage : 0
stats : 1
prof : 0
prof-libunwind : 0
prof-libgcc : 0
prof-gcc : 0
tcache : 1
fill : 1
utrace : 0
valgrind : 0
xmalloc : 0
mremap : 0
munmap : 0
dss : 0
lazy_lock : 0
tls : 1
===============================================================================
cd jemalloc && make CFLAGS="-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops " LDFLAGS="" lib/libjemalloc.a
make[4]: Entering directory `/usr/local/codis/extern/redis-2.8.13/deps/jemalloc'
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/jemalloc.o src/jemalloc.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/arena.o src/arena.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/atomic.o src/atomic.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/base.o src/base.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/bitmap.o src/bitmap.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/chunk.o src/chunk.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/chunk_dss.o src/chunk_dss.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/chunk_mmap.o src/chunk_mmap.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/ckh.o src/ckh.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/ctl.o src/ctl.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/extent.o src/extent.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/hash.o src/hash.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/huge.o src/huge.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/mb.o src/mb.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/mutex.o src/mutex.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/prof.o src/prof.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/quarantine.o src/quarantine.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/rtree.o src/rtree.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/stats.o src/stats.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/tcache.o src/tcache.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/util.o src/util.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/tsd.o src/tsd.c
ar crus lib/libjemalloc.a src/jemalloc.o src/arena.o src/atomic.o src/base.o src/bitmap.o src/chunk.o src/chunk_dss.o src/chunk_mmap.o src/ckh.o src/ctl.o src/extent.o src/hash.o src/huge.o src/mb.o src/mutex.o src/prof.o src/quarantine.o src/rtree.o src/stats.o src/tcache.o src/util.o src/tsd.o
make[4]: Leaving directory `/usr/local/codis/extern/redis-2.8.13/deps/jemalloc'
make[3]: Leaving directory `/usr/local/codis/extern/redis-2.8.13/deps'
CC adlist.o
CC ae.o
CC anet.o
CC dict.o
CC redis.o
CC sds.o
CC zmalloc.o
CC lzf_c.o
CC lzf_d.o
CC pqsort.o
CC zipmap.o
CC sha1.o
CC ziplist.o
CC release.o
CC networking.o
CC util.o
CC object.o
CC db.o
CC replication.o
CC rdb.o
CC t_string.o
CC t_list.o
CC t_set.o
CC t_zset.o
CC t_hash.o
CC config.o
CC aof.o
CC pubsub.o
CC multi.o
CC debug.o
CC sort.o
CC intset.o
CC syncio.o
CC migrate.o
CC endianconv.o
CC slowlog.o
CC scripting.o
CC bio.o
CC rio.o
CC rand.o
CC memtest.o
CC crc64.o
CC crc32.o
CC bitops.o
CC sentinel.o
CC notify.o
CC setproctitle.o
CC hyperloglog.o
CC latency.o
CC sparkline.o
CC slots.o
CC redis-cli.o
CC redis-benchmark.o
CC redis-check-dump.o
CC redis-check-aof.o
LINK redis-benchmark
LINK redis-check-aof
LINK redis-server
LINK redis-check-dump
LINK redis-cli
INSTALL redis-sentinel
Hint: To run 'make test' is a good idea ;)
make[2]: Leaving directory `/usr/local/codis/extern/redis-2.8.13/src'
make[1]: Leaving directory `/usr/local/codis/extern/redis-2.8.13'
go test ./pkg/... ./cmd/... -race
? _/usr/local/codis/pkg/env [no test files]
ok _/usr/local/codis/pkg/models 2.253s
ok _/usr/local/codis/pkg/proxy/cachepool 0.009s
? _/usr/local/codis/pkg/proxy/group [no test files]
ok _/usr/local/codis/pkg/proxy/parser 0.018s
? _/usr/local/codis/pkg/proxy/redisconn [no test files]
? _/usr/local/codis/pkg/proxy/redispool [no test files]
ok _/usr/local/codis/pkg/proxy/router 17.146s
? _/usr/local/codis/pkg/proxy/router/topology [no test files]
ok _/usr/local/codis/pkg/utils 0.012s
ok _/usr/local/codis/cmd/cconfig 0.019s
? _/usr/local/codis/cmd/proxy [no test files]
安裝測試成功,就可以配置了。
編譯後的二進位制檔案在/usr/local/codis/bin目錄下面。
啟動codis之前需要安裝zookeeper。
下載地址:http://zookeeper.apache.org/releases.html#download
安裝目錄/usr/local/zookeeper
mkdir /usr/local/zookeeper/logs
vi /usr/local/zookeeper/conf/zoo.cfg配置檔案
tickTime=2000
clientPort=2181
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/logs
啟動zookeeper
sh /usr/local/zookeeper/bin/zkServer.sh start
啟動Codis服務,之前必須啟動zookeeper,sample目錄有簡單的叢集配置。
startall.sh指令碼會同時將redis啟動。
# sh /usr/local/codis/sample/startall.sh
sleep 3s
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.8.13 (6e3095dc/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6381
| `-._ `._ / _.-' | PID: 1259
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[1259] 06 Mar 09:55:30.852 # Server started, Redis version 2.8.13
[1259] 06 Mar 09:55:30.853 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[1259] 06 Mar 09:55:30.853 * The server is now ready to accept connections on port 6381
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.8.13 (6e3095dc/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6382
| `-._ `._ / _.-' | PID: 1260
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[1260] 06 Mar 09:55:30.846 # Server started, Redis version 2.8.13
[1260] 06 Mar 09:55:30.846 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[1260] 06 Mar 09:55:30.846 * The server is now ready to accept connections on port 6382
add group 1 with a master(localhost:6381), Notice: do not use localhost when in produciton
add group 2 with a master(localhost:6382), Notice: do not use localhost when in produciton
slots initializing...
add group 1 with a master(localhost:6381), Notice: do not use localhost when in produciton
{
"msg": "OK",
"ret": 0
}
add group 2 with a master(localhost:6382), Notice: do not use localhost when in produciton
{
"msg": "OK",
"ret": 0
}
slots initializing...
{
"msg": "OK",
"ret": 0
}
done
set slot ranges to server groups...
{
"msg": "OK",
"ret": 0
}
{
"msg": "OK",
"ret": 0
}
done
shut down proxy_1...
{
"msg": "OK",
"ret": 0
}
done
start new proxy...
done
sleep 3s
nohup: appending output to ‘nohup.out’
2015/03/06 09:55:33 main.go:98: [info] dump file path: /usr/local/codis/bin
2015/03/06 09:55:33 main.go:106: [info] running on 0.0.0.0:19000
2015/03/06 09:55:33 helper.go:312: [info] &{proxyId:proxy_1 productName:test zkAddr:localhost:2181 f:<nil> netTimeout:5 proto:tcp}
2015/03/06 09:55:33 router.go:628: [info] start with configuration: &{proxyId:proxy_1 productName:test zkAddr:localhost:2181 f:<nil> netTimeout:5 proto:tcp}
2015/03/06 09:55:33 router.go:652: [info] proxy_info:{Id:proxy_1 Addr:go:19000 LastEvent: LastEventTs:0 State:offline Description: DebugVarAddr:go:11000}
2015/03/06 09:55:34 router.go:615: [fatal] zk: could not connect to a server
2015/03/06 11:12:51 main.go:98: [info] dump file path: /usr/local/codis/bin
2015/03/06 11:12:51 main.go:106: [info] running on 0.0.0.0:19000
2015/03/06 11:12:51 helper.go:312: [info] &{proxyId:proxy_1 productName:test zkAddr:localhost:2181 f:<nil> netTimeout:5 proto:tcp}
2015/03/06 11:12:51 router.go:628: [info] start with configuration: &{proxyId:proxy_1 productName:test zkAddr:localhost:2181 f:<nil> netTimeout:5 proto:tcp}
2015/03/06 11:12:51 router.go:652: [info] proxy_info:{Id:proxy_1 Addr:go:19000 LastEvent: LastEventTs:0 State:offline Description: DebugVarAddr:go:11000}
2015/03/06 11:12:51 router.go:600: [warning] proxy_1 wait to be online
set proxy_1 online
{
"msg": "OK",
"ret": 0
}
done
啟動之後就可以看到zookeeper裡面的資料了。
[zk: localhost:2181(CONNECTED) 8] ls /zk/codis/db_test
[migrate_manager, fence, migrate_tasks, LOCK, slots, actions, servers, proxy]
3,管理介面顯示
啟動之後就可以訪問admin頁面了。
資料遷移介面
整個桶結構
4,總結
Codis可以完美的解決Redis叢集問題,在目前Redis 3.0版本還不是很穩定的情況下,是非常不錯的解決方案。支援資料擴充套件。
但是並不是所有的redis命令都支援。
如果你使用以下命令:
KEYS, MOVE, OBJECT, RENAME, RENAMENX, SORT, SCAN, BITOP,MSETNX, BLPOP, BRPOP, BRPOPLPUSH, PSUBSCRIBE,PUBLISH, PUNSUBSCRIBE, SUBSCRIBE, UNSUBSCRIBE, DISCARD, EXEC, MULTI, UNWATCH, WATCH, SCRIPT EXISTS, SCRIPT FLUSH, SCRIPT KILL, SCRIPT LOAD, AUTH, ECHO, SELECT, BGREWRITEAOF, BGSAVE, CLIENT KILL, CLIENT LIST, CONFIG GET, CONFIG SET, CONFIG RESETSTAT, DBSIZE, DEBUG OBJECT, DEBUG SEGFAULT, FLUSHALL, FLUSHDB, INFO, LASTSAVE, MONITOR, SAVE, SHUTDOWN, SLAVEOF, SLOWLOG, SYNC, TIME
是無法直接遷移到 Codis 上的. 你需要修改你的程式碼, 用其他的方式實現.