opengauss2.1.0-oe2203sp3数据库容器的生产性部署

发布时间:2024年01月15日

本文记录了用笔者基于openEuler-22.03-LTS-SP4底包构建的opengauss 2.1.0 rpm包安装的单机轻量版数据库容器,进行生产性部署的过程

一、生产化环境

1、容器镜像

参见笔者前文:

前文一:全网独家——基于openEuler-22.03-LTS-SP4底包构建opengauss 2.1.0 rpm包安装的单机轻量版数据库容器

前文二:启用opengauss2.1.0-oe2203sp3容器的数据库服务管理功能?

提前将容器镜像tar包分发至生产服务器/tmp目录下

2、生产服务器系统环境

操作系统版本:

[root@localhost ~]# cat /etc/os-release 
NAME="openEuler"
VERSION="22.03 LTS"
ID="openEuler"
VERSION_ID="22.03"
PRETTY_NAME="openEuler 22.03 LTS"
ANSI_COLOR="0;31"

?数据盘:/app

服务器IP地址:192.168.100.108

二、生产性部署过程

1、安装docker引擎服务
[root@localhost opt]# yum install docker
Last metadata expiration check: 0:56:38 ago on 2024年01月15日 星期一 10时23分59秒.
Dependencies resolved.
====================================================================================================================
 Package                    Architecture        Version                         Repository                     Size
====================================================================================================================
Installing:
 docker-engine              x86_64              18.09.0-300.oe2203              openEuler2203LTS               37 M
Installing dependencies:
 libcgroup                  x86_64              0.42.2-1.oe2203                 openEuler2203LTS               97 k

Transaction Summary
====================================================================================================================
Install  2 Packages

Total download size: 37 M
Installed size: 154 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): libcgroup-0.42.2-1.oe2203.x86_64.rpm                                         1.3 MB/s |  97 kB     00:00    
(2/2): docker-engine-18.09.0-300.oe2203.x86_64.rpm                                   56 MB/s |  37 MB     00:00    
--------------------------------------------------------------------------------------------------------------------
Total                                                                                56 MB/s |  37 MB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                            1/1 
  Running scriptlet: libcgroup-0.42.2-1.oe2203.x86_64                                                           1/2 
  Installing       : libcgroup-0.42.2-1.oe2203.x86_64                                                           1/2 
  Running scriptlet: libcgroup-0.42.2-1.oe2203.x86_64                                                           1/2 
  Installing       : docker-engine-18.09.0-300.oe2203.x86_64                                                    2/2 
  Running scriptlet: docker-engine-18.09.0-300.oe2203.x86_64                                                    2/2 
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

  Verifying        : docker-engine-18.09.0-300.oe2203.x86_64                                                    1/2 
  Verifying        : libcgroup-0.42.2-1.oe2203.x86_64                                                           2/2 

Installed:
  docker-engine-18.09.0-300.oe2203.x86_64                      libcgroup-0.42.2-1.oe2203.x86_64                     

Complete!
2、将镜像文件拷贝到数据盘目录
[root@localhost opt]# cd /app
[root@localhost app]# mkdir opengauss
[root@localhost app]# cd opengauss/
[root@localhost opengauss]# mv /tmp/opengauss2.1.0-oe2203sp3.docker.tar .
3、导入镜像
[root@localhost opengauss]# docker load -i opengauss2.1.0-oe2203sp3.docker.tar 


Loaded image: opengauss2.1.0:oe2203sp3
4、生成容器
[root@localhost opengauss]# docker run -itd --restart=always --name opengauss  --privileged -p 7654:7654 -v /etc/localtime:/etc/localtime:ro  opengauss2.1.0:oe2203sp3 /sbin/init
65825e92e915627c4244e30d4b26db7e9c8a57d7b7d64d5f907342291c65a2b5
5、将数据库的数据文件从容器中复制到本地数据盘中
[root@localhost app]# cd opengaussdata/
[root@localhost opengaussdata]# docker ps -a
CONTAINER ID        IMAGE                      COMMAND             CREATED             STATUS              PORTS                              NAMES
d80de3d43652        opengauss2.1.0:oe2203sp3   "/sbin/init"        3 minutes ago       Up 3 minutes        5432/tcp, 0.0.0.0:7654->7654/tcp   opengauss
[root@localhost opengaussdata]# docker cp opengauss:/var/lib/opengauss . 
[root@localhost opengaussdata]# ll
总用量 0
drwx------ 3 root root 60  1月 11 10:41 opengauss
[root@localhost opengaussdata]# ll -al opengauss/
总用量 12K
drwx------  3 root root   60  1月 11 10:41 .
drwxr-x---  3 root root   23  1月 15 11:43 ..
-rw-------  1 root root  562  1月 11 10:46 .bash_history
-rw-r--r--  1 root root  202 12月 28 14:29 .bash_profile
drwx------ 25 root root 4.0K  1月 15 11:39 data
6、删除初始化容器,用本地数据盘的数据文件重新启动容器
[root@localhost opengaussdata]# docker rm -f opengauss
opengauss
[root@localhost opengaussdata]# docker run -itd --restart=always --name opengauss  --privileged -p 7654:7654 -v /etc/localtime:/etc/localtime:ro -v /app/opengaussdata/opengauss:/var/lib/opengauss opengauss2.1.0:oe2203sp3 /sbin/init 
18aa9b3464849e15ee9d58de875f70de3b0e74749910c074412f22316104e0eb
7、进入容器修正目录权限并重启服务
[root@localhost opengaussdata]# docker exec -it opengauss /bin/bash


