Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Redis] ElastiCache-Redis Cross-Region Replication|Global DataStore

Posted on January 3, 2023January 4, 2023 By nim No Comments on [Redis] ElastiCache-Redis Cross-Region Replication|Global DataStore

Contents

Toggle
  • 1) Introduce global datastore grading to Elasticache(Redis)
  • 2) Action Redis and Global Datastore via UI console of AWS
    • 2.1) Requirement.
  • 3) Provisioning Elasticache (Redis) and Global Datastore by Terraform.
    • 3.1) Create both Redis Primary and Global Datastore.
      • 3.1.1) Create Global Datastore for the existing Redis.
    • 3.2) Create Redis secondary based on Global Datastore.
  • Recheck – SET data to primary and GET data from secondary
  • Using a module to define and set up easily

1) Introduce global datastore grading to Elasticache(Redis)

Chúng ta có thể sử dụng Global Datastore cho Redis Feature.

Để dễ hiều về Global Datastore bạn sẽ cần nhớ câu: Write Local Read Global
==> Bạn write redis primary và bạn có thể đọc data đó ở bất kỳ redis secondary trên các region khác.

Dưới dây là PDF mình sưu tầm được.

Session-1-ElastiCache-DeepDive_v2_rev

2) Action Redis and Global Datastore via UI console of AWS

Bạn có thể sem video.

2.1) Requirement.

Đây là 1 số yêu cầu nho nhỏ khi apply global datastores for Redis.

To use Global Datastores, use Redis engine version 5.0.6 or higher and R5, R6g, R6gd, M5 or M6g node types.
https://docs.amazonaws.cn/en_us/AmazonElastiCache/latest/red-ug/Redis-Global-Datastores-Getting-Started.html

https://github.com/hashicorp/terraform-provider-aws/issues/18075

3) Provisioning Elasticache (Redis) and Global Datastore by Terraform.

3.1) Create both Redis Primary and Global Datastore.

Đầu tiên bạn sẽ tạo redis với vai trò là primary, sau đó create Global Datastore tiếp là add redis primary vào GD.

# Terraform Remote State Datasource - Remote Backend AWS S3
data "terraform_remote_state" "vpc" {
  backend = "s3"
  config = {
    bucket = "terraform-on-aws-eks-nim"
    key    = "dev/vpc-redis-2/terraform.tfstate"
    region = var.aws_region
  }
}

module "elasticache" {
  source  = "mrnim94/elasticache/aws"
  version = "1.1.12"

  aws_region = var.aws_region
  business_divsion = "nimtechnology"
  environment = "dev"
  num_nodes = "2"
  elasticache_subnet_group_name = data.terraform_remote_state.vpc.outputs.elasticache_subnet_group_name
  engine_version = "5.0.6"
  family = "redis5.0"
  instance_type = "cache.t2.micro"
  #instance_type = "cache.m5.large"
  vpc_id = data.terraform_remote_state.vpc.outputs.vpc_id
  global_datastore = false
}

output "global_replication_group_id" {
  description = "The suffix name of a Global Datastore"
  value       = module.elasticache.global_replication_group_id
}
redis sẽ được tạo với role: primary
Tiếp đến terraform sẽ tạo global datastore và bạn để ý sẽ có ký tự random ở đầu Global Datastore name

Có 1 phần bạn cần chú ý là:
trong module sẽ tạo 1 parameter group là cache-params và gắn vào redis primary

Tiếp đến module sẽ tạo parameter group mới “global-datastore-redis-nimtechnology-dev-primaryxeum” bằng cách copy cache-params

Sau đó module sẽ gắn “global-datastore-redis-nimtechnology-dev-primaryxeum” vào redis-primary và global-datastore

3.1.1) Create Global Datastore for the existing Redis.

Error: creating ElastiCache Global Replication Group (xxx-xxx-xxx): InvalidParameterValue: Global replication group is not supported for the node type.

Nếu bạn gặp lỗi này thì cần change type của redis.

Giờ redis đã được upgrade type.
variable "aws_region" {
  description = "Region in which AWS Resources to be created"
  type = string
  default = "us-east-2"
}

provider "aws" {
  region = "us-east-1"
  alias = "redis-primary"
}

#create global datastore.
resource "aws_elasticache_global_replication_group" "global_datastore" {
  provider = aws.redis-primary

  global_replication_group_id_suffix = "global-datastore-nim"
  primary_replication_group_id       = "redis-nimtechnology-dev"
}

3.2) Create Redis secondary based on Global Datastore.

Ở các bước trên chúng ta đã có redis primary và global datastore.
Giờ chúng ta tạo redis secondary

variable "aws_region" {
  description = "Region in which AWS Resources to be created"
  type = string
  default = "us-east-2"
}

# Terraform Remote State Datasource - Remote Backend AWS S3
data "terraform_remote_state" "vpc" {
  backend = "s3"
  config = {
    bucket = "terraform-on-aws-eks-nim"
    key    = "dev/vpc-redis-3/terraform.tfstate"
    region = "us-east-1" 
  }
}

module "elasticache-secondary-on-global-store" {
  source  = "mrnim94/elasticache-secondary-on-global-store/aws"
  version = "0.0.9"

  aws_region = var.aws_region
  business_divsion = "nimtechnology"
  elasticache_subnet_group_name = data.terraform_remote_state.vpc.outputs.elasticache_subnet_group_name
  environment = "dev"
  family = "redis5.0"
  global_replication_group_id = "ldgnf-redis-nimtechnology-dev"
  num_nodes = "2"
  vpc_id = data.terraform_remote_state.vpc.outputs.vpc_id
}

Recheck – SET data to primary and GET data from secondary

Using a module to define and set up easily

Vâng nim đã biệt module ở linh dưới bạn có thể tham khảo:

https://registry.terraform.io/modules/mrnim94/elasticache-secondary-on-global-datastore/aws/latest

AWS - Amazon Web Service

Post navigation

Previous Post: [Phi&P] Leadershift Certificate.
Next Post: [AWS] How to increase the disk size of a Windows EC2 machine?

More Related Articles

[AWS] Creating AWS Certificate Manager (ACM) AWS - Amazon Web Service
[AWS] Pull images from ECR AWS - Amazon Web Service
[AWS] Login and get secret/token/credential of ECR AWS - Amazon Web Service
[Terraform] – Terraform Beginner – Lesson 8: Terraform Functions and Conditional Expressions AWS - Amazon Web Service
[AWS] Looking into IAM Role and Assume Role in AWS AWS - Amazon Web Service
[AWS] Encrypting your data easily via KMS on AWS AWS - Amazon Web Service

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Azure] The subscription is not registered to use namespace ‘Microsoft.ContainerService’ May 8, 2025
  • [Azure] Insufficient regional vcpu quota left May 8, 2025
  • [WordPress] How to add a Dynamic watermark on WordPress. May 6, 2025
  • [vnet/Azure] VNet provisioning via Terraform. April 28, 2025
  • [tracetcp] How to perform a tracert command using a specific port. April 3, 2025

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.