MathJax

MathJax-2

MathJax-3

Google Code Prettify

置頂入手筆記

EnterproseDB Quickstart — 快速入門筆記

由於考慮採用 EnterpriseDB 或是直接用 PostgreSQL 的人,通常需要一些入手的資料。這邊紀錄便提供相關快速上手的簡單筆記 ~ 這篇筆記以 資料庫安裝完畢後的快速使用 為目標,基本紀錄登入使用的範例:

2018年10月16日 星期二

EDB 的 Postgres 企業版的 Docker 容器 v2.3 簡易試用筆記

近日 PostgreSQL 的企業版服務公司 EnterpriseDB 提供了其企業版產品的 Docker 容器服務。只要是 Docker Container 引擎為基礎的容器平台(Docker CE,Docker EE 或其他像 Red Hat OpenShift 平台等)都可以在認證後登入 EDB 提供的 Docker Registry(訂閱期間的用戶都可以~)去拉資料庫的 Image。

這裡簡單紀錄一下 Docker CE 裡面對 EDB Container Registry v2.3 的功能體驗筆記。

首先,EDB 服務的訂閱帳戶登入網站,到相關頁面 EDB Postgres Containers | EnterpriseDB 進行帳號密碼註冊。過一陣子,查看相關的信箱,就會收到帳號密碼了。

然後用這組帳號密碼登入 EDB 的 Docker Image Registry:
bash-4.2$ docker login https://containers.enterprisedb.com/
Username: 你的帳號 
Password: 如字面上中翻英的意思~
WARNING! Your password will be stored unencrypted in /home/aaa/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
bash-4.2$ 

登入成功,就可以開始拉 Docker Image。這邊 EDB 提供了三類型的 Image
  1. 企業版資料庫,內含 EFM HA Agent
  2. 對企業版語法認得的 pgPool
  3. 備份管理工具 BART
  4. 監控平台 PEM Server

接著,就是 docker pull 把 image 拉下來:這邊只測試簡單的,所以只拉一個 Image,所有支援的 Image 清單可參考手冊
bash-4.2$ docker pull containers.enterprisedb.com/edb/edb-as:v10
v10: Pulling from edb/edb-as
256b176beaff: Pulling fs layer 
b1f1efdf6678: Pulling fs layer 
045157d53b2e: Pulling fs layer 
ac15b3f96e6e: Pulling fs layer 
4242e1cdb801: Pulling fs layer 
bbe9f536f137: Pulling fs layer 
167e6e21e8d3: Pulling fs layer 
d95b33c8b0ba: Pulling fs layer 
e12989f503a7: Pulling fs layer 
6e62407fe542: Pulling fs layer 
117b5e7df0f6: Pulling fs layer 
e51c1cd3b9b2: Pulling fs layer 
8d9d93d358ff: Pulling fs layer 
17983be5ec92: Pulling fs layer 
8824746cdabc: Pulling fs layer 
42d564ff6177: Pulling fs layer 
4701f05b083a: Pulling fs layer 
527dd7dafc1d: Pulling fs layer 
13c85b76e6e3: Pulling fs layer 
c857e7750b30: Pulling fs layer 
341813a728d3: Pulling fs layer 
d00bba2c49c3: Pulling fs layer 
cf6a82434979: Pulling fs layer 
4a9b34daebad: Pulling fs layer 
f76bc3cbc33c: Pulling fs layer 
7b8ba7272eaa: Pulling fs layer 
fbc8f2a23596: Pulling fs layer 
8e6a78fab360: Pull complete 
157bb86ef8cb: Pull complete 
d5604e1727cf: Pull complete 
6cf0326321af: Pull complete 
4ddbe07f2b97: Pull complete 
971097004b6f: Pull complete 
8cb0053bef12: Pull complete 
9d116d00cc1b: Pull complete 
6a6df4b49705: Pull complete 
ed5dc2ba48f8: Pull complete 
42955ccdf244: Pull complete 
747559c35adf: Pull complete 
013f2d2f4db0: Pull complete 
0e86b177e06c: Pull complete 
6c25b4cff961: Pull complete 
61e860601818: Pull complete 
33f72abf232b: Pull complete 
6a9ea5f39a4d: Pull complete 
df7b6c59a003: Pull complete 
5d738b763e04: Pull complete 
adbffa6191bc: Pull complete 
e56883ef558b: Pull complete 
c1b6ea0543d1: Pull complete 
acda239d35df: Pull complete 
15666557e93f: Pull complete 
686a65b423cb: Pull complete 
25fd1fc1d9bf: Pull complete 
Digest: sha256:5d5be8237148717431b011af988a09e4f97d71a4222af87ae1a35aac92613dac
Status: Downloaded newer image for containers.enterprisedb.com/edb/edb-as:v10
bash-4.2$ docker image ls
REPOSITORY                               TAG                 IMAGE ID            CREATED             SIZE
containers.enterprisedb.com/edb/edb-as   v10                 1d118c96529b        2 weeks ago         1.8GB
bash-4.2$ 