Welcome to 5.10.0-60.18.0.50.oe2203.x86_64

System information as of time:  Mon Jan 15 12:27:26 CST 2024

System load:    0.03
Processes:      9
Memory used:    32.6%
Swap used:      9.9%
Usage On:       34%
Users online:   0


[root@18aa9b346484 /]# ll /var/lib/opengauss/
total 4
drwx------ 25 root root 4096 Jan 15 11:39 data
[root@18aa9b346484 /]# chown opengauss:opengauss /var/lib/opengauss -R
[root@18aa9b346484 /]# systemctl restart opengauss 
[root@18aa9b346484 /]# systemctl status opengauss
● opengauss.service - Start openGauss server
     Loaded: loaded (/usr/lib/systemd/system/opengauss.service; enabled; vendor preset: disabled)
     Active: active (exited) since Mon 2024-01-15 12:28:09 CST; 8s ago
    Process: 158 ExecStart=/usr/local/opengauss/script/autostart.sh (code=exited, status=0/SUCCESS)
   Main PID: 158 (code=exited, status=0/SUCCESS)
     CGroup: /docker/18aa9b3464849e15ee9d58de875f70de3b0e74749910c074412f22316104e0eb/system.slice/opengauss.service
             └─ 214 /usr/local/opengauss/bin/gaussdb -D /var/lib/opengauss/data

Jan 15 12:28:09 18aa9b346484 systemd[1]: Started Start openGauss server.
Jan 15 12:28:09 18aa9b346484 su[159]: (to opengauss) root on none
Jan 15 12:28:09 18aa9b346484 su[159]: pam_unix(su-l:session): session opened for user opengauss(uid=1000) by (uid=0)
Jan 15 12:28:10 18aa9b346484 su[159]: pam_unix(su-l:session): session closed for user opengauss
Jan 15 12:28:10 18aa9b346484 autostart.sh[158]: Start openGauss database success.
[root@18aa9b346484 /]# su - opengauss
Last login: Mon Jan 15 12:28:09 CST 2024


Welcome to 5.10.0-60.18.0.50.oe2203.x86_64

System information as of time:  Mon Jan 15 12:28:29 CST 2024

