自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何為雙活Redis Enterprise搭建基于Docker的開發(fā)環(huán)境?

譯文
數(shù)據(jù)庫 其他數(shù)據(jù)庫 開源 Redis
最近我們發(fā)布了一篇關(guān)于如何使用雙活Redis Enterprise來開發(fā)應(yīng)用程序的教程。為了模擬生產(chǎn)環(huán)境,開發(fā)人員或測(cè)試人員需要一種小型化的開發(fā)環(huán)境,很容易用Docker來搭建。我們?cè)诒疚闹薪榻B創(chuàng)建基于Docker的Redis Enterprise集群的步驟,這一切通過命令行來完成。

【51CTO.com快譯】Redis Enterprise這種雙活數(shù)據(jù)庫是地域分布式應(yīng)用程序的理想選擇。其架構(gòu)基于無沖突復(fù)制數(shù)據(jù)類型(CRDT)方面是突破性的學(xué)術(shù)研究。這種方法與其他雙活數(shù)據(jù)庫相比具有許多優(yōu)點(diǎn),包括如下:

1. 為讀寫操作提供本地延遲

2. 為簡(jiǎn)單和復(fù)雜的數(shù)據(jù)類型提供內(nèi)置的沖突解決方案

3. 跨區(qū)域故障切換

4. 簡(jiǎn)化實(shí)施了諸多用例,比如積分榜、分布式緩存、共享會(huì)話和多用戶計(jì)費(fèi)等。

最近我們發(fā)布了一篇關(guān)于如何使用雙活Redis Enterprise來開發(fā)應(yīng)用程序的教程。為了模擬生產(chǎn)環(huán)境,開發(fā)人員或測(cè)試人員需要一種小型化的開發(fā)環(huán)境,很容易用Docker來搭建。

Redis Enterprise在Docker hub上以redislabs/redis的形式存在,我們已經(jīng)在Redis Enterprise說明文檔頁面和docker hub本身上介紹了如何在Docker上搭建Redis Enterprise的詳細(xì)逐步說明。

我們?cè)诒疚闹薪榻B創(chuàng)建基于Docker的Redis Enterprise集群的步驟,這一切通過命令行來完成。下面大體介紹了整個(gè)過程(更多詳細(xì)信息如下):

1. 安裝數(shù)據(jù)庫

1)創(chuàng)建一個(gè)3個(gè)節(jié)點(diǎn)的Redis Enterprise集群,每個(gè)節(jié)點(diǎn)在單獨(dú)的子網(wǎng)上

2)創(chuàng)建基于CRDT的Redis Enterprise數(shù)據(jù)庫

3)連接到三個(gè)不同的實(shí)例

2. 驗(yàn)證安裝的環(huán)境

3. 拆分網(wǎng)絡(luò)

4. 恢復(fù)連接

5. 停止Redis Enterprise

在開始之前,確保你已有一個(gè)bash shell,并為docker進(jìn)程分配了足夠的內(nèi)存。你可以進(jìn)入到Docker -> Preferences -> Advanced來檢查內(nèi)存。

Docker內(nèi)存***項(xiàng)高級(jí)選項(xiàng)卡

圖1:Docker內(nèi)存***項(xiàng)高級(jí)選項(xiàng)卡

1. 安裝數(shù)據(jù)庫

