Martin
by Martin Kysel

在Docker中运行Nuodb - 第4部分:使用Docker Compose

在第一 诺克斯博客,我们概述了如何在Docker容器中部署Nuodb数据库 Docker运行 。在此博客文章中,我们将通过提供完整Nuodb堆栈的单击部署来改进该过程。

为实现这一目标,我们将使用 Docker撰写 ,一个用于定义和运行多容器Docker应用程序的工具。撰写显着简化了NOODB的部署。

对于此博客文章,我们将使用一个非常简单,最小的数据库组成

  • 2管理流程
  • 1存储管理器(SM)
  • 2交易引擎(TE)。

我们将使用Nuodb Community Edition(CE),可自由地提供 Dockerhub. .

步骤1.验证Docker Compose可用

首先,您应该验证您的机器是否有 Docker撰写 安装了软件。此示例使用的是Compose文件版本“3.7”,可提供Docker Engine版本18.06.0+。

$ docker-compose -v
Docker撰写 version 1.27.2, build 18f557f9

 

步骤2.创建Docker Compose.yml配置文件

要启动,请使用以下内容创建Docker-compose.yml文件:

version: "3.7"
  
volumes:
  nuoadmin-raft-1:
  nuoadmin-raft-2:
  hockey-arch-vol-1:
 
services:
 nuoadmin1:
   image: nuodb/nuodb-ce:latest
   environment:
     NUODB_DOMAIN_ENTRYPOINT: nuoadmin1
     NUOCMD_API_SERVER: http://nuoadmin1:8888
   hostname: nuoadmin1
   volumes:
     - nuoadmin-raft-1:/var/opt/nuodb
   command: ["nuoadmin", "--", "ssl=false"]
 nuoadmin2:
   image: nuodb/nuodb-ce:latest
   environment:
     NUODB_DOMAIN_ENTRYPOINT: nuoadmin1
     NUOCMD_API_SERVER: http://nuoadmin2:8888
   hostname: nuoadmin2
   volumes:
     - nuoadmin-raft-2:/var/opt/nuodb
   command: ["nuoadmin", "--", "ssl=false"]
 sm:
   image: nuodb/nuodb-ce:latest
   hostname: sm
   environment:
     NUOCMD_API_SERVER: http://nuoadmin1:8888
   volumes:
     - hockey-arch-vol-1:/var/opt/nuodb
   depends_on:
   - nuoadmin1
   command: ["nuodocker", "start", "sm", "--db-name", "hockey", "--server-id", "nuoadmin1", "--dba-user", "dba", "--dba-password", "goalie", "--servers-ready-timeout", "15000"]
 te:
   image: nuodb/nuodb-ce:latest
   hostname: te
   environment:
     NUOCMD_API_SERVER: http://nuoadmin1:8888
   depends_on:
   - nuoadmin1
   - sm
   deploy:
     replicas: 2
   command: ["nuodocker", "start", "te", "--db-name", "hockey", "--server-id", "nuoadmin1", "--servers-ready-timeout", "15000"]

此Docker-compose.yml文件指定由2个管理员进程组成的域(服务:nuoadmin1和service:nuoadmin2),1个存储管理器(服务:SM)和2个事务引擎(服务:TE)。

步骤3.启动Nuodb域

使用您当前目录中存在的Docker-compose.yml文件, Docker撰写 installed, run: 

$ docker-compose up -d
Creating network "nuodb_default" with the default driver
Creating volume "nuodb_nuoadmin-raft-1" with default driver
Creating volume "nuodb_nuoadmin-raft-2" with default driver
Creating volume "nuodb_test-arch-vol-1" with default driver
Creating nuodb_nuoadmin1_1 ... done
Creating nuodb_nuoadmin2_1 ... done
Creating nuodb_sm_1        ... done
Creating nuodb_te_1        ... done
Creating nuodb_te_2        ... done

您可以验证Docker Compose按预期启动五个容器:

$ docker ps
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                       NAMES
503acb3b7472        nuodb/nuodb-ce:latest   "docker-entrypoint.s…"   54 seconds ago      Up 53 seconds       8888/tcp, 48004-48006/tcp   nuodb_te_2
b6cf209144bb        nuodb/nuodb-ce:latest   "docker-entrypoint.s…"   54 seconds ago      Up 53 seconds       8888/tcp, 48004-48006/tcp   nuodb_te_1
37a1db309b29        nuodb/nuodb-ce:latest   "docker-entrypoint.s…"   54 seconds ago      Up 53 seconds       8888/tcp, 48004-48006/tcp   nuodb_sm_1
4fa0ab0255e7        nuodb/nuodb-ce:latest   "docker-entrypoint.s…"   55 seconds ago      Up 54 seconds       8888/tcp, 48004-48006/tcp   nuodb_nuoadmin1_1
2621e1b79ed3        nuodb/nuodb-ce:latest   "docker-entrypoint.s…"   55 seconds ago      Up 54 seconds       8888/tcp, 48004-48006/tcp   nuodb_nuoadmin2_1

您应该看到nuodb_te_1,nuodb_te_2,nuodb_sm_1,nuodb_nuoadmin_1和nuodb_nuoadmin2。容器名称取决于服务名称(SM / TE / NUOODMIN1 / NUOODMIN2)和当前目录的名称。在我们的示例中,我们正在从一个名为“NOODB”的目录中执行。

Docker. 撰写自动为所有容器创建网络,因此不需要公开任何端口,指定网络或链接容器。