System load:    0.01
Processes:      12
Memory used:    37.7%
Swap used:      9.9%
Usage On:       34%
Users online:   0
To run a command as administrator(user "root"),use "sudo <command>".
[opengauss@18aa9b346484 ~]$ gs_ctl query -D /var/lib/opengauss/data
[2024-01-15 12:28:31.613][305][][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 
8、修改数据库的访问方式及监听地址等参数,并重启服务开放外部访问
[opengauss@18aa9b346484 ~]$ cd /var/lib/opengauss/
[opengauss@18aa9b346484 ~]$ cd data
[opengauss@18aa9b346484 data]$ ll
total 4876
-rw------- 1 opengauss opengauss       4 Jan 11 09:52 PG_VERSION
drwx------ 3 opengauss opengauss      25 Jan 11 09:52 asp_data
drwx------ 6 opengauss opengauss      58 Jan 11 09:52 base
-rw------- 1 opengauss opengauss      72 Jan 15 12:28 gaussdb.state
drwx------ 2 opengauss opengauss    4096 Jan 15 12:28 global
-rw------- 1 opengauss opengauss     354 Jan 11 09:52 gs_gazelle.conf
drwx------ 3 opengauss opengauss      25 Jan 11 09:52 gs_profile
-rw------- 1 opengauss opengauss 4915200 Jan 11 09:52 gswlm_userinfo.cfg
drwx------ 3 opengauss opengauss      50 Jan 11 09:52 pg_audit
drwx------ 2 opengauss opengauss      26 Jan 11 09:52 pg_clog
drwx------ 2 opengauss opengauss      26 Jan 11 09:52 pg_csnlog
-rw------- 1 opengauss opengauss       0 Jan 15 12:28 pg_ctl.lock
drwx------ 2 opengauss opengauss       6 Jan 11 09:52 pg_errorinfo
-rw------- 1 opengauss opengauss    4504 Jan 11 09:52 pg_hba.conf
-rw------- 1 opengauss opengauss    1636 Jan 11 09:52 pg_ident.conf
drwx------ 4 opengauss opengauss      39 Jan 11 09:52 pg_llog
drwx------ 2 opengauss opengauss       6 Jan 11 09:52 pg_location
drwx------ 2 opengauss opengauss     206 Jan 15 12:28 pg_log
drwx------ 4 opengauss opengauss      36 Jan 11 09:52 pg_multixact
drwx------ 2 opengauss opengauss      26 Jan 15 12:28 pg_notify
drwx------ 3 opengauss opengauss      25 Jan 11 09:52 pg_perf
drwx------ 2 opengauss opengauss       6 Jan 11 09:52 pg_replslot
drwx------ 2 opengauss opengauss       6 Jan 11 09:52 pg_serial
drwx------ 2 opengauss opengauss       6 Jan 11 09:52 pg_snapshots
drwx------ 2 opengauss opengauss      25 Jan 15 12:28 pg_stat_tmp
drwx------ 2 opengauss opengauss       6 Jan 11 09:52 pg_tblspc
drwx------ 2 opengauss opengauss       6 Jan 11 09:52 pg_twophase
drwx------ 3 opengauss opengauss    4096 Jan 11 10:45 pg_xlog
-rw------- 1 opengauss opengauss   31540 Jan 11 09:52 postgresql.conf
-rw------- 1 opengauss opengauss    1024 Jan 11 09:52 postgresql.conf.lock
-rw------- 1 opengauss opengauss      64 Jan 15 12:28 postmaster.opts
-rw------- 1 opengauss opengauss      70 Jan 15 12:28 postmaster.pid
drwx------ 3 opengauss opengauss      25 Jan 11 09:52 sql_monitor
drwx------ 5 opengauss opengauss      67 Jan 15 12:28 undo
[opengauss@18aa9b346484 data]$ cp pg_hba.conf{,.bak}
[opengauss@18aa9b346484 data]$ cp postgresql.conf{,.bak}
[opengauss@18aa9b346484 data]$ vi pg_hba.conf
[opengauss@18aa9b346484 data]$ diff pg_hba.conf{,.bak}
89c89
< #local   all             all                                     trust
---
> local   all             all                                     trust
91c91
< #host    all             all             127.0.0.1/32            trust
---
> host    all             all             127.0.0.1/32            trust
93c93
< #host    all             all             ::1/128                 trust
---
> host    all             all             ::1/128                 trust
99,100d98
< host    all             all             0.0.0.0/0               sha256
< host    all             all             ::1/128                 sha256
[opengauss@18aa9b346484 data]$ vi postgresql.conf
[opengauss@18aa9b346484 data]$ diff postgresql.conf{,.bak}
68,69c68
< #listen_addresses = '127.0.0.1'
< listen_addresses = '*'
---
> listen_addresses = '127.0.0.1'
75,76c74
< #max_connections = 16                 # (change requires restart)
< max_connections = 3000                        # (change requires restart)
---
> max_connections = 16                  # (change requires restart)
90d87
< ssl = off
112d108
< password_encryption_type = 2
[opengauss@18aa9b346484 data]$ exit
logout
[root@18aa9b346484 /]# systemctl restart opengauss
[root@18aa9b346484 /]# systemctl status opengauss              
● opengauss.service - Start openGauss server
     Loaded: loaded (/usr/lib/systemd/system/opengauss.service; enabled; vendor preset: disabled)
     Active: active (exited) since Mon 2024-01-15 12:44:00 CST; 12s ago
    Process: 363 ExecStart=/usr/local/opengauss/script/autostart.sh (code=exited, status=0/SUCCESS)
   Main PID: 363 (code=exited, status=0/SUCCESS)
     CGroup: /docker/18aa9b3464849e15ee9d58de875f70de3b0e74749910c074412f22316104e0eb/system.slice/opengauss.service
             └─ 419 /usr/local/opengauss/bin/gaussdb -D /var/lib/opengauss/data

Jan 15 12:44:00 18aa9b346484 systemd[1]: Started Start openGauss server.
Jan 15 12:44:00 18aa9b346484 su[364]: (to opengauss) root on none
Jan 15 12:44:00 18aa9b346484 su[364]: pam_unix(su-l:session): session opened for user opengauss(uid=1000) by (uid=0)
Jan 15 12:44:01 18aa9b346484 su[364]: pam_unix(su-l:session): session closed for user opengauss
Jan 15 12:44:01 18aa9b346484 autostart.sh[363]: Start openGauss database success.

其中pg_hba.conf做以下修改

1、注释以下行:

#local ? all ? ? ? ? ? ? all ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? trust
#host ? ?all ? ? ? ? ? ? all ? ? ? ? ? ? 127.0.0.1/32 ? ? ? ? ? ?trust
#host ? ?all ? ? ? ? ? ? all ? ? ? ? ? ? ::1/128 ? ? ? ? ? ? ? ? trust
2、增加以下行:
host ? ?all ? ? ? ? ? ? all ? ? ? ? ? ? 0.0.0.0/0 ? ? ? ? ? ? ? sha256
host ? ?all ? ? ? ? ? ? all ? ? ? ? ? ? ::1/128 ? ? ? ? ? ? ? ? sha256

??postgresql.conf

1、注释以下行

#listen_addresses = '127.0.0.1'
#max_connections = 16 ? ? ? ? ? ? ? ? # (change requires restart)

2)、增加以下行
max_connections = 3000
ssl = off
password_encryption_type = 2

