Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Redis

การย้ายถ่ายข้อมูลจาก Amazon ElastiCache ไป Redis Enterprise Cloud: โซลูชันง่าย Low-Downtime

เครื่องมือย้ายถ่ายฐานข้อมูลส่วนใหญ่ในปัจจุบันเป็นแบบ offline พวกเขาซับซ้อนและต้องการการแทรกแซงด้วยมือ

หากคุณอยากย้ายข้อมูลจาก Amazon ElastiCache ไป Redis Enterprise Cloud ตัวอย่างเช่น กระบวนการปกติคือการ backup ข้อมูล ElastiCache ไปยัง Amazon S3 bucket จากนั้นนำเข้าข้อมูลโดยใช้ Redis Enterprise Cloud UI กระบวนการนี้อาจต้องการ downtime ที่เจ็บปวดและอาจทำให้เกิดการสูญเสียข้อมูล เทคนิคอื่นๆ ที่มีอยู่รวมถึงการสร้าง point-in-time snapshots ของ Redis server ต้นทางและนำการเปลี่ยนแปลงไปปรับใช้บนเซิร์ฟเวอร์ปลายทางเพื่อให้ทั้งสองเซิร์ฟเวอร์ sync กัน นั่นอาจดูเป็นแนวทางที่ดี แต่มันท้าทายเมื่อคุณต้องดูแล script หลายสิบตัวเพื่อนำกลยุทธ์การย้ายถ่ายไปปฏิบัติ

ดังนั้นเราจึงคิดวิธีแตกต่างออกไป:

แนะนำ RIOT

RIOT เป็นเครื่องมือย้ายถ่ายออนไลน์ open source ที่สร้างโดย Julien Ruaux Solution Architect ที่ Redis RIOT ใช้ client-side replication ด้วยแนวทาง producer/consumer Producer คือการรวมของ key และ value readers ที่มีการเชื่อมต่อกับ ElastiCache Key reader component ระบุคีย์ที่จะถูกจำลองโดยใช้ scan และ keyspace notifications สำหรับแต่ละคีย์ value reader component ทำ DUMP และจัดการ key+bytes ที่ได้ไปยัง consumer (writer) ซึ่งทำ RESTORE บนการเชื่อมต่อ Redis Enterprise

การย้ายถ่ายข้อมูลจาก Amazon ElastiCache ไป Redis Enterprise Cloud: โซลูชันง่าย Low-Downtime

บล็อกโพสต์นี้จะแสดงวิธีการย้ายถ่ายฐานข้อมูลจาก ElastiCache ไป Redis Enterprise Cloud แบบ seamless online

อย่าพลาด: 6 Key Features to Consider When Choosing a DBaaS Provider และ How Redis Enterprise Cloud Meets the Needs of Maturing Enterprise Customers on AWS

ข้อกำหนดก่อนหน้า (Prerequisites):

คุณจะต้องการทรัพยากรน้อยๆ เพื่อใช้เครื่องมือย้ายถ่าย:

  1. การสมัครสมาชิก Redis Enterprise Cloud
  2. Amazon ElastiCache (primary endpoint ในกรณี single-master EC และ configuration endpoint ในกรณี clustered EC: อ้างอิง Finding Connection Endpoints ในเอกสาร ElastiCache เพื่อเรียนรู้เพิ่มเติม)
  3. Amazon EC2 instance บน Linux

การตั้งค่า Amazon EC2 instance

คุณสามารถสร้าง EC2 instance ใหม่หรือใช้ instance ที่มีอยู่ ในตัวอย่างของเรา เราจะสร้าง instance บน Amazon Web Services (AWS) ก่อน สถานการณ์ทั่วไปคือการเข้าถึง ElastiCache cluster จาก Amazon EC2 instance ใน Amazon Virtual Private Cloud (Amazon VPC) เดียวกัน เราใช้ Ubuntu 16.04 LTS สำหรับ setup นี้ แตคุณสามารถเลือก Ubuntu หรือ Debian distribution ที่คุณชอบได้

ใช้ SSH เชื่อมต่อกับ EC2 instance ใหม่นี้จากคอมพิวเตอร์ของคุณ ตามที่แสดงที่นี่:

ssh -i “public key” <AWS EC2 Instance>

ติดตั้ง redis-cli tool บน instance ใหม่นี้โดยรันคำสั่งนี้:

$ sudo apt update # sudo apt install -y redis-tools

ใช้ redis-cli เพื่อยืนยันการเชื่อมต่อกับฐานข้อมูล ElastiCache