由於其他功能比較需要 K8S 的設置,所以這邊先測試 DB HA 的功能就好(此刻的我沒需求也沒動力去搞 K8S。。。)~以下就手動開 1 Master,2 Standby 的架構
先準備一個 Network 物件
bash-4.2$ docker network create --subnet=172.18.0.0/16 efm123
79ca0b786609dc7e389e2da5bff5eacb4f687b2030ad6d4927484bed7ace4452
bash-4.2$ 

首先是 Master DB
bash-4.2$ sudo mkdir -p /var/lib/edb/as10/master
bash-4.2$ sudo chmod -R 777 /var/lib/edb/as10/master
bash-4.2$ docker run \
-e DATABASE_NAME="edb" \
-e PGPORT=5444 \
-e DATABASE_USER="enterprisedb" \
-e DATABASE_USER_PASSWORD="edb" \
-e ENTERPRISEDB_PASSWORD="edb" \
-e LOCALEPARAMETER="en_US" \
-e CLEANUP_SCHEDULE="0:0:*:*:*" \
-e EFM_EMAIL="email@address.com" \
-e ACCEPT_EULA=Yes \
-e REPL_USER="repuser" \
-e REPL_PASSWORD="edb" \
--net efm123 \
--ip 172.18.0.22 \
--name "efm1" \
-v /var/lib/edb/as10/master:/edbvolume \
-d containers.enterprisedb.com/edb/edb-as:v10
a928cb00726dde777d2fea8d9a246ebe7d7a1609b248fbe60d4f33d55fb5af44
bash-4.2$ 
bash-4.2$ docker container ls
CONTAINER ID        IMAGE                                        COMMAND              CREATED             STATUS              PORTS                   NAMES
a928cb00726d        containers.enterprisedb.com/edb/edb-as:v10   "./entrypoint.sh "   12 seconds ago      Up 11 seconds       25/tcp, 5430-5431/tcp   efm1
bash-4.2$ 
bash-4.2$ docker exec -it efm1 bash
[enterprisedb@a928cb00726d ~]$ efm cluster-status edb
Cluster Status: edb

        Agent Type  Address              Agent  DB       VIP
        -----------------------------------------------------------------------
        Master      172.18.0.22          UP     UP        

Allowed node host list:
        172.18.0.22

Membership coordinator: 172.18.0.22

Standby priority host list:
        (List is empty.)

Promote Status:

        DB Type     Address              XLog Loc         Info
        --------------------------------------------------------------
        Master      172.18.0.22          0/30484A8        

        No standby databases were found.
[enterprisedb@a928cb00726d ~]$

接著是第一個 Standby DB:要追隨 efm1 的 Master DB
bash-4.2$ sudo mkdir -p /var/lib/edb/as10/stdby1
bash-4.2$ sudo chmod -R 777 /var/lib/edb/as10/stdby1
bash-4.2$ docker run \
-e DATABASE_NAME="edb" \
-e PGPORT=5444 \
-e DATABASE_USER="enterprisedb" \
-e DATABASE_USER_PASSWORD="edb" \
-e ENTERPRISEDB_PASSWORD="edb" \
-e REPL_USER="repuser" \
-e REPL_PASSWORD="edb" \
-e LOCALEPARAMETER="en_US" \
-e CLEANUP_SCHEDULE="0:0:*:*:*" \
-e EFM_EMAIL="email@address.com" \
-e ACCEPT_EULA=Yes \
-e MASTER_HOST="`sudo docker inspect --format '{{.NetworkSettings.Networks.efm123.IPAddress }}' efm1`" \
-e MASTER_PORT=5444 \
--net efm123 \
--ip 172.18.0.23 \
--name "efm2" \
-v /var/lib/edb/as10/stdby1:/edbvolume \
-d containers.enterprisedb.com/edb/edb-as:v10
7dcedf9f991bd0780e8cfd1d2c2f17b0529ab7adf079a5c35aafa479930e0963
bash-4.2$ 
bash-4.2$ docker container ls
CONTAINER ID        IMAGE                                        COMMAND              CREATED             STATUS              PORTS                   NAMES
7dcedf9f991b        containers.enterprisedb.com/edb/edb-as:v10   "./entrypoint.sh "   30 seconds ago      Up 28 seconds       25/tcp, 5430-5431/tcp   efm2
a928cb00726d        containers.enterprisedb.com/edb/edb-as:v10   "./entrypoint.sh "   2 minutes ago       Up 2 minutes        25/tcp, 5430-5431/tcp   efm1
bash-4.2$ 
bash-4.2$ docker exec -it efm1 bash
[enterprisedb@a928cb00726d ~]$ efm cluster-status edb
Cluster Status: edb

        Agent Type  Address              Agent  DB       VIP
        -----------------------------------------------------------------------
        Master      172.18.0.22          UP     UP        
        Standby     172.18.0.23          UP     UP        

