openGauss6.0.0(LTS)企业版搭建主备集群保姆级部署手册

举报
Gauss松鼠会小助手 发表于 2024/10/17 14:21:42 2024/10/17
【摘要】 openGauss 6.0.0(LTS)是openGauss 2024年9月发布的LTS版本,该版本生命周期为3年。当前文档是基于openGauss 6.0.0(LTS)企业版搭建的测试环境。

image.png

本文作者:沈阳
简介:目前从事于医疗信息化系统的维护。非常荣幸能在此与各位老师分享我在学习openGauss数据库时的一些见解和经验。
由于近几年的去“O”浪潮,要求我们必须要与时俱进,持续学习国产数据库。openGauss数据库学习,让我认识到要想学好国产数据库,必须学好openGauss数据库。openGauss数据库的学习,不仅深化了我对国产数据库技术的理解。还让我学习到openGauss充分运用智能化来优化运营效率以及提升用户体验方面的重要性。
本人积极参加社区活动、线下交流会、通过公众号等形式分享学习成果,让更多的人了解国产数据库的使用方法,为国产数据库社区贡献自己的力量,为信创国产化增砖添瓦。

前言:

openGauss 6.0.0(LTS)是openGauss 2024年9月发布的LTS版本,该版本生命周期为3年。当前文档是基于openGauss 6.0.0(LTS)企业版搭建的测试环境。

一、了解openGauss

1.1、openGauss概况

