CentOS 7 安装 openGauss 3.0 企业版(单节点)

Source

openGauss 是一个开源的关系型数据库管理系统。

当前 openGauss 有三种版本,提供了 centos_x86_64、openeuler_aarch64 和 openeuler_x86_64 平台的安装包。

image20220429084329kiutegz.png

安装前准备

1、配置主机名

hostnamectl set-hostname node1

2、关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

3、禁用 SELinux

setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config

4、修改 /etc/sysctl.conf 文件

echo "net.ipv4.tcp_retries1 = 5" >> /etc/sysctl.conf
echo "net.ipv4.tcp_syn_retries = 5" >> /etc/sysctl.conf
echo "net.ipv4.tcp_synack_retries = 5" >> /etc/sysctl.conf
echo "net.ipv4.ip_local_port_range = 26000 65535" >> /etc/sysctl.conf
echo "net.ipv4.tcp_fin_timeout = 60" >> /etc/sysctl.conf
echo "net.ipv4.tcp_sack = 1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_timestamps = 1" >> /etc/sysctl.conf
echo "vm.extfrag_threshold = 500" >> /etc/sysctl.conf
echo "vm.overcommit_ratio = 90" >> /etc/sysctl.conf
sysctl -p

5、修改 /etc/security/limits.conf 文件

echo "* soft nofile 1000000" >> /etc/security/limits.conf
echo "* hard nofile 1000000" >> /etc/security/limits.conf

6、修改网卡 MTU

echo "8192" > /sys/class/net/ens32/mtu

7、设置 root 用户远程登录

/etc/ssh/sshd_config 文件中 #PermitRootLogin 前的注释去掉

sed -i 's/^#PermitRootLogin yes$/PermitRootLogin yes/' /etc/ssh/sshd_config
systemctl restart sshd.service

8、安装依赖

yum install -y bzip2 python3 libaio-devel flex bison ncurses-devel glibc-devel patch redhat-lsb-core readline-devel

9、创建安装目录

mkdir -p /opt/software/openGauss
chmod 755 -R /opt/software

下载安装包

1、下载安装包

方式一:先下载再上传

下载地址:https://opengauss.org/zh/download.html

下载 centos_x86_64 平台下的企业版:openGauss-3.0.0-CentOS-64bit-all.tar.gz

将安装包上传到安装目录:/opt/software/openGauss

方式二:直接下载

root 用户连接主机,切换到安装目录,然后用下面的命令下载。

curl -O https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.0.0/x86/openGauss-3.0.0-CentOS-64bit-all.tar.gz

2、解压安装包

2.1 解压安装包 openGauss-3.0.0-CentOS-64bit-all.tar.gz

tar zxf openGauss-3.0.0-CentOS-64bit-all.tar.gz

将会得到四个压缩包:

[root@node1 openGauss]# tar zxf openGauss-3.0.0-CentOS-64bit-all.tar.gz
[root@node1 openGauss]# ll
total 227604
-rw-r--r--. 1 root root 116068945 Apr 29 17:33 openGauss-3.0.0-CentOS-64bit-all.tar.gz
-rw-r--r--. 1 root root       105 Apr  1 18:26 openGauss-3.0.0-CentOS-64bit-cm.sha256
-rw-r--r--. 1 root root   6201097 Apr  1 18:26 openGauss-3.0.0-CentOS-64bit-cm.tar.gz
-rw-r--r--. 1 root root        65 Apr  1 18:25 openGauss-3.0.0-CentOS-64bit-om.sha256
-rw-r--r--. 1 root root  14139662 Apr  1 18:25 openGauss-3.0.0-CentOS-64bit-om.tar.gz
-rw-r--r--. 1 root root        65 Apr  1 18:26 openGauss-3.0.0-CentOS-64bit.sha256
-rw-r--r--. 1 root root  96246093 Apr  1 18:26 openGauss-3.0.0-CentOS-64bit.tar.bz2
-rw-------. 1 root root        65 Apr  1 18:24 upgrade_sql.sha256
-rw-------. 1 root root    383932 Apr  1 18:24 upgrade_sql.tar.gz
[root@node1 openGauss]#

2.2 继续解压 OM 安装包

tar zxf openGauss-3.0.0-CentOS-64bit-om.tar.gz

创建配置文件

openGauss 提供了 XML 文件模板,在安装包解压后的 script 目录中。

文件模板路径:script/gspylib/etc/conf/cluster_config_template.xml

root 用户连接主机,切换到安装目录,创建一个配置文件。

vi cluster_config.xml

文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
    <!-- openGauss整体信息 -->
    <CLUSTER>
        <PARAM name="clusterName" value="myGaussDB" />
        <PARAM name="nodeNames" value="node1" />
        <PARAM name="gaussdbAppPath" value="/opt/huawei/install/app" />
        <PARAM name="gaussdbLogPath" value="/var/log/omm" />
        <PARAM name="tmpMppdbPath" value="/opt/huawei/tmp" />
        <PARAM name="gaussdbToolPath" value="/opt/huawei/install/om" />
        <PARAM name="corePath" value="/opt/huawei/corefile" />
        <PARAM name="backIp1s" value="192.168.153.30" />
    </CLUSTER>
    <!-- 每台服务器上的节点部署信息 -->
    <DEVICELIST>
        <!-- node1上的节点部署信息 -->
        <DEVICE sn="node1_hostname">
            <PARAM name="name" value="node1" />
            <PARAM name="azName" value="AZ1" />
            <PARAM name="azPriority" value="1" />
            <!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
            <PARAM name="backIp1" value="192.168.153.30" />
            <PARAM name="sshIp1" value="192.168.153.30" />
            <!--dbnode-->
            <PARAM name="dataNum" value="1" />
            <PARAM name="dataPortBase" value="15400" />
            <PARAM name="dataNode1" value="/opt/huawei/install/data/dn" />
            <PARAM name="dataNode1_syncNum" value="0" />
        </DEVICE>
    </DEVICELIST>