Allowed node host list:
        172.18.0.22 172.18.0.23

Membership coordinator: 172.18.0.22

Standby priority host list:
        172.18.0.23

Promote Status:

        DB Type     Address              XLog Loc         Info
        --------------------------------------------------------------
        Master      172.18.0.22          0/5000060        
        Standby     172.18.0.23          0/5000060        

        Standby database(s) in sync with master. It is safe to promote.
[enterprisedb@a928cb00726d ~]$ 

接著是第二個 Standby DB:一樣要追隨 efm1 的 Master DB
bash-4.2$ sudo mkdir -p /var/lib/edb/as10/stdby2
bash-4.2$ sudo chmod -R 777 /var/lib/edb/as10/stdby2
bash-4.2$ docker run \
-e DATABASE_NAME="edb" \
-e PGPORT=5444 \
-e DATABASE_USER="enterprisedb" \
-e DATABASE_USER_PASSWORD="edb" \
-e ENTERPRISEDB_PASSWORD="edb" \
-e REPL_USER="repuser" \
-e REPL_PASSWORD="edb" \
-e LOCALEPARAMETER="en_US" \
-e CLEANUP_SCHEDULE="0:0:*:*:*" \
-e EFM_EMAIL="email@address.com" \
-e ACCEPT_EULA=Yes \
-e MASTER_HOST="`sudo docker inspect --format '{{.NetworkSettings.Networks.efm123.IPAddress }}' efm1`" \
-e MASTER_PORT=5444 \
--net efm123 \
--ip 172.18.0.24 \
--name "efm3" \
-v /var/lib/edb/as10/stdby2:/edbvolume \
-d containers.enterprisedb.com/edb/edb-as:v10
8b34ad7a566a9fd706de50a9eaba6af7b448567f9fa323e20398d40ff6c76176
bash-4.2$ 
bash-4.2$ docker container ls
CONTAINER ID        IMAGE                                        COMMAND              CREATED             STATUS              PORTS                   NAMES
8b34ad7a566a        containers.enterprisedb.com/edb/edb-as:v10   "./entrypoint.sh "   19 seconds ago      Up 18 seconds       25/tcp, 5430-5431/tcp   efm3
7dcedf9f991b        containers.enterprisedb.com/edb/edb-as:v10   "./entrypoint.sh "   2 minutes ago       Up 2 minutes        25/tcp, 5430-5431/tcp   efm2
a928cb00726d        containers.enterprisedb.com/edb/edb-as:v10   "./entrypoint.sh "   4 minutes ago       Up 4 minutes        25/tcp, 5430-5431/tcp   efm1
bash-4.2$ 

然後檢視一下最後的 EFM 狀態
bash-4.2$ docker exec -it efm1 efm cluster-status edb
Cluster Status: edb

        Agent Type  Address              Agent  DB       VIP
        -----------------------------------------------------------------------
        Master      172.18.0.22          UP     UP        
        Standby     172.18.0.23          UP     UP        
        Standby     172.18.0.24          UP     UP        

Allowed node host list:
        172.18.0.22 172.18.0.23 172.18.0.24

Membership coordinator: 172.18.0.22

Standby priority host list:
        172.18.0.23 172.18.0.24

Promote Status:

        DB Type     Address              XLog Loc         Info
        --------------------------------------------------------------
        Master      172.18.0.22          0/7000060        
        Standby     172.18.0.24          0/7000060        
        Standby     172.18.0.23          0/7000060        

        Standby database(s) in sync with master. It is safe to promote.
bash-4.2$ 

弄的太順,手滑不小心多加一個:因為很快就建好了~
bash-4.2$ sudo mkdir -p /var/lib/edb/as10/stdby3
bash-4.2$ sudo chmod -R 777 /var/lib/edb/as10/stdby3
bash-4.2$ docker run -e DATABASE_NAME="edb" -e PGPORT=5444 -e DATABASE_USER="enterprisedb" -e DATABASE_USER_PASSWORD="edb" -e ENTERPRISEDB_PASSWORD="edb" -e REPL_USER="repuser" -e REPL_PASSWORD="edb" -e LOCALEPARAMETER="en_US" -e CLEANUP_SCHEDULE="0:0:*:*:*" -e EFM_EMAIL="email@address.com" -e ACCEPT_EULA=Yes -e MASTER_HOST="`sudo docker inspect --format '{{.NetworkSettings.Networks.efm123.IPAddress }}' efm1`" -e MASTER_PORT=5444 --net efm123 --ip 172.18.0.25 --name "efm4" -v /var/lib/edb/as10/stdby3:/edbvolume -d containers.enterprisedb.com/edb/edb-as:v10
77224de73f44bd024f1827169a8860c0189cae9ab42204836201eea04bbcc250
bash-4.2$ 

