{Redis}クラスターの管理

Redis (クラスターモードが無効)クラスターには、常に 1 個のシャード (APICLI では 1 つのノードグループ) のみが含まれます。
Redis シャードには、1 ~ 6 のノードが含まれます。
シャードに複数のノードがある場合、シャードはレプリケーションをサポートします。
この場合、1 つのノードは読み取り/書き込みプライマリノードであり、他のノードは読み取り専用レプリカノードです。

シャード (API/CLI: ノードグループ) は、1 ~ 6 個の Redis ノードで構成される集合です。
Redis エンジンのバージョンが 5.0.6 以上の場合、ノードまたはシャードの制限は、クラスターごとに最大 500 個に増やすことができます。
例えば、83 個のシャード (シャードごとに 1 つのプライマリと 5 レプリカ) と
500 個のシャード (プライマリのみでレプリカなし) の範囲で、500 個のノードクラスターを設定できます。

 

(1)redis-cliユーティリティのセットアップ
sudo amazon-linux-extras install epel -y
sudo yum install gcc jemalloc-devel openssl-devel tcl tcl-devel -y
sudo wget http://download.redis.io/redis-stable.tar.gz
sudo tar xvzf redis-stable.tar.gz
cd redis-stable
sudo make

 

(2)クラスターモードが無効(レプリカなし)のクラスタ

-- 1. クラスターの作成

aws elasticache create-cache-cluster \
--cache-cluster-id redis01 \
--cache-node-type cache.t3.micro \
--engine redis \
--engine-version 6.x \
--num-cache-nodes 1 \
--cache-parameter-group default.redis6.x

-- 2. クラスターの詳細の表示

aws elasticache describe-cache-clusters --cache-cluster-id redis01
aws elasticache describe-cache-clusters --cache-cluster-id redis01 --show-cache-node-info

-- 3. 動作確認

src/redis-cli -h redis01.xxxxxx.0001.apne1.cache.amazonaws.com -c -p 6379

set x XXX
set y YYY
set z ZZZ
get x
get y
get z

-- 4. クラスターの再起動

aws elasticache reboot-cache-cluster \
--cache-cluster-id redis01 \
--cache-node-ids-to-reboot 0001

-- 5. クラスターの削除

aws elasticache delete-cache-cluster \
--cache-cluster-id redis01

 

(3)クラスターモードが無効(レプリカあり)のクラスタ

-- 1. クラスターの作成

aws elasticache create-replication-group \
--replication-group-id redis02 \
--replication-group-description "redis02" \
--num-cache-clusters 2 \
--cache-node-type cache.t3.micro \
--cache-parameter-group default.redis6.x \
--engine redis \
--engine-version 6.x \
--multi-az-enabled

 

-- 2. クラスターの詳細の表示

aws elasticache describe-replication-groups
aws elasticache describe-replication-groups --replication-group-id redis02

aws elasticache describe-cache-clusters --cache-cluster-id redis02-001
aws elasticache describe-cache-clusters --cache-cluster-id redis02-001 --show-cache-node-info

aws elasticache describe-cache-clusters --cache-cluster-id redis02-002
aws elasticache describe-cache-clusters --cache-cluster-id redis02-002 --show-cache-node-info


-- 3. 動作確認

src/redis-cli -h redis02.xxxxxx.ng.0001.apne1.cache.amazonaws.com -c -p 6379
src/redis-cli -h redis02-001.xxxxxx.0001.apne1.cache.amazonaws.com -c -p 6379
src/redis-cli -h redis02-002.xxxxxx.0001.apne1.cache.amazonaws.com -c -p 6379


set x XXX
set y YYY
set z ZZZ
get x
get y
get z


-- 4. クラスターの再起動

aws elasticache reboot-cache-cluster \
--cache-cluster-id redis02-001 \
--cache-node-ids-to-reboot 0001


-- 5. クラスターへのレプリカノードの追加


aws elasticache increase-replica-count \
--replication-group-id redis02 \
--new-replica-count 2 \
--apply-immediately


-- 6. クラスターからのレプリカノードの削除

