用docker方式安装openGauss数据库的事项记录

发布于:2024-04-26 ⋅ 阅读:(20) ⋅ 点赞:(0)

(一)背景

差不多2年前吧进行了数据库的从Oracle迁移到国产化数据库的工作。
比如这篇就记录了一些情况。

但实际上后面都是弄的中兴GoldenDB(MySQL)那边。
然后在GoldenDB那边遇到的若干神奇问题以及性能问题,更加印证了Oracle的遥遥领先。

现在又准备开始华为这边,但我已经忘得差不多了啊,可恶……
看了看openGauss官网,想了想懒得动之前装好的openGauss3.0.0数据库,考虑到环境互相影响,决定用docker来装目前稳定的5.0.1 LTS(目前已正式发行 6.0.0 RC1 版)吧。
在这里插入图片描述

(二)安装

(2.1)安装docker

我已经有了所以略……
如果没有的话就,我的是CentOS7,需要添加yum的docker的源。

问:docker-ce为什么有个ce后缀?
答:CE (Community Edition) 社区版。

> sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

然后安装docker:

> sudo yum install -y docker-ce

装好了看看版本:

> docker -v
Docker version 25.0.4, build 1a576c5

测试看能不能用:

> docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

至此hello world镜像能运行了,说明docker安装无误。
如果哪一步报错,就设法解决呗。

(2.2)安装openGauss

其实已经没有安装的过程了。
仅仅是拉取镜像(为啥openguass/opengauss:5.0.1不存在呢?):

> docker pull enmotech/opengauss:5.0.1

我也试了latest居然版本是5.1.0,既然不是官网的LTS,还是指定版本吧。
然后确认下镜像(我这有几个别的东西请无视):

> docker images
REPOSITORY           TAG       IMAGE ID       CREATED         SIZE
emqx/emqx            5.5.1     f9a9d20bd75c   7 weeks ago     476MB
enmotech/opengauss   5.0.1     1aefc6a6f5a5   3 months ago    466MB
dgraph/dgraph        latest    3a69d4681409   8 months ago    178MB
hello-world          latest    d2c94e258dcb   11 months ago   13.3kB
dgraph/ratel         latest    98e9777f3b57   2 years ago     26.7MB

(三)运行

(3.1)运行openGauss镜像

首次运行会创建这个镜像的容器,名字我们指定的是opengauss

> sudo docker run --name opengauss --privileged=true -d -e GS_PASSWORD=你的密码包含字母符号数字 -p 5432:5432 enmotech/opengauss:5.0.1

注意2点:

  1. 通过GS_PASSWORD设置个相对复杂的密码(包含字母符号数字),否则登不上啊。
  2. 通过-p参数给个端口映射,外面才能访问(如果默认5432外面在用,那么换个比如8888:5432映射)。

确认下在运行么:

> docker ps
CONTAINER ID   IMAGE                      COMMAND                   CREATED         STATUS         PORTS                                       NAMES
20f56e169910   enmotech/opengauss:5.0.1   "entrypoint.sh gauss…"   3 minutes ago   Up 3 minutes   0.0.0.0:5432->5432/tcp, :::5432->5432/tcp   opengauss

(3.2)连接openGauss

(3.2.1)内部gsql连接

如果没有刚才-p的端口映射,那么就只能进去再连接。
那个omm用户也是默认的。
镜像配置了本地信任机制,因此在容器内连接数据库无需密码。

> docker exec -it opengauss sh
# su - omm
omm@20f56e169910:~$ gsql
gsql ((openGauss 5.0.1 build 33b035fd) compiled at 2023-12-15 19:51:49 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

omm=# \q
omm@20f56e169910:~$ exit
logout
# exit
> 

现在整个流程完成了,数据库确实是openGauss 5.0.1 build 33b035fd版本。
但是要正常用还是得从外面和网络连接它。

(3.2.2)外部客户端工具连接

回到亲切的Windows图形界面,打开数据库客户端工具。

  • 设置数据库类型为PostgreSQL,主机,端口。
  • 设置连接数据库名字为postgres (PG默认的)
  • 设置用户名为gaussdb (默认的)
  • 设置密码为“刚才你指定的那个挺复杂的密码”。

PS:如果没有刚才-p的端口映射,外面是连不了的。

在这里插入图片描述
连接试试,连上了没问题:
如果还是连不上估计得看看防火墙,ping下port通么(胡言乱语了)。
在这里插入图片描述
这时候就可以做常规操作了。
比如建用户,建表等。

(3.3)停止openGauss容器

在首次运行docker的镜像时,创建了容器,我们查询并停止这个容器。
根据刚才docker ps 查询到的信息,我们停止这个容器的运行。

> docker stop 20f56e169910
20f56e169910
> 

再ps看看应该没有openGauss的容器在运行了。
这时候我们可以查询全部容器确认运行状态,确实是Exited状态。

> docker ps -a
CONTAINER ID   IMAGE                      COMMAND                   CREATED             STATUS                         PORTS     NAMES
20f56e169910   enmotech/opengauss:5.0.1   "entrypoint.sh gauss…"   54 minutes ago      Exited (0) 2 seconds ago                 opengauss
915dedb7d037   hello-world                "/hello"                  About an hour ago   Exited (0) About an hour ago             trusting_nobel
a52db001f7a8   emqx/emqx:5.5.1            "/usr/bin/docker-ent…"   5 weeks ago         Exited (0) 5 weeks ago                   emqx
abec43d19cd2   dgraph/dgraph:latest       "dgraph zero --my=ze…"   6 weeks ago         Exited (0) 5 weeks ago                   shion_zero_1
374538787e98   dgraph/ratel:latest        "dgraph-ratel"            6 weeks ago         Exited (2) 5 weeks ago                   shion_ratel_1
5dd928033303   dgraph/dgraph:latest       "dgraph alpha --secu…"   6 weeks ago         Exited (0) 5 weeks ago                   shion_server_1
a4b606382d1c   dgraph/dgraph:latest       "dgraph"                  6 weeks ago         Exited (0) 6 weeks ago                   dgraph
e5c8c8e1cd6e   dgraph/dgraph:latest       "dgraph alpha --my=a…"   6 weeks ago         Exited (0) 6 weeks ago                   shion_alpha_1

(3.4)重新运行openGauss容器

还是那个容器ID:

> docker restart 20f56e169910
20f56e169910

再用工具看看里面的表数据,重新运行成功了。
关于容器重启和其它的可以参考这个文章。

(四)额外

(4.1)移除容器

⚠️删了就没了哦!!!

容器需要停止后才能删除。

> docker stop 20f56e169910
20f56e169910
> docker rm 20f56e169910
20f56e169910

这样容器就没了,那么如果再次运行openGauss的镜像,会创建一个新的容器。
你之前的表和数据,随着旧容器的删除,就都丢失了。。。

怕理解错了,所以加了这小段。


至于镜像-容器-数据卷,自动重启等等。网上资料很多,不在此继续讨论。