$ docker network ls
NETWORK ID          NAME                      DRIVER              SCOPE
f2e75c2c3086        compose_default           bridge              local

您可以使用适当的Docker命令列出由Docker编写创建的持久存储卷。在此示例中,我们为每个管理过程创建了1卷,为SM过程为1卷。

$ docker volume ls
DRIVER              VOLUME NAME
local               nuodb_nuoadmin-raft-1
local               nuodb_nuoadmin-raft-2
local               nuodb_hockey-arch-vol-1

步骤4.验证域是否正在运行

验证所有容器是否完全连接并形成了健康域的最佳方法,我们建议使用 Nuocmd. command:

$ docker-compose exec nuoadmin1 nuocmd show domain
server version: 4.1.1-3-2203dab8dd, server license: Community
server time: 2020-10-09T18:14:51.848, client token: c6cbc5381db737078b4541740ad520570f7f0900
Servers:
  [nuoadmin1] nuoadmin1:48005 [last_ack = 0.85] [member = ADDED] [raft_state = ACTIVE] (LEADER, Leader=nuoadmin1, log=0/23/23) Connected *
  [nuoadmin2] nuoadmin2:48005 [last_ack = 0.85] [member = ADDED] [raft_state = ACTIVE] (FOLLOWER, Leader=nuoadmin1, log=0/23/23) Connected
Databases:
  hockey [state = RUNNING]
    [SM] sm/192.168.144.4:48006 [start_id = 0] [server_id = nuoadmin1] [pid = 38] [node_id = 1] [last_ack =  4.04] MONITORED:RUNNING
    [TE] te/192.168.144.6:48006 [start_id = 1] [server_id = nuoadmin1] [pid = 38] [node_id = 3] [last_ack =  0.19] MONITORED:RUNNING
    [TE] te/192.168.144.5:48006 [start_id = 2] [server_id = nuoadmin1] [pid = 38] [node_id = 2] [last_ack =  1.02] MONITORED:RUNNING

运行SQL.

使用域启动和运行,您现在可以遵循概述的步骤 Docker博客I. 并探索Nuodb的SQL功能。要连接到管理员容器,只需执行

$ docker exec -it compose_nuoadmin1_1 bash
bash-4.2$ 

或者

$ docker-compose exec nuoadmin1 bash
bash-4.2$ 

缩放数据库

使用Docker-Compose,很容易缩放NuodB进程的数量。添加第三个te,只需执行 Docker撰写 scale as follows:

$ docker-compose up -d --scale te=3
Starting nuodb_te_1 ... done
Starting nuodb_te_2 ... done
Creating nuodb_te_3 ... done

等待后,新TE可在域中提供。

$ docker-compose exec nuoadmin1 nuocmd show domain
server version: 4.1.1-3-2203dab8dd, server license: Community
server time: 2020-10-09T18:24:17.892, client token: 10e758721a939611fe18e22c03b4c6e6639d3d7a
Servers:
  [nuoadmin1] nuoadmin1:48005 [last_ack = 1.75] [member = ADDED] [raft_state = ACTIVE] (LEADER, Leader=nuoadmin1, log=0/29/29) Connected *
  [nuoadmin2] nuoadmin2:48005 [last_ack = 1.75] [member = ADDED] [raft_state = ACTIVE] (FOLLOWER, Leader=nuoadmin1, log=0/29/29) Connected
Databases:
  hockey [state = RUNNING]
    [SM] sm/192.168.176.4:48006 [start_id = 0] [server_id = nuoadmin1] [pid = 39] [node_id = 1] [last_ack =  8.85] MONITORED:RUNNING
    [TE] te/192.168.176.5:48006 [start_id = 1] [server_id = nuoadmin1] [pid = 38] [node_id = 2] [last_ack =  5.85] MONITORED:RUNNING
    [TE] te/192.168.176.6:48006 [start_id = 2] [server_id = nuoadmin1] [pid = 38] [node_id = 3] [last_ack =  4.85] MONITORED:RUNNING
    [TE] te/192.168.176.7:48006 [start_id = 3] [server_id = nuoadmin1] [pid = 40] [node_id = 4] [last_ack =  2.74] MONITORED:RUNNING

如何关闭nuodb

关闭使用Docker Compose创建的Nuodb域,执行 Docker. -Compose 命令在相同目录中包含您在步骤1中早期创建的docker-compose.yml文件的。

$ docker-compose down
Stopping nuodb_te_2        ... done
Stopping nuodb_te_1        ... done
Stopping nuodb_sm_1        ... done
Stopping nuodb_nuoadmin1_1 ... done
Stopping nuodb_nuoadmin2_1 ... done
Removing nuodb_te_2        ... done
Removing nuodb_te_1        ... done
Removing nuodb_sm_1        ... done
Removing nuodb_nuoadmin1_1 ... done
Removing nuodb_nuoadmin2_1 ... done
Removing network nuodb_default

Docker撰写 将自动清理所有资源。您可以运行以下命令以确认。

网络:

$ docker network ls
NETWORK ID          NAME                      DRIVER              SCOPE

容器:

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

另一方面,卷将保存:

$ docker volume ls
DRIVER              VOLUME NAME
local               nuodb_nuoadmin-raft-1
local               nuodb_nuoadmin-raft-2
local               nuodb_hockey-arch-vol-1

而已!我们希望您享受使用Docker Compose和Nuodb的快速游览!