aws elasticache decrease-replica-count \
--replication-group-id redis02 \
--new-replica-count 1 \
--apply-immediately


-- 7. クラスターの削除

aws elasticache delete-replication-group \
--replication-group-id redis02 \
--no-retain-primary-cluster

 

(4)クラスターモードが有効のクラスタ


-- 1. クラスターの作成

aws elasticache create-replication-group \
--replication-group-id redis03 \
--replication-group-description "redis03" \
--num-node-groups 2 \
--replicas-per-node-group 1 \
--cache-node-type cache.t3.micro \
--cache-parameter-group default.redis6.x.cluster.on \
--engine redis \
--engine-version 6.x \
--multi-az-enabled

 

-- 2. クラスターの詳細の表示

aws elasticache describe-replication-groups
aws elasticache describe-replication-groups --replication-group-id redis03

aws elasticache describe-cache-clusters --cache-cluster-id redis03-0001-001
aws elasticache describe-cache-clusters --cache-cluster-id redis03-0001-001 --show-cache-node-info

aws elasticache describe-cache-clusters --cache-cluster-id redis03-0001-002
aws elasticache describe-cache-clusters --cache-cluster-id redis03-0001-002 --show-cache-node-info

aws elasticache describe-cache-clusters --cache-cluster-id redis03-0002-001
aws elasticache describe-cache-clusters --cache-cluster-id redis03-0002-001 --show-cache-node-info

aws elasticache describe-cache-clusters --cache-cluster-id redis03-0002-002
aws elasticache describe-cache-clusters --cache-cluster-id redis03-0002-002 --show-cache-node-info


-- 3. 動作確認

src/redis-cli -h redis03.xxxxxx.clustercfg.apne1.cache.amazonaws.com -c -p 6379
src/redis-cli -h redis03-0001-001.xxxxxx.0001.apne1.cache.amazonaws.com -c -p 6379
src/redis-cli -h redis03-0001-002.xxxxxx.0001.apne1.cache.amazonaws.com -c -p 6379
src/redis-cli -h redis03-0002-001.xxxxxx.0001.apne1.cache.amazonaws.com -c -p 6379
src/redis-cli -h redis03-0002-002.xxxxxx.0001.apne1.cache.amazonaws.com -c -p 6379


set x XXX
set y YYY
set z ZZZ
get x
get y
get z


host redis03-0001-001.xxxxxx.0001.apne1.cache.amazonaws.com
host redis03-0001-002.xxxxxx.0001.apne1.cache.amazonaws.com
host redis03-0002-001.xxxxxx.0001.apne1.cache.amazonaws.com
host redis03-0002-002.xxxxxx.0001.apne1.cache.amazonaws.com

-- 4. クラスターの再起動

aws elasticache reboot-cache-cluster \
--cache-cluster-id redis03-0001-001 \
--cache-node-ids-to-reboot 0001

An error occurred (InvalidParameterCombination) when calling the RebootCacheCluster operation:
Cannot reboot cache cluster with cluster mode enabled.

※再起動はできない模様


-- 5. クラスターへのレプリカノードの追加

aws elasticache increase-replica-count \
--replication-group-id redis03 \
--new-replica-count 2 \
--apply-immediately


-- 6. クラスターからのレプリカノードの削除

aws elasticache decrease-replica-count \
--replication-group-id redis03 \
--new-replica-count 1 \
--apply-immediately


-- 7. オンラインリシャーディングによるシャードの追加

aws elasticache modify-replication-group-shard-configuration \
--replication-group-id redis03 \
--node-group-count 3 \
--apply-immediately


-- 8. オンラインリシャーディングによるシャードの削除

aws elasticache modify-replication-group-shard-configuration \
--replication-group-id redis03 \
--node-group-count 2 \
--node-groups-to-remove "0003" \
--apply-immediately


-- 9. オンラインシャードの再分散

aws elasticache modify-replication-group-shard-configuration \
--replication-group-id redis03 \
--node-group-count 2 \
--apply-immediately


-- 10. クラスターの削除

aws elasticache delete-replication-group \
--replication-group-id redis03 \
--no-retain-primary-cluster