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

文章目录

(一)背景

差不多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) 社区版。

bash 复制代码
> sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

然后安装docker:

bash 复制代码
> sudo yum install -y docker-ce

装好了看看版本:

bash 复制代码
> docker -v
Docker version 25.0.4, build 1a576c5

测试看能不能用:

bash 复制代码
> 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不存在呢?):

bash 复制代码
> docker pull enmotech/opengauss:5.0.1

我也试了latest居然版本是5.1.0,既然不是官网的LTS,还是指定版本吧。

然后确认下镜像(我这有几个别的东西请无视):

bash 复制代码
> 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

bash 复制代码
> 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映射)。

确认下在运行么:

bash 复制代码
> 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用户也是默认的。

镜像配置了本地信任机制,因此在容器内连接数据库无需密码。

bash 复制代码
> 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 查询到的信息,我们停止这个容器的运行。

bash 复制代码
> docker stop 20f56e169910
20f56e169910
> 

再ps看看应该没有openGauss的容器在运行了。

这时候我们可以查询全部容器确认运行状态,确实是Exited状态。

bash 复制代码
> 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:

bash 复制代码
> docker restart 20f56e169910
20f56e169910

再用工具看看里面的表数据,重新运行成功了。

关于容器重启和其它的可以参考这个文章。

(四)额外

(4.1)移除容器

⚠️删了就没了哦!!!

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

bash 复制代码
> docker stop 20f56e169910
20f56e169910
> docker rm 20f56e169910
20f56e169910

这样容器就没了,那么如果再次运行openGauss的镜像,会创建一个新的容器。

你之前的表和数据,随着旧容器的删除,就都丢失了。。。

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


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

相关推荐
程序员Android2 分钟前
MTK多帧拍照流程分析
数据库
不剪发的Tony老师3 分钟前
Apache Doris:一款高性能的实时数据仓库
数据库·数据仓库
甜可儿14 分钟前
redis序列化设置
数据库·redis
GGBondlctrl19 分钟前
【SpringBoot】论坛项目中如何进行实现发布文章,以及更新对应数据库的数据更新
数据库·springboot项目·三层设计思想·文章发布项目
若云止水33 分钟前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_init_cycle 函数 - 详解(4)
数据库·nginx·ubuntu
Dontla1 小时前
Docker run --add-host参数解析(在容器启动时向/etc/hosts文件中添加自定义的主机名与IP映射)(适用于临时调试或测试)
tcp/ip·docker·容器
西西小飞龙1 小时前
Docker和K8S中pod、services、container的介绍和关系
docker·容器·kubernetes
jay丿1 小时前
Django模板系统深入
数据库·django·sqlite
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
kngines1 小时前
【实战 ES】实战 Elasticsearch:快速上手与深度实践-1.3.1单节点安装(Docker与手动部署)
大数据·elasticsearch·docker