</ROOT>

初始化安装环境

1、切换到工具脚本目录

cd /opt/software/openGauss/script

2、执行 gs_preinstall 脚本

./gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/cluster_config.xml

该脚本会自动完成一些安装前的准备工作:

  • 配置一些 Linux 内核参数。
  • 当 openGauss 安装用户、用户组不存在时,创建安装用户以及用户组(即:-U-G 参数指定的用户和用户组)。
  • 读取 openGauss 配置文件(即:-X 参数指定的配置文件)中的目录信息并创建,然后将目录权限授予安装用户。

执行过程:

[root@node1 script]# ./gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/cluster_config.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.
Setting host ip env
Successfully set host ip env.
Are you sure you want to create the user[omm] (yes/no)? yes
Please enter password for cluster user.
Password:
Please enter password for cluster user again.
Password:
Generate cluster user password files successfully.

Successfully created [omm] user on all nodes.
Preparing SSH service.
Successfully prepared SSH service.
Checking OS software.
Successfully check os software.
Checking OS version.
Successfully checked OS version.
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 "/opt/software/openGauss/script/gs_checkos -i A -h node1 --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]#

执行过程中需要确认创建 omm 用户并输入密码,密码至少包含 8 个字符,至少包含大写字母、小写字母、数字和特殊字符(~!@#$%^&*()-_=+|[{}];:,<.>/?)四类中的三类字符。

3、重启机器

有些 Linux 内核参数重启才会生效。

执行安装

切换到 openGauss 安装用户 omm,运行下面的命令:

gs_install -X /opt/software/openGauss/cluster_config.xml --gsinit-parameter="--locale=zh_CN.utf8"

其中,参数 --locale=zh_CN.utf8 用来指定数据库的区域和字符集。

安装时若不指定字符集,默认字符集为 SQL_ASCII,为简化和统一区域 loacle 默认设置为 C。

执行过程:

[omm@node1 ~]$ gs_install -X /opt/software/openGauss/cluster_config.xml --gsinit-parameter="--locale=zh_CN.utf8"
Parsing the configuration file.
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 /opt/huawei/install/app/share/sslcert/om
NO cm_server instance, no need to create CA for CM.
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.
Configuring pg_hba on all nodes.
Configuration is completed.
Successfully started cluster.
Successfully installed application.
end deploy..
[omm@node1 ~]$

在安装过程中会自动生成一个初始用户初始用户拥有系统的最高权限,能够执行所有操作。

若在安装时不指定初始用户名称,则初始用户与进行数据库安装的操作系统用户同名(即:本示例中的 omm)。

在执行过程中会提示输入初始用户的密码,若不指定,则密码为空。若初始用户密码为空,则除修改密码外无法执行其他SQL操作以及升级、扩容、节点替换等操作。

安装验证

1、检查数据库状态

使用下面的命令检查数据库状态是否正常:

gs_om -t status

命令执行结果:

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

cluster_name    : myGaussDB
cluster_state   : Normal
redistributing  : No

-----------------------------------------------------------------------
[omm@node1 ~]$

“cluster_state ”显示“Normal”表示数据库可正常使用。

2、连接默认数据库

数据库安装完成后,默认生成名称为 postgres 的数据库。第一次连接数据库时可以用 gsql 工具连接到此数据库。

gsql -d postgres -p 15400

其中,-d 参数指定的是数据库名称,-p 参数指定的是数据库节点的端口号,即 XML 配置文件中 dataPortBase 的值。

连接成功后的效果:

[omm@node1 ~]$
[omm@node1 ~]$ gsql -d  postgres -p 15400
gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:34 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=# \q
[omm@node1 ~]$

输入 \q 退出 gsql。

创建用户并赋权

初始用户是不能用来远程连接数据库的,所以若要远程连接数据库,则需要创建一个新的用户。

1、创建新用户

连接数据库,使用 create user ... 语句创建一个新用户。

[omm@node1 ~]$ gsql -d  postgres -p 15400
gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:34 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=# create user wzk with createdb password "1qaz!QAZ";
CREATE ROLE
openGauss=# \q
[omm@node1 ~]$

2、给这个新用户配置远程连接的权限

gs_guc reload -N all -I all -h "host  all  wzk  0.0.0.0/0  sha256"

其中:

  • -N all 表示 openGauss 的所有主机。

  • -I all 表示主机的所有实例。

  • -h 用来指定需要在 pg_hba.conf 文件中增加的规则。

    • all 表示允许客户端连接到任意的数据库。
    • wzk 表示连接数据库的用户。
    • 0.0.0.0/0 表示允许所有 IP 地址的客户端连接。也可以指定一个固定的 IP,比如:10.10.0.30/32,这样就限定了客户端的 IP。
    • sha256 表示连接时 wzk 用户的密码使用sha256算法加密。

配置完权限之后就可以在其他机器使用 Dbeaver 等工具连接数据库了。

image20220429112508qcxj9tl.png

相关资料

企业版安装 | openGauss

Dbeaver适配openGauss使用指导书