启用opengauss2.1.0-oe2203sp3容器的数据库服务管理功能

发布时间:2024年01月11日

前文《全网独家:基于openEuler-22.03-LTS-SP4底包构建opengauss 2.1.0 rpm包安装的单机轻量版数据库容器》已完成opengauss2.1.0-oe2203sp3容器的构建,本文记录启用数据库服务管理功能的过程。

一、基础容器

见本人前文

《基于openEuler-22.03-LTS-SP4底包构建opengauss 2.1.0 rpm包安装的单机轻量版数据库容器》

已完成?opengauss2.1.0-oe2203sp3容器的构建。

二、配置启用数据库服务管理功能

1、一点说明

在构建?opengauss2.1.0-oe2203sp3容器时,使用的openEuler-22.03-LTS-SP4底包缺省没有安装systemd服务包,因此启动容器命令使用的是/bin/bash。在yum install?opengauss的安装过程中,实际上是把systemd服务包作为依赖包进行了安装:

...

====================================================================================================================
?Package ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Architecture ? ? Version ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Repository ? ?Size
====================================================================================================================
Installing:
?opengauss ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?x86_64 ? ? ? ? ? 2.1.0-9.oe2203sp3 ? ? ? ? ? ? ? ? ? ? ? OS ? ? ? ? ? ?14 M
Installing dependencies:

...

systemd ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?x86_64 ? ? ? ? ? 249-63.oe2203sp3 ? ? ? ? ? ? ? ? ? ? ? ?OS ? ? ? ? ? 3.5 M

..

因此安装opengauss完成后的容器带了Systemd这个系统init软件,可以进行系统初始化并管理系统服务的,如下所示


[root@22bab46d8b1d /]# ll /sbin/init
lrwxrwxrwx 1 root root 22 Dec 28 13:49 /sbin/init -> ../lib/systemd/systemd
[root@22bab46d8b1d /]# cat /usr/lib/systemd/system/opengauss.service
[Unit]
Description=Start openGauss server
After=local-fs.target

[Service]
Type=idle
ExecStart=/usr/local/opengauss/script/autostart.sh
Delegate=yes
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
2、启用数据库服务管理功能

因当前容器只是做了安装初始化,还未导入生产库数据,因此删除现有容器,用/sbin/init作为启动命令让容器启动时运行systemd。

[root@localhost opengauss-2.1.0-oe2203sp3]# docker rm -f opengauss
opengauss
[root@localhost opengauss-2.1.0-oe2203sp3]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
opengauss2.1.0            oe2203sp3           6e3c83d115f3        32 minutes ago      1.49GB
[root@localhost opengauss-2.1.0-oe2203sp3]# docker run -itd --restart=always --name opengauss  --privileged -p 7654:7654 -v /etc/localtime:/etc/localtime:ro  opengauss2.1.0:oe2203sp3 /sbin/init
4ec583f58a8cdb0ae4136d46f8610aed5946f901b9784e712142790fa846ebdf

进入容器察看服务管理是否已生效

[root@localhost opengauss-2.1.0-oe2203sp3]# docker exec -it opengauss /bin/bash


Welcome to 5.10.0-60.18.0.50.oe2203.x86_64

System information as of time:  Thu Jan 11 11:24:01 CST 2024

System load:    0.08
Processes:      10
Memory used:    26.6%
Swap used:      3.3%
Usage On:       86%
Users online:   0


[root@4ec583f58a8c /]# systemctl status opengauss
● opengauss.service - Start openGauss server
     Loaded: loaded (/usr/lib/systemd/system/opengauss.service; enabled; vendor preset: disabled)
     Active: active (exited) since Thu 2024-01-11 11:23:53 CST; 18s ago
    Process: 34 ExecStart=/usr/local/opengauss/script/autostart.sh (code=exited, status=0/SUCCESS)
   Main PID: 34 (code=exited, status=0/SUCCESS)
     CGroup: /docker/4ec583f58a8cdb0ae4136d46f8610aed5946f901b9784e712142790fa846ebdf/system.slice/opengauss.service
             └─ 99 /usr/local/opengauss/bin/gaussdb -D /var/lib/opengauss/data

Jan 11 11:23:53 4ec583f58a8c systemd[1]: Started Start openGauss server.
Jan 11 11:23:53 4ec583f58a8c su[42]: (to opengauss) root on none
Jan 11 11:23:53 4ec583f58a8c su[42]: pam_unix(su-l:session): session opened for user opengauss(uid=1000) by (uid=0)
Jan 11 11:23:55 4ec583f58a8c su[42]: pam_unix(su-l:session): session closed for user opengauss
Jan 11 11:23:55 4ec583f58a8c autostart.sh[34]: Start openGauss database success.
[root@4ec583f58a8c /]# su - opengauss
Last login: Thu Jan 11 11:23:53 CST 2024


Welcome to 5.10.0-60.18.0.50.oe2203.x86_64

System information as of time:  Thu Jan 11 11:24:40 CST 2024

System load:    0.04
Processes:      12
Memory used:    26.7%
Swap used:      3.3%
Usage On:       86%
Users online:   0
To run a command as administrator(user "root"),use "sudo <command>".
[opengauss@4ec583f58a8c ~]$ gs_ctl query -D /var/lib/opengauss/data
[2024-01-11 11:24:43.034][248][][gs_ctl]: gs_ctl query ,datadir is /var/lib/opengauss/data 
 HA state:           
        local_role                     : Normal
        static_connections             : 0
        db_state                       : Normal
        detail_information             : Normal

 Senders info:       
No information 
 Receiver info:      
No information 
[opengauss@4ec583f58a8c ~]$ 

可以看到数据库服务已随容器启动自动拉起

3、重启服务测试
[root@4ec583f58a8c /]# systemctl restart opengauss
[root@4ec583f58a8c /]# systemctl status opengauss             
● opengauss.service - Start openGauss server
     Loaded: loaded (/usr/lib/systemd/system/opengauss.service; enabled; vendor preset: disabled)
     Active: active (exited) since Thu 2024-01-11 13:54:16 CST; 2min 37s ago
    Process: 808 ExecStart=/usr/local/opengauss/script/autostart.sh (code=exited, status=0/SUCCESS)
   Main PID: 808 (code=exited, status=0/SUCCESS)
     CGroup: /docker/4ec583f58a8cdb0ae4136d46f8610aed5946f901b9784e712142790fa846ebdf/system.slice/opengauss.service
             └─ 864 /usr/local/opengauss/bin/gaussdb -D /var/lib/opengauss/data

Jan 11 13:54:16 4ec583f58a8c systemd[1]: Started Start openGauss server.
Jan 11 13:54:16 4ec583f58a8c su[809]: (to opengauss) root on none
Jan 11 13:54:16 4ec583f58a8c su[809]: pam_unix(su-l:session): session opened for user opengauss(uid=1000) by (uid=0)
Jan 11 13:54:17 4ec583f58a8c su[809]: pam_unix(su-l:session): session closed for user opengauss
Jan 11 13:54:17 4ec583f58a8c autostart.sh[808]: Start openGauss database success.

测试OK。

文章来源:https://blog.csdn.net/forestqq/article/details/135524829
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。