注,改?pg_hba.conf时注意加密算法要选sha256,网上有文档提示加密算法写md5,实测因为opengauss数据库内保存的密码已是sha256加密,写md5测试远程登录会一直提示:

gsql: FATAL: ?Invalid username/password,login denied.

提示用户名/密码无效,登录被拒绝。但实际上用户名密码是正确的,我在这里掉坑里了很久才爬上来,总算填上了。

9、 登录数据库增加远程登录维护管理员帐号(“opengauss”这个初始化帐号不能用于远程登录,必须要建)
[root@18aa9b346484 /]# su - opengauss
Last login: Mon Jan 15 12:44:00 CST 2024


Welcome to 5.10.0-60.18.0.50.oe2203.x86_64

System information as of time:  Mon Jan 15 12:47:08 CST 2024

System load:    0.03
Processes:      12
Memory used:    39.3%
Swap used:      10.5%
Usage On:       34%
Users online:   0
To run a command as administrator(user "root"),use "sudo <command>".
[opengauss@18aa9b346484 ~]$ gsql -d postgres -U opengauss -W "Huawei@123" -p 7654 -h 127.0.0.1                      
gsql ((GaussDB Kernel V500R002C00 build ) compiled at 2023-12-28 14:27:08 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=# CREATE USER dbuser IDENTIFIED BY 'Huawei@123';
CREATE ROLE
openGauss=# ALTER USER dbuser SYSADMIN;
ALTER ROLE
openGauss=# exit
openGauss-# \q
10、测试新建管理员帐号的登录情况
[opengauss@18aa9b346484 ~]$ gsql -d postgres -U dbuser -W 'Hqb@015955' -p 7654 -h 127.0.0.1   
gsql ((GaussDB Kernel V500R002C00 build ) compiled at 2023-12-28 14:27:08 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=> \l    
                               List of databases
   Name    |   Owner   | Encoding  | Collate | Ctype |    Access privileges    
-----------+-----------+-----------+---------+-------+-------------------------
 postgres  | opengauss | SQL_ASCII | C       | C     | 
 template0 | opengauss | SQL_ASCII | C       | C     | =c/opengauss           +
           |           |           |         |       | opengauss=CTc/opengauss
 template1 | opengauss | SQL_ASCII | C       | C     | =c/opengauss           +
           |           |           |         |       | opengauss=CTc/opengauss
(3 rows)

openGauss=> \q       

可见新建帐号登录使用正常。

11、退出容器,在主机系统上搭建客户端环境
[opengauss@18aa9b346484 ~]$ exit
logout
[root@18aa9b346484 /]# exit
exit
[root@localhost opengaussdata]# docker cp opengauss:/usr/local/opengauss /usr/local
[root@localhost opengaussdata]# tail -n2 ~/.bashrc
export PATH=/usr/local/opengauss/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/opengauss/lib:$LD_LIBRARY_PATH
[root@localhost opengaussdata]# source ~/.bashrc
[root@localhost opengaussdata]# gsql -d postgres -U dbuser -W "Huawei@123" -p 7654 -r -H 127.0.0.1
gsql: error while loading shared libraries: libboundscheck.so: cannot open shared object file: No such file or directory

出现报错 :gsql: error while loading shared libraries: libboundscheck.so: cannot open shared object file: No such file or directory

12、提示差“libboundscheck.so”库文件,准备相关文件
[root@localhost opengaussdata]# cd ~
[root@localhost ~]# docker exec -it opengauss /bin/bash                            


Welcome to 5.10.0-60.18.0.50.oe2203.x86_64

System information as of time:  Mon Jan 15 13:59:54 CST 2024

System load:    0.00
Processes:      10
Memory used:    42.1%
Swap used:      0%
Usage On:       35%
Users online:   0


[root@18aa9b346484 /]# find / -name libboundscheck*    
/usr/lib64/libboundscheck.so
/usr/share/licenses/libboundscheck
/usr/share/doc/libboundscheck
[root@18aa9b346484 /]# exit
exit 
[root@localhost ~]# docker cp opengauss:/usr/lib64/libboundscheck.so /usr/local/opengauss/lib/
[root@localhost ~]# gsql -d postgres -U dbuser -W "Huawei@123" -p 7654 -h 127.0.0.1
gsql: could not connect to server: 操作现在正在进行
        Is the server running on host "127.0.0.1" and accepting
        TCP/IP connections on port 7654?

出现报错:gsql: could not connect to server: 操作现在正在进行
? ? ? ? Is the server running on host "127.0.0.1" and accepting
? ? ? ? TCP/IP connections on port 7654??

13、连接不上服务端口,检查服务端口情况
[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE                      COMMAND             CREATED             STATUS              PORTS                              NAMES
18aa9b346484        opengauss2.1.0:oe2203sp3   "/sbin/init"        2 hours ago         Up 23 seconds       5432/tcp, 0.0.0.0:7654->7654/tcp   opengauss
[root@localhost ~]# telnet 127.0.0.1 7654
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: No route to host

容器运行正常,端口访问不到

14、重建容器进行测试
[root@localhost ~]# docker rm -f opengauss
opengauss
[root@localhost ~]# docker run -itd --restart=always --name opengauss  --privileged -p 7654:7654 -v /etc/localtime:/etc/localtime:ro -v /app/opengaussdata/opengauss:/var/lib/opengauss opengauss2.1.0:oe2203sp3 /sbin/init
WARNING: IPv4 forwarding is disabled. Networking will not work.
02e8ad00dad586868933998a53e633aa9ad24b6b35f2ae367489feba4d514a1b

出现警示:?IPv4 forwarding is disabled. Networking will not work.

15、配置启用IPV4转发
[root@localhost ~]# vi /etc/sysctl.conf 
[root@localhost ~]# grep net.ipv4.ip_forward /etc/sysctl.conf 
net.ipv4.ip_forward=1
[root@localhost ~]# sysctl -p
kernel.sysrq = 0
net.ipv4.ip_forward = 1
net.ipv4.conf.all.send_redirects = 0
...
16、重建容器测试
[root@localhost ~]# docker rm -f opengauss                                         
opengauss
[root@localhost ~]# docker run -itd --restart=always --name opengauss  --privileged -p 7654:7654 -v /etc/localtime:/etc/localtime:ro -v /app/opengaussdata/opengauss:/var/lib/opengauss opengauss2.1.0:oe2203sp3 /sbin/init
081b706a0e94b8a3aa5edbd24a774c7387c89ab0363934914992667f771ec395
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                      COMMAND             CREATED             STATUS              PORTS                              NAMES
081b706a0e94        opengauss2.1.0:oe2203sp3   "/sbin/init"        2 minutes ago       Up 27 seconds       5432/tcp, 0.0.0.0:7654->7654/tcp   opengauss
[root@localhost ~]# telnet 192.168.100.108 7654
Trying 192.168.100.108...
Connected to 192.168.100.108.
Escape character is '^]'.
^CConnection closed by foreign host.
[root@localhost ~]# gsql -d postgres -U dbuser -W 'Huawei@123' -p 7654 -h 192.168.100.108  
gsql ((GaussDB Kernel V500R002C00 build ) compiled at 2023-12-28 14:27:08 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=> exit
openGauss-> \q

没有警示信息了,数据库也正常连接成功。接下来就可以进行生产库、表的创建和程序测试了。

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