Redisレプリケーションメモ

最近、NoSQLと分類されるRedisで遊んでいるのですが、レプリケーションをさせてみるメモを残そうかと。

まず、masterとslave用の設定ファイルを作成します。ほとんどデフォルトのままですが、ファイルが衝突しないように変更しているの、とレプリケーション用の設定だけ変えています。

  • redis-master.conf
daemonize no
port 6379
bind 127.0.0.1
loglevel verbose
logfile stdout
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump-master.rdb
dir /home/komamitsu/tmp/redis
appendonly no
appendfsync everysec
vm-enabled no
vm-swap-file /home/komamitsu/tmp/redis-master.swap
vm-max-memory 0
vm-page-size 32
vm-pages 134217728
vm-max-threads 4
glueoutputbuf yes
hash-max-zipmap-entries 64
hash-max-zipmap-value 512
activerehashing yes
  • redis-slave.conf (下記以外はmasterと同じ)
port 6380
dbfilename dump-slave.rdb
slaveof localhost 6379
vm-swap-file /home/komamitsu/tmp/redis-slave.swap

で、両方とも立ち上がると以下のようなログで接続した感じを醸し出します。

  • master
[2781] 09 Feb 23:19:44 - Accepted 127.0.0.1:44619
[2781] 09 Feb 23:19:44 * Slave ask for synchronization
[2781] 09 Feb 23:19:44 * Starting BGSAVE for SYNC
[2781] 09 Feb 23:19:44 * Background saving started by pid 2783
[2783] 09 Feb 23:19:44 * DB saved on disk
[2781] 09 Feb 23:19:44 * Background saving terminated with success
[2781] 09 Feb 23:19:44 * Synchronization with slave succeeded
  • slave
[2782] 09 Feb 23:19:44 * Connecting to MASTER...
[2782] 09 Feb 23:19:44 * Receiving 10 bytes data dump from MASTER
[2782] 09 Feb 23:19:44 * MASTER <-> SLAVE sync succeeded

そしてここで、おもむろにmasterにレコードを追加してみます。

komamitsu@onion:~/tmp/redis$ redis-cli
redis> set 1111 qwert
OK
redis> set 2222 asdfg
OK
redis> set 3333 zxcvb
OK
redis> 

返す刀でslaveをチェック。

komamitsu@onion:~/tmp/redis$ redis-cli -h localhost -p 6380
redis> keys *
1. "3333"
2. "2222"
3. "1111"
redis> 

まぁ非常に簡単にレプリケーションできて嬉しいことは嬉しいですよねぇ。

が、しかし...

ここまではほんの余興... 本当の目的はクラスタリングを試すことにありっ!


と思ったら、クラスタリング機能って2.2からじゃん... Stableな2.0入れてたわ...

と思ったら
http://redis.io/download


Where's Redis Cluster?

Salvatore is already hacking on Redis Cluster. By March 2011 we should have some kind of experimental version, while a Release Candidate is not expected until June 2011.

Probably the first stable version of Redis with clustering support will be called 3.0, but Salvatore will try to merge to 2.2 as an experimental feature if the stability of the system is not affected when the cluster is not used.

とのこと...