下列腳本在3節(jié)點(diǎn)集群上創(chuàng)建基于CRDT的Redis Enterprise數(shù)據(jù)庫。將其保存在文件中并為其命名,比如“create_3_node_cluster.sh”。然后將模式改成可執(zhí)行(chmod + x create_3_node_cluster.sh),并運(yùn)行腳本([path] /create_3_node_cluster.sh)。 

  1. #!/bin/bash  
  2. Delete the bridge networks if they already exist  
  3. docker network rm network1 2>/dev/null  
  4. docker network rm network2 2>/dev/null  
  5. docker network rm network3 2>/dev/null  
  6. Create new bridge networks  
  7. echo “Creating new subnets…”  
  8. docker network create network1 –subnet=172.18.0.0/16 –gateway=172.18.0.1  
  9. docker network create network2 –subnet=172.19.0.0/16 –gateway=172.19.0.1  
  10. docker network create network3 –subnet=172.20.0.0/16 –gateway=172.20.0.1  
  11. # Start 3 docker containers. Each container is a node in a separate network  
  12. # These commands pull redislabs/redis from the docker hub. Because of the  
  13. # port mapping rules, Redis Enterprise instances are available on ports  
  14. # 12000, 12002, 12004  
  15. echo “”  
  16. echo “Starting Redis Enterprise as Docker containers…”  
  17. docker run -d –cap-add sys_resource -h rp1 –name rp1 -p 8443:8443 -p 9443:9443 -p 12000:12000 –network=network1 –ip=172.18.0.2 redislabs/redis  
  18. docker run -d –cap-add sys_resource -h rp2 –name rp2 -p 8445:8443 -p 9445:9443 -p 12002:12000 –network=network2 –ip=172.19.0.2 redislabs/redis  
  19. docker run -d –cap-add sys_resource -h rp3 –name rp3 -p 8447:8443 -p 9447:9443 -p 12004:12000 –network=network3 –ip=172.20.0.2 redislabs/redis  
  20. Connect the networks  
  21. docker network connect network2 rp1  
  22. docker network connect network3 rp1  
  23. docker network connect network1 rp2  
  24. docker network connect network3 rp2  
  25. docker network connect network1 rp3  
  26. docker network connect network2 rp3  
  27. # Sleep while the nodes start. Increase the sleep time if your nodes take  
  28. # longer than 60 seconds to start  
  29. echo “”  
  30. echo “Waiting for the servers to start…”  
  31. sleep 60  
  32. Create 3 Redis Enterprise clusters – one for each network. You can login to  
  33. # a cluster as https://localhost:8443/ (or 8445, 8447). The user name is  
  34. # r@r.com, password is password. Change the user  
  35. echo “”  
  36. echo “Creating clusters”  
  37. docker exec -it rp1 /opt/redislabs/bin/rladmin cluster create name cluster1.local username r@r.com password test  
  38. docker exec -it rp2 /opt/redislabs/bin/rladmin cluster create name cluster2.local username r@r.com password test  
  39. docker exec -it rp3 /opt/redislabs/bin/rladmin cluster create name cluster3.local username r@r.com password test  
  40. Create the CRDB  
  41. echo “”  
  42. echo “Creating a CRDB”  
  43. docker exec -it rp1 /opt/redislabs/bin/crdb-cli crdb create –name mycrdb –memory-size 512mb –port 12000 –replication false –shards-count 1 –instance fqdn=cluster1.local,username=r@r.com,password=test –instance fqdn=cluster2.local,username=r@r.com,password=test –instance fqdn=cluster3.local,username=r@r.com,password=test 

 

2. 驗(yàn)證安裝的環(huán)境

在端口12000、12002和12004上運(yùn)行redis-cli,驗(yàn)證你可以連接到所有三個(gè)Redis Enterprise端口。如果你將應(yīng)用程序連接到Redis Enterprise,需要應(yīng)用程序的三個(gè)實(shí)例連接到三個(gè)不同的端口。比如: 

  1. $ redis-cli -p 12000  
  2. 127.0.0.1:12000> incr counter  
  3. (integer) 1  
  4. 127.0.0.1:12000> get counter  
  5. “1” 

 

3. 拆分網(wǎng)絡(luò)