然後,登出 Registry~通常正式環境不用這個動作~
bash-4.2$ docker logout https://containers.enterprisedb.com/
Removing login credentials for containers.enterprisedb.com
bash-4.2$ 

觸發 Failover
bash-4.2$ docker stop efm1
efm1
bash-4.2$ 

過一下子後,看看狀態
bash-4.2$ docker exec -it efm2 efm cluster-status edb
Cluster Status: edb

        Agent Type  Address              Agent  DB       VIP
        -----------------------------------------------------------------------
        Master      172.18.0.23          UP     UP        
        Standby     172.18.0.24          UP     UP        
        Standby     172.18.0.25          UP     UP        

Allowed node host list:
        172.18.0.22 172.18.0.23 172.18.0.24 172.18.0.25

Membership coordinator: 172.18.0.23

Standby priority host list:
        172.18.0.24 172.18.0.25

Promote Status:

        DB Type     Address              XLog Loc         Info
        --------------------------------------------------------------
        Master      172.18.0.23          0/9000170        
        Standby     172.18.0.25          0/9000170        
        Standby     172.18.0.24          0/9000170        

        Standby database(s) in sync with master. It is safe to promote.
bash-4.2$ 

再補回一個:不過這邊要注意 Master DB 換成 efm2 了

bash-4.2$ sudo mkdir -p /var/lib/edb/as10/stdby4
bash-4.2$ sudo chmod -R 777 /var/lib/edb/as10/stdby4
bash-4.2$ docker run -e DATABASE_NAME="edb" -e PGPORT=5444 -e DATABASE_USER="enterprisedb" -e DATABASE_USER_PASSWORD="edb" -e ENTERPRISEDB_PASSWORD="edb" -e REPL_USER="repuser" -e REPL_PASSWORD="edb" -e LOCALEPARAMETER="en_US" -e CLEANUP_SCHEDULE="0:0:*:*:*" -e EFM_EMAIL="email@address.com" -e ACCEPT_EULA=Yes -e MASTER_HOST="`sudo docker inspect --format '{{.NetworkSettings.Networks.efm123.IPAddress }}' efm2`" -e MASTER_PORT=5444 --net efm123 --ip 172.18.0.26 --name "efm5" -v /var/lib/edb/as10/stdby4:/edbvolume -d containers.enterprisedb.com/edb/edb-as:v10
2972bb261f8e10a596903142fc1a0cd0af3322139c4186db4914df355ba45eca
bash-4.2$ 

確認狀態一如預期
bash-4.2$ docker exec -it efm2 efm cluster-status edb
Cluster Status: edb
        Agent Type  Address              Agent  DB       VIP
        -----------------------------------------------------------------------
        Master      172.18.0.23          UP     UP        
        Standby     172.18.0.24          UP     UP        
        Standby     172.18.0.25          UP     UP        
        Standby     172.18.0.26          UP     UP        

Allowed node host list:
        172.18.0.22 172.18.0.23 172.18.0.24 172.18.0.25 172.18.0.26

Membership coordinator: 172.18.0.23

Standby priority host list:
        172.18.0.24 172.18.0.25 172.18.0.26

Promote Status:

        DB Type     Address              XLog Loc         Info
        --------------------------------------------------------------
        Master      172.18.0.23          0/B000060        
        Standby     172.18.0.25          0/B000060        
        Standby     172.18.0.24          0/B000060        
        Standby     172.18.0.26          0/B000060        

        Standby database(s) in sync with master. It is safe to promote.
bash-4.2$ 

這裡只有用單機的佈署處理。如果要作實際跨 Host 的 HA 規劃,則可以用 Docker Compose 搭配 Docker Swarm 或 Kubernetes 等「容器調度平台」處理,手冊已經提供了 Openshift + Kubernetes 的 YAML 設定檔可以參考。以後有機會再來試試~

實際上,EnterpriseDB 對於 Red Hat 的 OpenShift 解決方案提供高度整合的支援,可以在相關的管理界面輕易進行佈署與設置私有的 Registry,詳細請看官方手冊。如果是使用其他的平台(例如,Docker EE)原則上也是可以設置的~只是要參考一下相關手冊,把 EDB Container Registry 註冊進去就可以了。

參考資料:

沒有留言:

張貼留言