Skip to content

Instantly share code, notes, and snippets.

@SofijaErkin
Forked from ochim/mac-redis-cluster.md
Created December 8, 2021 06:36
Show Gist options
  • Save SofijaErkin/6b9d63742be9e926bc5ee67c95d9b04b to your computer and use it in GitHub Desktop.
Save SofijaErkin/6b9d63742be9e926bc5ee67c95d9b04b to your computer and use it in GitHub Desktop.
Mac OS X で Redis Clusterを組む

開発環境

  • Mac:10.12.6
  • redis:4.0.0
  • ruby:2.0.0p648

1サーバで3台のRedis Clusterを作る(最低3台かららしい)

1.ディレクトリの用意

$ mkdir ~/cluster-test
$ cd ~/cluster-test
$ mkdir 700{0,1,2}

2.最小構成の設定ファイルを用意する

$ cd 7000
$ vim redis.conf
port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes 

3.各サーバの起動

terminal A
$ cd 7000
$ redis-server ./redis.conf
terminal B
$ cd 7001
$ redis-server ./redis.conf
terminal C
$ cd 7002
$ redis-server ./redis.conf

4.redisのソースを任意のディレクトリにダウンロード http://download.redis.io からLatest stable versionの圧縮ファイルをダウンロードして任意のディレクトリに展開する

$ cd 
$ tar zvxf redis.tar

5.gemのredisをインストール

$ sudo gem install redis -v 3.3.3 
(ruby2.0.0なのでversion3.3.3にする)

6.クラスタリング

$ cd ~/redis/src/
$ ./redis-trib.rb create 127.0.0.1:7000 127.0.0.1:7001  127.0.0.1:7002
  • Can I set the above configuration? と聞かれるので yes を入力します
  • [OK] All nodes agree about slots configuration. となれば Cluster の構築は完了です

動作確認

$ redis-cli -c -p 7000

Redis Clusterをredis-commanderで扱うにはどうすれば?(他のツールでもいいけど)

参考URL

追記

上記で展開した、redisのソースにRedis Clusterを作るスクリプトがあるので、それを使うと簡単。 utils/create-clusterディレクトリにcreate-clusterというスクリプトがある。 使い方は同ディレクトリのreadmeを参照する。

開始するとき
$ ./create-cluster start
$ ./create-cluster create
停止するとき
$ ./create-cluster stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment