Skip to content

Instantly share code, notes, and snippets.

@YoshihitoAso
Last active December 11, 2015 19:08
Show Gist options
  • Save YoshihitoAso/4646190 to your computer and use it in GitHub Desktop.
Save YoshihitoAso/4646190 to your computer and use it in GitHub Desktop.
Redis クラスタリング設定(twemproxy)
// install redis (Redis1(10.0.0.10), Redis2(10.0.0.20))
# cd /usr/local/src
# curl -OL http://redis.googlecode.com/files/redis-2.6.4.tar.gz
# tar xzf redis-2.6.4.tar.gz
# cd redis-2.6.4
# make
# make install
# mkdir /etc/redis /var/lib/redis
# cd /usr/local/src/redis-2.6.4/
# cp redis.conf /etc/redis/
# nohup redis-server /etc/redis/redis.conf &
// install twemproxy (Proxy(10.0.0.30))
# cd /usr/local/src
# curl -OL http://redis.googlecode.com/files/redis-2.6.4.tar.gz
# tar xzf redis-2.6.4.tar.gz
# cd redis-2.6.4
# make
# make install
# cd ../
# curl -OL http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
# tar xvzf autoconf-2.69.tar.gz
# cd autoconf-2.69
# ./configure
# make
# make install
# cd ../
# curl -OL http://ftp.gnu.org/gnu/automake/automake-1.12.tar.gz
# tar xvzf automake-1.12.tar.gz
# cd automake-1.12
# ./configure
# make
# make install
# cd ../
# curl -OL http://ftp.jaist.ac.jp/pub/GNU/libtool/libtool-2.4.2.tar.gz
# tar xvzf libtool-2.4.2.tar.gz
# cd libtool-2.4.2
# ./configure
# make
# make install
# cd ../
# curl -OL https://github.com/twitter/twemproxy/archive/v0.2.2.zip
# unzip v0.2.2.zip
# cd twemproxy-0.2.2/
# /usr/local/bin/autoreconf -fvi
# ./configure
# make
# make install
// Setting twemproxy (nuckcracker)
# cd ~/
# vim nuckcracker.yml
redis:
listen: 0.0.0.0:22222
hash: fnv1a_64
distribution: ketama
auto_eject_hosts: true
timeout: 400
redis: true
servers:
- 10.0.0.10:6379:1 twemredis1
- 10.0.0.20:6379:1 twemredis2
// start
# nutcracker -c nutcracker.yml -d
// how to use
-- @twemproxy
# redis-cli
redis 127.0.0.1:22222> set hoge "moge"
OK
redis 127.0.0.1:22222> get hoge
"moge"
redis 127.0.0.1:22222> set hello "world"
OK
redis 127.0.0.1:22222> get hello
"world"
-- @redis1
# redis-cli
redis 127.0.0.1:6379> get hoge
"moge"
redis 127.0.0.1:6379> get hello
(nil)
-- @redis2
# redis-cli
redis 127.0.0.1:6379> get hoge
(nil)
redis 127.0.0.1:6379> get hello
"world"
-- @twemproxy
# redis-cli
redis 127.0.0.1:22222> get hoge
"moge"
redis 127.0.0.1:22222> get hello
"world"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment