Redis Clusterに関して
Redis Clusterを試しに組んでみたので、その簡単な構築方法。
Redisインストール
Redis Clusterの場合6ノード必要(master : 3台/slave : 3台)になります。
また、Masterを3台のみで構成することも可能です。
[user@localhost]$ sudo su - root [root@localhost]# cd /usr/local/src [root@localhost]# wget http://download.redis.io/releases/redis-3.2.4.tar.gz [root@localhost]# tar -zxvf redis-3.2.4.tar.gz [root@localhost]# mv redis-3.2.4 ../redis [root@localhost]# cd ../redis [root@localhost]# make
Redis設定ファイル
[root@localhost]# cd /usr/local [root@localhost]# mkdir redis_cluster [root@localhost]# cd redis_cluster [root@localhost]# cp ../redis/redis.conf . [root@localhost]# vi redis.conf daemonize yes bind 0.0.0.0 port 7000 cluster-enabled yes cluster-config-file /usr/local/redis_cluster/nodes.conf cluster-node-timeout 5000 appendonly yes
Redis Server起動
[root@localhost]# cd /usr/local/redis_cluster [root@localhost]# /usr/local/redis/src/redis-server ./redis.conf
Redis Clusterの構成はRedis Serverは6ノードでMasterは3ノードでClusterを組みSlaveは3ノードの構成で検証します。
ノード | IP | ポート | 尾行 |
redis01 | 172.20.100.10 | 7000 | Master |
redis02 | 172.20.100.11 | 7001 | Master |
redis03 | 172.20.100.12 | 7002 | Master |
redis04 | 172.20.100.13 | 7003 | Slave |
redis05 | 172.20.100.14 | 7004 | Slave |
redis06 | 172.20.100.15 | 7005 | Slave |
6台のRedis ServerでClusterを構成
[root@localhost]# /usr/local/redis/src/redis-trib.rb create 172.20.100.10:7000 172.20.100.11:7001 172.20.100.12:7002 172.20.100.13:7003 172.20.100.14:7004 172.20.100.15:7005
Redis Cluster確認
[root@localhost]# /usr/local/redis/src/redis-cli -c -p 7000 127.0.0.1:7000> set foo bar -> Redirected to slot [12182] located at 172.20.100.11:7001 OK 172.20.100.11:7001> set hello world -> Redirected to slot [866] located at 172.20.100.10:7000 OK 172.20.100.11:7001> get foo "bar" 172.20.100.11:7001> get hello -> Redirected to slot [866] located at 172.20.100.10:7000 "world" 172.20.100.10:7000>