拆分網(wǎng)絡(luò)可幫助你在Redis Enterprise副本之間引入“網(wǎng)絡(luò)分區(qū)”。你在設(shè)計(jì)應(yīng)用程序時(shí),必須設(shè)計(jì)成副本斷開連接后可以順暢運(yùn)行。該腳本幫助你隔離三個(gè)副本。將該腳本保存在文件“split_networks.sh”中,并在運(yùn)行之前更改模式,讓它成為可執(zhí)行(chmod +x split_networks.sh)。 

  1. #!/bin/bash  
  2. docker network disconnect network2 rp1  
  3. docker network disconnect network3 rp1  
  4. docker network disconnect network1 rp2  
  5. docker network disconnect network3 rp2  
  6. docker network disconnect network1 rp3  
  7. docker network disconnect network2 rp3 

 

4. 恢復(fù)連接

你運(yùn)行腳本“split_netorks.sh”后,本地副本會(huì)停止與其他副本共享數(shù)據(jù)庫更新?;謴?fù)連接將讓它們能夠交換所有更新,并獲得同樣的最終狀態(tài),這歸功于Redis Enterprise提供了很強(qiáng)的最終一致性。下列腳本恢復(fù)副本之間的網(wǎng)絡(luò)連接。將這保存在文件“restore_networks.sh”中,并更改模式讓它成為可執(zhí)行(chmod +x restore_networks.sh)。 

  1. #!/bin/bash  
  2. docker network connect network2 rp1  
  3. docker network connect network3 rp1  
  4. docker network connect network1 rp2  
  5. docker network connect network3 rp2  
  6. docker network connect network1 rp3  
  7. docker network connect network2 rp3 

 

5. 停止Redis Enterprise

完成開發(fā)和測(cè)試后,只要運(yùn)行下列腳本,就可以終止Redis Enterprise的所有三個(gè)節(jié)點(diǎn)。將該文件保存在文件中,并將文件命名為“stop.sh”,更改模式,讓它成為可執(zhí)行(chmod +x stop.sh)。 

  1. #!/bin/bash  
  2. docker stop rp1 rp2 rp3  
  3. docker rm rp1 rp2 rp3  
  4. docker network rm network1  
  5. docker network rm network2  
  6. docker network rm network3 

 

就是這樣。完成了上述步驟后,現(xiàn)在你有了自己的基于Docker的Redis Enterprise雙活數(shù)據(jù)庫環(huán)境。若有任何問題,歡迎留言交流。

原文標(biāo)題:How to Set Up a Docker-based Development Environment for Active-Active Redis Enterprise,作者:Roshan Kumar 

【51CTO譯稿,合作站點(diǎn)轉(zhuǎn)載請(qǐng)注明原文譯者和出處為51CTO.com】

 

責(zé)任編輯:龐桂玉 來源: 51CTO
相關(guān)推薦

2016-03-02 09:50:09

docker測(cè)試環(huán)境

2015-01-04 09:49:37

PHPDocker開發(fā)環(huán)境

2016-11-03 09:49:04

2022-06-24 10:11:15

DockerLinux

2017-07-11 13:30:12

RedisDockerLinux

2010-02-03 14:37:10

Python 開發(fā)環(huán)境

2009-06-10 16:30:05

基于Eclipse的PWindows

2010-09-07 17:27:54

Carbide.c++Symbian移動(dòng)開發(fā)

2016-09-08 16:04:59

JavaDocker前端

2009-07-03 16:56:37

JSP開發(fā)環(huán)境

2023-04-07 08:28:14

2015-01-05 14:16:16

DockerFig自動(dòng)化容器編排

2015-12-30 13:58:00

DockerGit開發(fā)環(huán)境

2024-10-15 09:10:10

2011-03-15 15:51:12

netfilteriptables

2011-08-31 13:11:53

AndroidPhoneGap

2014-09-04 09:35:17

2021-12-06 15:05:41

鴻蒙HarmonyOS應(yīng)用

2016-08-16 13:44:28

AndroidLinuxADT

2013-07-23 06:11:44

Android開發(fā)學(xué)習(xí)Android開發(fā)環(huán)境Java
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)