openGauss是一款全面友好开放,携手伙伴共同打造的企业级开源关系型数据库。openGauss提供面向多核架构的极致性能、全链路的业务、数据安全、基于AI的调优和高效运维的能力。openGauss深度融合华为在数据库领域多年的研发经验,结合企业级场景需求,持续构建竞争力特性。openGauss网站 (https://opengauss.org/zh/ ) 提供了有关openGauss软件的最新信息。

1.2、openGauss 6.0.0(LTS)是新一代数据库管理系统

openGauss 6.0.0版本在AI领域带来了一系列的新特性和升级,这些特性旨在提升数据库的智能化水平,使其更好地支持人工智能应用。以下是一些关键点:

  • AI集成:openGauss通过内置AI引擎实现了与多种AI框架和算法的无缝集成,包括TensorFlow、PyTorch等,允许用户直接在数据库中运行AI任务,无需将数据导出到外部平台。
  • AI优化:利用AI技术对数据库查询进行优化,通过对历史查询数据的分析,智能选择最优的查询计划,提高查询效率。
  • AI预测:提供了基于AI的预测功能,可以根据历史数据预测未来的趋势和变化,帮助用户提前做出决策。
  • AI安全:通过AI技术增强了数据库的安全性,能够识别异常行为、防止数据泄露,并提供智能化的安全建议。
  • 深度学习框架集成:openGauss内置了多种深度学习框架的接口,使得用户可以方便地在数据库中运行深度学习模型,实现图像识别、自然语言处理等任务。
  • 强化学习优化查询:采用强化学习技术,通过不断尝试和学习,找到最优的查询计划,从而提高查询效率。
  • 时间序列预测:利用时间序列分析技术,对历史数据进行分析和建模,预测未来的变化趋势,为用户提供决策支持。
  • AI安全引擎:集成了AI安全引擎,通过机器学习技术对数据库行为进行分析,识别异常行为,提供安全预警和建议。
  • 性能优化:在主备复制方面进行了优化,新版本在数据同步和故障恢复方面表现优异,能够满足大多数业务场景的需求。
  • 中文日志支持:新版本增加了中文日志支持功能,便于国内用户更直观地理解数据库的运行状态和错误信息。
  • 多版本支持:提供了企业版和轻量版两个安装版本,以满足不同用户的需求。
  • AI4DB能力:包括参数智能调优与诊断、慢SQL发现、索引推荐、时序预测、异常检测等,实现自调优、自监控、自诊断等功能。
  • DB4AI能力:兼容MADlib生态,支持70+算法,新增了XGBoost、prophet、GBDT等高级算法套件,统一SQL到机器学习的技术栈,实现从数据管理到模型训练的SQL语句“一键驱动”。
    这些新特性和升级显著提升了openGauss数据库在AI领域的能力,使其成为一个更加强大和灵活的数据管理平台。

二、初始化操作系统环境

2.1、安装准备

了解安装openGauss的环境准备和配置,主要步骤如下:

  • 了解安装流程
    本章节通过流程图简要介绍openGauss的安装流程。
  • 获取安装包
    openGauss开源社区上提供了安装包的获取方式。
  • 准备软硬件安装环境
    本章节描述安装前需要进行的环境准备。
  • 了解安装用户及用户组
    为了实现安装过程中安装帐户权限最小化,及安装后openGauss的系统运行安全性,安装脚本在安装过程中会自动按照用户指定内容创建安装用户,并将此用户作为后续运行和维护openGauss的管理员帐户。

2.2、 了解安装流程图

说明:流程图简要介绍openGauss的安装流程。

openGauss的安装流程如图1所示。
58af8eb89c8e5a8cdf74763d357ec753_20241016-1846483275307646976_512440.png
image.png

表 1 安装流程图说明
image.png

2.3、 准备软硬件安装环境

本章节描述安装前需要进行的环境准备。

  • 软硬件环境要求
  • 修改操作系统配置
  • 设置root用户远程登录

2.3.1、 硬件环境要求

表1列出了openGauss服务器应具备的最低硬件要求。在实际产品中,硬件配置的规划需考虑数据规模及所期望的数据库响应速度。请根据实际情况进行规划。

表 1 硬件环境要求
image.png

2.3.2、软件环境要求

表 2 软件环境要求
image.png
注意: 安装集群时,要求各个节点的python版本一致。

2.3.3、软件依赖要求

表 3 软件依赖要求

image.png

注意:

  • 1.关闭操作系统防火墙:
    为了在防火墙开启的状态下,确保openGauss的正常使用。用户需要将同openGauss相关的服务、协议、IP以及端口添加到openGauss各主机的防火墙白名单中。
  • 使用root用户进行操作,操作完成后请及时注销root用户,避免误操作。

2.4、 openGauss部署主机信息

image.png

说明:以下操作需在2台主机上执行(Node1、Node2)。

2.5、检查环境

操作系统版本:

[root@Node1 ~]#
[root@Node1 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@Node1 ~]#
[root@Node2 ~]#
[root@Node2 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@Node2 ~]#

CPU核数:

[root@Node1 ~]# cat /proc/cpuinfo | grep "physical id" | uniq | wc -l
4
[root@Node1 ~]#
[root@Node2 ~]# cat /proc/cpuinfo | grep "physical id" | uniq | wc -l
4
[root@Node2 ~]#

内存大小:

[root@Node2 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           3.7G        813M        334M        760M        2.6G        1.6G
Swap:          8.0G          0B        8.0G
[root@Node2 ~]#
[root@Node2 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           3.7G        813M        334M        760M        2.6G        1.6G
Swap:          8.0G          0B        8.0G
[root@Node2 ~]#

2.6、安装依赖

yum install -y bzip2 libaio-devel readline-devel expect wget

2.7、检查Python版本

[root@Node1 ~]# python --version
Python 2.7.5
[root@Node1 ~]#
[root@Node1 ~]# python3 --version
-bash: python3: command not found
[root@Node1 ~]#
[root@Node2 ~]# python --version
Python 2.7.5
[root@Node2 ~]#
[root@Node2 ~]# python3 --version
-bash: python3: command not found
[root@Node2 ~]#

说明:本例未安装Python3,需安装Python3.
代码如下:

yum install -y python3

2.8、关闭SELINUX

[root@Node1 ~]# sed -i  "s/SELINUX=enforcing/SELINUX=disabled/"  /etc/selinux/config
[root@Node1 ~]#
[root@Node2 ~]# sed -i  "s/SELINUX=enforcing/SELINUX=disabled/"  /etc/selinux/config
[root@Node2 ~]#

2.9、关闭RemoveIPC

说明:在各数据库节点上,关闭RemoveIPC。CentOS操作系统默认为关闭,可以跳过该步骤。

[root@Node1 ~]#
[root@Node1 ~]# cat>>/etc/systemd/logind.conf<<EOF
> RemoveIPC=no
> EOF
[root@Node1 ~]#

[root@Node1 ~]#
[root@Node1 ~]# cat>>/usr/lib/systemd/system/systemd-logind.service<<EOF
> RemoveIPC=no
> EOF
[root@Node1 ~]#
[root@Node2 ~]#
[root@Node2 ~]# cat>>/etc/systemd/logind.conf<<EOF
> RemoveIPC=no
> EOF
[root@Node2 ~]#

[root@Node2 ~]#
[root@Node2 ~]# cat>>/usr/lib/systemd/system/systemd-logind.service<<EOF
> RemoveIPC=no
> EOF
[root@Node2 ~]#

2.10、修改内核

sysctl -w kernel.sem="250 85000 250 330"

2.11、关闭防火墙

[root@Node1 ~]#
[root@Node1 ~]# systemctl disable firewalld.service
viceRemoved symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@Node1 ~]# systemctl stop firewalld.service
[root@Node1 ~]#
[root@Node2 ~]#
[root@Node2 ~]# systemctl disable firewalld.service
viceRemoved symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@Node2 ~]# systemctl stop firewalld.service
[root@Node2 ~]#

说明:目前仅支持在防火墙关闭的状态下进行安装。

2. 12、检查服务器主机时间

[root@Node1 ~]# date
Mon Oct 14 21:20:02 CST 2024
[root@Node1 ~]#
[root@Node2 ~]# date
Mon Oct 14 21:20:05 CST 2024
[root@Node2 ~]#

说明:如果当前时间与本地时间不一致,需修改。

2.13、关闭HISTORY记录

[root@Node1 ~]# sed  -i  “s/HISTSIZE=1000/HISTSIZE=0//etc/profile
[root@Node1 ~]#
[root@Node2 ~]# sed  -i  “s/HISTSIZE=1000/HISTSIZE=0//etc/profile
[root@Node2 ~]#

2.14、修改字符集

查看本地字符集:

[root@Node1 ~]# locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
[root@Node2 ~]# locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

修改字符集:

[root@Node1 ~]# 
[root@Node1 ~]# cat>> /etc/profile<<EOF
> export LANG=en_US.UTF08
> EOF
[root@Node1 ~]# 
[root@Node2 ~]# 
[root@Node2 ~]# cat>> /etc/profile<<EOF
> export LANG=en_US.UTF08
> EOF
[root@Node2 ~]# 

查看字符集:

[root@Node1 ~]#
[root@Node1 ~]# cat /etc/profile
# /etc/profile
unset i
unset -f pathmunge
export LANG=en_US.UTF-8
[root@Node1 ~]#
[root@Node2 ~]#
[root@Node2 ~]# cat /etc/profile
# /etc/profile
unset i
unset -f pathmunge
export LANG=en_US.UTF-8
[root@Node2 ~]#

2.15、修改hosts

cat>> /etc/hosts<<EOF
192.168.1.61 Node1
192.168.1.62 Node2
EOF

2.16、创建互信

rm -rf /home/root/.ssh
mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa
ssh-copy-id root@192.168.1.61
ssh-copy-id root@192.168.1.62

2.17、以上设置完毕,重启主机。

三、初始化openGauss部署环境

3.1、新建管理用户

groupadd dbgrp -g 4000
useradd omm -g 4000 -u 4000
echo "omm"|passwd --stdin omm

3.2、创建安装目录

目录规划:
image.png

代码如下:

mkdir /openGauss  /install
chown -R omm:dbgrp /openGauss  /install

3.3、配置sudo,使用root账户

注意:生产环境不建议开启。

sed -i.bak '100aomm   ALL=(ALL)       NOPASSWD:ALL' /etc/sudoers

3.4、下载安装包

说明:
下载地址:https://opengauss.org/zh/download/
选择openGauss 6.0.0 (LTS)企业版;
需登录社区账户才能下载。

1、下载示意图如下:

image.png官网下载示意图
de804cf42bc9a376dd5d439e75ba2fc3_20241016-1846483514374586368_512440.png

企业版地址:
https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/CentOS7/x86/openGauss-All-6.0.0-CentOS7-x86_64.tar.gz
代码如下:

[root@Node1 ~]# cd /install/
[root@Node1 install]# wget wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/CentOS7/x86/openGauss-All-6.0.0-CentOS7-x86_64.tar.gz
--2024-10-14 21:37:26--  http://wget/
Resolving wget (wget)... failed: Name or service not known.
wget: unable to resolve host address ‘wget’
--2024-10-14 21:37:26--  https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/CentOS7/x86/openGauss-All-6.0.0-CentOS7-x86_64.tar.gz
Resolving opengauss.obs.cn-south-1.myhuaweicloud.com (opengauss.obs.cn-south-1.myhuaweicloud.com)... 139.9.23.166, 121.37.63.47, 139.159.208.234, ...
Connecting to opengauss.obs.cn-south-1.myhuaweicloud.com (opengauss.obs.cn-south-1.myhuaweicloud.com)|139.9.23.166|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 153356080 (146M) [application/gzip]
Saving to: ‘openGauss-All-6.0.0-CentOS7-x86_64.tar.gz’

100%[===================================>] 153,356,080 9.45MB/s   in 15s

2024-10-14 21:37:42 (9.60 MB/s) - ‘openGauss-All-6.0.0-CentOS7-x86_64.tar.gz’ saved [153356080/153356080]

FINISHED --2024-10-14 21:37:42--
Total wall clock time: 16s
Downloaded: 1 files, 146M in 15s (9.60 MB/s)
[root@Node1 install]#

2、解压安装包

代码如下:

[root@Node1 install]# tar -xzvf openGauss-All-6.0.0-CentOS7-x86_64.tar.gz -C /openGauss/
openGauss-CM-6.0.0-CentOS7-x86_64.tar.gz
openGauss-OM-6.0.0-CentOS7-x86_64.tar.gz
openGauss-Server-6.0.0-CentOS7-x86_64.tar.bz2
openGauss-CM-6.0.0-CentOS7-x86_64.sha256
openGauss-OM-6.0.0-CentOS7-x86_64.sha256
openGauss-Server-6.0.0-CentOS7-x86_64.sha256
upgrade_sql.tar.gz
upgrade_sql.sha256

3、解压OM安装包

代码如下:

[root@Node1 install]# tar -zxvf /openGauss/openGauss-OM-6.0.0-CentOS7-x86_64.tar.gz -C /openGauss/
 ./lib/
./lib/pyasn1/
./lib/pyasn1/codec/
..............
./script/upgrade_checker/dev/developer_guide.md
./script/upgrade_checker/dev/og_controller.py
./script/upgrade_checker/dev/__init__.py
./script/upgrade_checker/dev/standard_vmap_gen.py
./script/upgrade_checker/verifier.py
./script/ssh-copy-id
./version.cfg
[root@Node1 install]#

4、拷贝cluster.xml集群配置文件

说明:
1、集群模板文件cluster_tmp.xml位于安装目录下的/openGauss/script/base_utils/template/cluster_tmp.xml
2、将cluster_tmp.xml重命名为cluster.xml
代码如下:

[root@Node1 install]# cp /openGauss/script/base_utils/template/cluster_tmp.xml /openGauss/script/base_utils/template/cluster.xml
[root@Node1 install]#

5、编辑cluster.xml集群配置文件

说明:根据实际环境修改。
代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
    <!-- openGauss整体信息 -->
    <CLUSTER>
        <!-- 数据库名称 -->
        <PARAM name="clusterName" value="Cluster1" />
        <!-- 数据库节点名称(hostname) -->
        <PARAM name="nodeNames" value="Node1,Node2" />
        <!-- 数据库安装目录-->
        <PARAM name="gaussdbAppPath" value="/openGauss/install/app" />
        <!-- 日志目录-->
        <PARAM name="gaussdbLogPath" value="/openGauss/log/omm" />
        <!-- 临时文件目录-->
        <PARAM name="tmpMppdbPath" value="/openGauss/tmp"/>
        <!-- 数据库工具目录-->
        <PARAM name="gaussdbToolPath" value="/openGauss/install/om" />
        <!-- 数据库core文件目录-->
        <PARAM name="corePath" value="/openGauss/corefile"/>
        <!-- 节点IP,与数据库节点名称列表一一对应 -->
        <PARAM name="backIp1s" value="192.168.1.61,192.168.1.62"/>
    </CLUSTER>
    <!-- 每台服务器上的节点部署信息 -->
    <DEVICELIST>
        <!-- 节点1上的部署信息 -->
        <DEVICE sn="Node1">
            <!-- 节点1的主机名称 -->
            <PARAM name="name" value="Node1"/>
            <!-- 节点1所在的AZAZ优先级 -->
            <PARAM name="azName" value="AZ1"/>
            <PARAM name="azPriority" value="1"/>
            <!-- 节点1IP,如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
            <PARAM name="backIp1" value="192.168.1.61"/>
            <PARAM name="sshIp1" value="192.168.1.61"/>

            <!--dn-->
            <PARAM name="dataNum" value="1"/>
            <PARAM name="dataPortBase" value="15400"/>
            <PARAM name="dataNode1" value="/openGauss/install/data/dn,Node2,/openGauss/install/data/dn"/>
            <PARAM name="dataNode1_syncNum" value="0"/>
        </DEVICE>

        <!-- 节点2上的节点部署信息,其中“name”的值配置为主机名称 -->
        <DEVICE sn="Node2">
            <!-- 节点2的主机名称 -->
            <PARAM name="name" value="Node2"/>
            <!-- 节点2所在的AZAZ优先级 -->
            <PARAM name="azName" value="AZ1"/>
            <PARAM name="azPriority" value="1"/>
            <!-- 节点2IP,如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
            <PARAM name="backIp1" value="192.168.1.62"/>
            <PARAM name="sshIp1" value="192.168.1.62"/>
        </DEVICE>
    </DEVICELIST>
</ROOT>

四、opeGauss部署

4.1、检查部署环境

说明:主要用于检查操作系统、控制参数、磁盘配置等内容,并对系统控制参数、I/O配置、网络配置和THP服务等信息进行配置。
代码如下:

[root@Node1 script]# /openGauss/script/gs_checkos -i A -h Node1,Node2 --detail
Checking items:
    A1. [ OS version status ]                                   : Normal
        [Node1]
        centos_7.9.2009_64bit
        [Node2]
        centos_7.9.2009_64bit

    A2. [ Kernel version status ]                               : Normal
        The names about all kernel versions are same. The value is "3.10.0-1160.el7.x86_64".
    A3. [ Unicode status ]                                      : Normal
        The values of all unicode are same. The value is "locale:".
    A4. [ Time zone status ]                                    : Normal
        The informations about all timezones are same. The value is "+0800".
    A5. [ Swap memory status ]                                  : Warning
        [Node1]
SwapMemory 8589930496 TotalMemory 3953958912

        [Node2]
SwapMemory 8589930496 TotalMemory 3953967104


    A6. [ System control parameters status ]                    : Warning
        [Node1]
        Warning reason: variable 'net.ipv4.tcp_retries1' RealValue '3' ExpectedValue '5'.
        Warning reason: variable 'net.ipv4.tcp_syn_retries' RealValue '6' ExpectedValue '5'.
        Check_SysCtl_Parameter warning.

        [Node2]
        Warning reason: variable 'net.ipv4.tcp_retries1' RealValue '3' ExpectedValue '5'.
        Warning reason: variable 'net.ipv4.tcp_syn_retries' RealValue '6' ExpectedValue '5'.
        Check_SysCtl_Parameter warning.


    A7. [ File system configuration status ]                    : Warning
        [Node2]
        Warning reason: variable 'open files' RealValue '1024' ExpectedValue '1000000'
        Warning reason: variable 'max user processes' RealValue '14999' ExpectedValue 'unlimited'

        [Node1]
        Warning reason: variable 'open files' RealValue '1024' ExpectedValue '1000000'
        Warning reason: variable 'max user processes' RealValue '14999' ExpectedValue 'unlimited'


    A8. [ Disk configuration status ]                           : Normal
        The value about XFS mount parameters is correct.
    A9. [ Pre-read block size status ]                          : Normal
        The value about Logical block size is correct.
    A10.[ IO scheduler status ]                                 : Normal
        The value of IO scheduler is correct.
    A11.[ Network card configuration status ]                   : Warning
        [Node2]
BondMode Null
        Warning reason: network 'ens33' 'mtu' RealValue '1500' ExpectedValue '8192'

        [Node1]
BondMode Null
        Warning reason: network 'ens33' 'mtu' RealValue '1500' ExpectedValue '8192'


    A12.[ Time consistency status ]                             : Warning
        [Node1]
        Neither nptd nor chrony was detected on machine and local time is "2024-10-14 22:13:29".
        [Node2]
        Neither nptd nor chrony was detected on machine and local time is "2024-10-14 22:13:29".

    A13.[ Firewall service status ]                             : Normal
        The firewall service is stopped.
    A14.[ THP service status ]                                  : Abnormal
        [Node1]
The THP service status RealValue 'enabled' ExpectedValue 'disabled'.

        [Node2]
The THP service status RealValue 'enabled' ExpectedValue 'disabled'.


Total numbers:14. Abnormal numbers:1. Warning numbers:5.
Do checking operation finished. Result: Abnormal.
[root@Node1 script]#

4.2、预安装

说明:安装前置脚本gs_preinstall可以协助用户自动完成如下的安装环境准备工作:

  • 自动设置Linux内核参数以达到提高服务器负载能力的目的。这些参数直接影响数据库系统的运行状态,请仅在确认必要时调整。openGauss所设置的Linux内核参数取值请参见配置操作系统参数。
  • 自动将openGauss配置文件、安装包拷贝到openGauss主机的相同目录下。
  • openGauss安装用户、用户组不存在时,自动创建安装用户以及用户组。
  • 读取openGauss配置文件中的目录信息并创建,将目录权限授予安装用户。
    代码如下:
[root@Node1 script]# ./gs_preinstall -U omm -G dbgrp -X /openGauss/script/base_utils/cluster.xml
Parsing the configuration file.
Successfully parsed the configuration file.
Installing the tools on the local node.
Successfully installed the tools on the local node.
Are you sure you want to create trust for root (yes/no)?yes
Please enter password for root
Please enter password for current user[root].
Password:
Checking network information.
All nodes in the network are Normal.
Successfully checked network information.
Creating SSH trust.
Creating the local key file.
Successfully created the local key files.
Appending local ID to authorized_keys.
Successfully appended local ID to authorized_keys.
Updating the known_hosts file.
Successfully updated the known_hosts file.
Appending authorized_key on the remote node.
Successfully appended authorized_key on all remote node.
Checking common authentication file content.
Successfully checked common authentication content.
Distributing SSH trust file to all node.
Distributing trust keys file to all node successfully.
Successfully distributed SSH trust file to all node.
Verifying SSH trust on all hosts.
Verifying SSH trust on all hosts by ip.
Successfully verified SSH trust on all hosts by ip.
Verifying SSH trust on all hosts by hostname.
Successfully verified SSH trust on all hosts by hostname.
Successfully verified SSH trust on all hosts.
Start set cron for root
Successfully to set cron for root
Successfully created SSH trust.
Successfully created SSH trust for the root permission user.
Setting host ip env
Successfully set host ip env.
Distributing package.
Begin to distribute package to tool path.
Successfully distribute package to tool path.
Begin to distribute package to package path.
Successfully distribute package to package path.
Successfully distributed package.
Are you sure you want to create the user[omm] and create trust for it (yes/no)? yes
Preparing SSH service.
Successfully prepared SSH service.
Installing the tools in the cluster.
Successfully installed the tools in the cluster.
Checking hostname mapping.
Successfully checked hostname mapping.
Creating SSH trust for [omm] user.
Please enter password for current user[omm].
Password:
Checking network information.
All nodes in the network are Normal.
Successfully checked network information.
Creating SSH trust.
Creating the local key file.
Successfully created the local key files.
Appending local ID to authorized_keys.
Successfully appended local ID to authorized_keys.
Updating the known_hosts file.
Successfully updated the known_hosts file.
Appending authorized_key on the remote node.
Successfully appended authorized_key on all remote node.
Checking common authentication file content.
Successfully checked common authentication content.
Distributing SSH trust file to all node.
Distributing trust keys file to all node successfully.
Successfully distributed SSH trust file to all node.
Verifying SSH trust on all hosts.
Verifying SSH trust on all hosts by ip.
Successfully verified SSH trust on all hosts by ip.
Successfully verified SSH trust on all hosts.
Start set cron for omm
Successfully to set cron for omm
Successfully created SSH trust.
Successfully created SSH trust for [omm] user.
Checking OS software.
Successfully check OS software.
Checking OS version.
Successfully checked OS version.
Checking cpu instructions.
Successfully checked cpu instructions.
Creating cluster's path.
Successfully created cluster's path.
Set and check OS parameter.
Setting OS parameters.
Successfully set OS parameters.
Warning: Installation environment contains some warning messages.
Please get more details by "/openGauss/script/gs_checkos -i A -h Node1,Node2 -X /openGauss/script/base_utils/cluster.xml --detail".
Set and check OS parameter completed.
Preparing CRON service.
Successfully prepared CRON service.
Setting user environmental variables.
Successfully set user environmental variables.
Setting the dynamic link library.
Successfully set the dynamic link library.
Setting Core file
Successfully set core path.
Setting pssh path
Successfully set pssh path.
Setting Cgroup.
Successfully set Cgroup.
Set ARM Optimization.
No need to set ARM Optimization.
Fixing server package owner.
Setting finish flag.
Successfully set finish flag.
Preinstallation succeeded.
[root@Node1 script]#

注意事项

  • 用户需要检查上层目录权限,保证安装用户对安装包和配置文件目录读写执行的权限。
  • xml文件中各主机的名称与IP映射配置正确。
  • 使用root或普通用户执行gs_preinstall命令。
  • 使用root用户执行gs_preinstall会清理/etc/hosts中的openGauss映射信息,可能存在已部署数据库连接丢失风险,可以在安装结束后手动添加其它数据库映射至/etc/hosts文件中。
  • gs_preinstall指定的用户不支持使用-d手动选定家目录,仅支持系统默认创建的/home下和用户同名的/home目录。
  • 本产品支持同一操作系统大版本下的小版本混合部署,其支持列表如下:CentOS 6.4/6.5/6.6/6.7/6.8/6.9、CentOS 7.0/7.1/7.2/7.3/7.4、openEuler

4.3、使用gs_install部署集群

说明:
前提条件

  • 已成功执行前置脚本gs_preinstall。
  • 用户需确保各个节点上的locale保持一致。
  • 需要使用前置时设置的openGauss用户进行安装操作。
  • openGauss安装部署,要求用户指定配置文件,配置文件中会指定程序安装路径、实例数据目录、主备关系、实例数、各实例的业务IP端口等信息。
    语法如下:
gs_install -X XMLFILE [--gsinit-parameter="PARAMETER" [...]] [--dn-guc="PARAMETER" [...]] [--alarm-component=ALARMCOMPONENT] [--time-out=SECS] [-l LOGFILE] [--enable-perf-config] [--dorado-cluster-mode="PARAMETER"] 

参数说明:

  • -X openGauss配置文件。取值范围:xml配置文件。
  • -l 指定安装日志文件及日志文件存放的路径。当不明确指定-l,但在XML文件中配置了gaussdbLogPath时,默认值为“gaussdbLogPath的值、用户名和om/gs_install-YYYY-MM-DD_hhmmss.log”的组合。
  • –gsinit-parameter=PARAM 数据实例参数指定。取值范围请参见gs_initdb的参数说明,其中对-A、-D、-U、-C、-X参数的设置不生效。
  • –dn-guc=PARAM 配置参数。 取值范围请参见gs_guc的参数说明。
  • –time-out=SECS 启动超时等待时间。单位:s。若–time-out取值过小,有可能会因为需要启动的实例数过多而引起超时。若在超时时间内启动不成功,则会报错启动超时,但是openGauss会在后台继续启动。可以等待一段时间后,查询openGauss状态,检查openGauss是否启动成功。
    取值范围:正整数,若无特殊需求,不需要配置该参数,系统会自动调整超时时间。
  • –alarm-component=alarm_component 指定告警上报组件的绝对路径。
  • –enable-perf-config 在install结束后,调用gs_perfconfig调整数据库配置,以使openGauss获得比较好的性能。
  • –dorado-cluster-mode=PARAM 指定存储设备的集群模式,dorado-cluster-mode 主机群or备机群。
    取值范围:
  •  primary:以资源池化dorado双集群主集群安装。
    
  • standby:以资源池化dorado双集群备集群安装。
    
  • -?, --help 显示帮助信息。
  • -V, --version 显示版本号信息。
    代码如下
[root@Node1 script]# su omm
[omm@Node1 script]$ gs_install -X /openGauss/script/base_utils/template/cluster.xml
Parsing the configuration file.
Successfully checked gs_uninstall on every node.
Check preinstall on every node.
Successfully checked preinstall on every node.
Creating the backup directory.
Successfully created the backup directory.
begin deploy..
Installing the cluster.
begin prepare Install Cluster..
Checking the installation environment on all nodes.
begin install Cluster..
Installing applications on all nodes.
Successfully installed APP.
begin init Instance..
encrypt cipher and rand files for database.
Please enter password for database:
Please repeat for database:
begin to create CA cert files
The sslcert will be generated in /openGauss/install/app/share/sslcert/om
NO cm_server instance, no need to create CA for CM.
Non-dss_ssl_enable, no need to create CA for DSS
Cluster installation is completed.
Configuring.
Deleting instances from all nodes.
Successfully deleted instances from all nodes.
Checking node configuration on all nodes.
Initializing instances on all nodes.
Updating instance configuration on all nodes.
Check consistence of memCheck and coresCheck on database nodes.
Successfully check consistence of memCheck and coresCheck on all nodes.
Configuring pg_hba on all nodes.
Configuration is completed.
The cluster status is Normal.
Successfully started cluster.
Successfully installed application.
end deploy..
[omm@Node1 script]$

五、检查安装情况

5.1、使用omm用户身份登录服务器,检查服务状态

说明:

  • 执行如下命令检查数据库状态是否正常,“cluster_state ”显示“Normal”表示数据库可正常使用。
  • 语法:gs_om -t status
    Node1:
[omm@Node1 ~]$ gs_om -t status
-----------------------------------------------------------------------

cluster_name    : Cluster1
cluster_state   : Normal
redistributing  : No

-----------------------------------------------------------------------
[omm@Node1 ~]$

Node2:

[omm@Node2 ~]$ gs_om -t status
-----------------------------------------------------------------------

cluster_name    : Cluster1
cluster_state   : Normal
redistributing  : No

-----------------------------------------------------------------------
[omm@Node2 ~]$

5.2、检查openGauss集群状态

[omm@Node1 data]$ gs_om -t status --detail
[   Cluster State   ]

cluster_state   : Normal
redistributing  : No
current_az      : AZ_ALL

[  Datanode State   ]

    node node_ip         port      instance                           state
-------------------------------------------------------------------------------------------
1  Node1 192.168.1.61    15400      6001 /openGauss/install/data/dn   P Primary Normal
2  Node2 192.168.1.62    15400      6002 /openGauss/install/data/dn   S Primary Normal
[omm@Node1 data]$

5.3、使用omm用户身份登录数据库

说明:

  • 数据库安装完成后,默认生成名称为postgres的数据库。第一次连接数据库时可以连接到此数据库。
  • 其中postgres为需要连接的数据库名称,15400为数据库主节点的端口号,即XML配置文件中的dataPortBase的值。请根据实际情况替换。
  • 语法:gsql -d postgres -p 15400
    Node1:
[omm@Node1 ~]$ gsql -d postgres -p 15400
gsql ((openGauss 6.0.0 build aee4abd5) compiled at 2024-09-29 18:38:08 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=#

Node2:

[omm@Node2 ~]$ gsql -d postgres -p 15400
gsql ((openGauss 6.0.0 build aee4abd5) compiled at 2024-09-29 18:38:08 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=#

5.4、使用omm用户身份登录数据库,创建管理用户、表空间、数据库、导入测试数据

5.4.1、创建表空间存储目录

mkdir -p /openGauss/tablespace
chown -R  omm:dbgrp /openGauss/tablespace
chmod -R 750 /openGauss/tablespace

5.4.2、登录openGauss数据库,创建用户sy,创建表空间cssd、数据库cssdserver

[omm@Node1 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 6.0.0 build aee4abd5) compiled at 2024-09-29 18:38:08 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=# create user sy password 'Sy@123456';
CREATE ROLE
openGauss=# create tablespace cssd owner sy location '/openGauss/tablespace';
CREATE TABLESPACE
openGauss=#
openGauss=# create database cssdserver owner sy tablespace cssd ;
CREATE DATABASE
openGauss=#

5.4.3、实现内网访问openGauss

说明:
需要修改postgresql.conf、pg_hba.conf相关配置。

1、修改pg_hba.conf

说明:
默认用户omm无法远程登录,需要创建使用用户sy登录,密码验证方式为sha256。

vi /openGauss/install/data/dn/pg_hba.conf
#####  TYPE  DATABASE        USER            ADDRESS                 METHOD

#####  "local" is for Unix domain socket connections only
local   all             all                                     trust
host    all    sy    192.168.1.61/32    sha256
host    all    sy    192.168.1.62/32    sha256
##### IPv4 local connections:
host    all             all             127.0.0.1/32            trust
host    all    all    192.168.1.61/32    sha256
host    all    all    192.168.1.62/32    sha256
host    all    all    0.0.0.0/0    sha256
#####  IPv6 local connections:
host    all             all             ::1/128                 trust
#####  Allow replication connections from localhost, by a user with the
#####  replication privilege.
##### local   replication     sy        127.0.0.1/32            trust
##### host    replication     sy        ::1/128                 trust
host    replication    sy    192.168.1.61/32    sha256
host    replication    sy    192.168.1.62/32    sha256
host    replication    sy    0.0.0.0/0    sha256

2、修改postgresql.conf

说明:

  • 密码验证方式为1,md5、sha256都支持
  • 建议开启归档,创建归档目录;
  • 修改密码策略后,需修改密码才能登录。
建议开启归档:
mkdir -p /openGauss/archive
chmod -R 750 /openGauss/archive/
chown -R omm:dbgrp /openGauss/archive/
vi /openGauss/install/data/dn/postgresql.conf


password_encryption_type =1


archive_mode = on               # allows archiving to be done
                                # (change requires restart)
archive_command = 'test ! -f /openGauss/archive/%f && cp %p /openGauss/archive/%f'  

5.5、使用navicat访问openGauss

说明:

  • Server:192.168.1.61
  • DataBase:cssdserver
  • Port: 15400
  • UserName:sy
  • Password:Sy@123456
    登录如下图:

fae5635a779d369df086b56f1eba797f_20241016-1846485837779927040_512440.png

5bf8aca7d5765ce53c018e91494081cb_20241016-1846485633022394368_512440.png

六、相关问题

6.1、错误代码:ascii’ codec can’t decode byte 0xe2 in position 0: ordinal not in range(128)

代码如下:

[GAUSS-51632] : Failed to do python3 '/opt/software/openGauss/script/local/LocalCheckOS.py' -t Check_Firewall_Service -l '/var/log/gaussdb/omm/om/gs_local.log' . Error: 
'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

解决:

[root@enmoedu1 om]# export LC_CTYPE=en_US.UTF-8

6.2、错误代码:[GAUSS-50102] : The /openGauss/log/omm/omm is not writable for omm.

代码如下:

Checking OS version.
Successfully checked OS version.
Checking cpu instructions.
Successfully checked cpu instructions.
Creating cluster's path.
[SUCCESS] Node1:
[FAILURE] Node2:
[GAUSS-50102] : The /openGauss/log/omm/omm is not writable for omm.

解决方案

[root@Node2 ~]# chown -R omm:dbgrp /openGauss/log/omm/omm
[root@Node2 ~]# chmod -R 750 /openGauss/log/omm/omm

七、总结

openGauss数据库主备集群部署模式,可以提供高可用性和数据冗余,以防止单点故障导致的数据丢失。在主备集群中,主节点负责处理所有的写操作,而备节点则同步主节点的数据变化,并在主节点出现故障时接管服务。

7.1、主备同步机制

openGauss的主备同步通常是通过流复制来实现的。在启动备节点时,备节点会启动一个startUp线程,尝试连接到主节点并开始接收和应用主节点的日志变更(WAL,Write-Ahead Logging)。一旦连接成功,备节点会触发启动wal receiver线程,随后wal receiver线程会发送信号启动wal sender线程。wal receiver线程与主库完成身份验证和日志一致性校验后,主库进入WalSndLoop开始日志复制循环。

7.2、故障转移和角色切换

当主节点发生故障时,集群管理会感知并基于Quorum协议进行选主仲裁。集群管理服务(CMS)会周期性地检测数据库的主备状态,如果发现主机不能正常提供服务,则会触发选主仲裁。CMS会根据当前数据库状态进行仲裁逻辑的推进,最终选出一个新的主节点来接管服务。

7.3、资源池化和容灾能力

openGauss还支持资源池化主备双集群容灾,这种模式可以通过网络流复制或基于特定存储设备的同步复制来实现。资源池化双集群容灾通过多种同步方式将主集群的xlog日志同步至备集群,备集群通过回放来自主集群的xlog实现数据一致性,以便于主集群发生严重故障时,备集群可以及时接管主集群业务1。

7.4、高可用特性

openGauss的高可用特性不仅限于主备同步,还包括逻辑复制、物理备份、作业失败自动重试、极致RTO(Recovery Time Objective)、级联备机、延时回放、备机增加删除、延迟进入最大可用模式、并行逻辑解码、DCF(Data Center Failover)、CM(Cluster Manager)等。这些特性共同构成了openGauss强大的高可用能力,确保了数据库服务的连续性和数据的安全性。

综上所述,openGauss主备集群通过流复制机制实现数据的实时同步,并通过集群管理服务提供故障转移和角色切换的自动化支持,从而达到高可用性的目标。此外,openGauss还提供了一系列高可用特性,以适应不同的业务需求和容灾场景。

openGauss6.0.0(LTS)版本已经发布,亲爱的小伙伴们,赶快体验吧!!!

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。