Syntax:

$ redis-cli -h <Elasticache Primary Endpoint > -p 6379

Command:

$ sudo redis-cli -h <elasticache primary endpoint> -p 6379

ให้แน่ใจว่าคำสั่งข้างต้นช่วยให้คุณเชื่อมต่อกับฐานข้อมูล Redis remote ได้สำเร็จ

การใช้เครื่องมือย้ายถ่าย RIOT

การย้ายถ่ายข้อมูลจาก Amazon ElastiCache ไป Redis Enterprise Cloud: โซลูชันง่าย Low-Downtime

รันคำสั่งด้านล่างเพื่อตั้งค่าเครื่องมือย้ายถ่าย

ข้อกำหนดก่อนหน้า (Prerequisites):

ติดตั้ง Java: เราแนะนำใช้ OpenJDK 11 หรือใหม่กว่า:

sudo add-apt-repository ppa:openjdk-r/ppa && sudo apt-get update -q && sudo apt install -y openjdk-11-jdk

การติดตั้ง RIOT

แตกไฟล์ package และตรวจสอบว่า RIOT binaries อยู่ในที่ถูกต้อง ตามที่แสดงที่นี่:

wget https://github.com/Redislabs-Solution-Architects/riot/releases/download/v2.0.8/riot-redis-2.0.8.zip unzip riot-redis-2.0.8.zip cd riot-redis-2.0.8/bin/

คุณสามารถตรวจสอบเวอร์ชันของ RIOT โดยรันคำสั่งด้านล่าง:

./riot-redis --version RIOT version "2.0.8" bin/riot-redis --help Usage: riot-redis [OPTIONS] [COMMAND] -q, --quiet Log errors only -d, --debug Log in debug mode (includes normal stacktrace) -i, --info Set log level to info -h, --help Show this help message and exit. -V, --version Print version information and exit. Redis connection options -r, --redis=<uri> Redis connection string (default: redis://localhost:6379) -c, --cluster Connect to a Redis Cluster -m, --metrics Show metrics -p, --pool=<int> Max pool connections (default: 8) Commands: replicate, r Replicate a source Redis database in a target Redis database info, i Display INFO command output latency, l Calculate latency stats ping, p Execute PING command

เมื่อติดตั้ง Java และ RIOT แล้ว เราพร้อมเริ่มกระบวนการย้ายถ่ายด้วยคำสั่งด้านล่าง ซึ่ง replicate ข้อมูลโดยตรงจาก source (ElastiCache) ไป target (Redis Enterprise Cloud)

สุดท้าย ถึงเวลา replicate ข้อมูลจาก ElastiCache ไป Redis Enterprise Cloud โดยรันคำสั่งด้านล่าง:

sudo ./riot-redis -r redis://<source Elasticache endpoint>:6379 replicate -r redis://password@<Redis Enterprise Cloud endpoint>:port --live

ElastiCache อนุญาตให้กำหนดค่าได้ 2 แบบ: clustered และ non-clustered ในตารางด้านล่าง แถวแรกแสดงคำสั่งที่คุณควรทำสำหรับสถานการณ์ non-clustered ในขณะที่แถวที่สองแสดงคำสั่งสำหรับสถานการณ์ clustered พร้อม namespace ฐานข้อมูลเฉพาะ:

การย้ายถ่ายข้อมูลจาก Amazon ElastiCache ไป Redis Enterprise Cloud: โซลูชันง่าย Low-Downtime

ตามที่คุณเห็น ทุกครั้งที่คุณมี ElastiCache แบบ clustered คุณต้องส่ง option –cluster ก่อนระบุ source ElastiCache endpoint

หมายเหตุสำคัญ

  • ทำ user acceptance testing ของการย้ายถ่ายก่อนนำไปใช้ใน production
  • เมื่อการย้ายถ่ายเสร็จสิ้น ให้แน่ใจว่า application traffic ถูก redirect ไปยัง Redis Enterprise endpoint สำเร็จ
  • ดำเนินการย้ายถ่ายในช่วง low traffic เพื่อลดโอกาสสูญเสียข้อมูล

สรุป

หากคุณมองหาเครื่องมือย้ายถ่ายแบบ live ที่เรียบง่ายและใช้งานง่าย ช่วยให้คุณย้ายข้อมูลจาก Amazon ElastiCache ไป Redis Enterprise Cloud โดยไม่มี downtime RIOT เป็นตัวเลือกที่น่าสนใจ

อ้างอิง:

  • RIOT – Redis input/output tools