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
    • Helm Chart
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log & Monitor
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
  • 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

  • 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] These are the helpful commands in AWS – awscli AWS - Amazon Web Service
[AWS] Looking into IAM Role and Assume Role in AWS AWS - Amazon Web Service
[Terraform] – Terraform Beginner – Lesson 5: Terraform Provisioners and creating EC2 AWS - Amazon Web Service
[Terraform] – Terraform Beginner – Lesson 2: Working with Terraform. AWS - Amazon Web Service
[AWS] EKS IAM Roles for Service Accounts (IRSA) using Terraform AWS - Amazon Web Service
[Kafka/MSK] Install kafka or MSK on aws through terraform. 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

  • [Smartctl] Instruction check the health disk of Raspberry. January 16, 2023
  • [kubectl/Argocd] How to create a kubectl config file for serviceaccount or from the cluster secret of Argocd January 12, 2023
  • [Helm/Github] Create a public Helm chart repository with GitHub Pages January 8, 2023
  • [AWS] How to increase the disk size of a Windows EC2 machine? January 4, 2023
  • [Redis] ElastiCache-Redis Cross-Region Replication|Global DataStore January 3, 2023

Archives

  • 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
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • Golang
    • Jquery & JavaScript
    • Laravel
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kubernetes
      • Ingress
    • Longhorn – Storage
    • Vault
    • VictoriaMetrics
  • Log & Monitor
    • ELK
      • Kibana
      • Logstash
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2023 NimTechnology.