(一)背景
差不多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点:
- 通过GS_PASSWORD设置个相对复杂的密码(包罗字母符号数字),否则登不上啊。
- 通过-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 20f56e16991020f56e169910
复制代码 如许容器就没了,那么假如再次运行openGauss的镜像,会创建一个新的容器。
你之前的表和数据,随着旧容器的删除,就都丢失了。。。
怕明白错了,所以加了这小段。
至于镜像-容器-数据卷,自动重启等等。网上资料很多,不在此继承讨论。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |