openGauss3.1.0企业版HA环境部署测试
前言
openGauss 是华为开源的一款高性能关系型数据库,这两年感觉 pg 系的数据库在国内慢慢火起来了,pg 的操作还是跟 mysql 和 oracle 略有差距,还得慢慢学,先从部署开始吧。对于我这种老鸟,本以为对着手册部署还不得一把过啊,没想到其中还是碰到了不少问题,折腾了多半天终于搞定了。
环境
信息 主机 1 主机 2
主机名 opengauss01 opengauss02
IP 地址 ... ...
os 版本 centos 7.9 centos 7.9
部署 openGauss
1、修改/etc/hosts
[root@opengauss01 /]# cat /etc/hosts
... localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
... opengauss01
... opengauss02
2、关闭防火墙
[root@opengauss01 /]# systemctl stop firewalld
[root@opengauss01 /]# systemctl disable firewalld
======》这两步一定要做哈,尤其是后面那个 disable,我在做的时候就忘了,后边重启了 os,防火墙又启动了,导致备库始终连不上主库的端口。
3、关闭 selinux
[root@opengauss01 /]# setenforce 0
[root@opengauss01 /]# cat /etc/selinux/config
SELINUX=disabled
SELINUXTYPE=targeted
4、 修改系统资源限制参数
[root@opengauss01 /]# echo "* soft stack 3072" >> /etc/security/limits.conf
[root@opengauss01 /]# echo "* hard stack 3072" >> /etc/security/limits.conf
[root@opengauss01 /]# echo "* soft nofile 1000000" >> /etc/security/limits.conf
[root@opengauss01 /]# echo "* hard nofile 1000000" >> /etc/security/limits.conf
[root@opengauss01 /]# echo "* soft nproc unlimited" >> /etc/security/limits.d/90-nproc.conf
5、关闭透明大页
[root@opengauss01 /]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@opengauss01 /]# echo never > /sys/kernel/mm/transparent_hugepage/defrag
======》这个是在线关闭,也可以从内核层面关闭。
6、下载企业版安装包,部署 HA 的话,就需要企业版的。
地址:https://opengauss.org/zh/download/
7、上传压缩包并解压
[root@opengauss02 opengauss]# tar -xvf openGauss-Lite-3.1.0-CentOS-x86_64.tar.gz
./dependency/
./dependency/libstdc++.so.6
./install.sh
./openGauss-Lite-3.1.0-CentOS-x86_64.bin
./openGauss-Lite-3.1.0-CentOS-x86_64.sha256
./opengauss_lite.conf
./uninstall.sh
./upgrade_common.sh
./upgrade_config.sh
./upgrade_errorcode.sh
./upgrade_GAUSSV5.sh
./upgrade_sql.sha256
./upgrade_sql.tar.gz
./version.cfg
8、安装依赖包 expect
yum install expect -y
======》这个在安装的时候需要。
9、安装 python3 环境
参考https://www.cnblogs.com/lemon-feng/p/11208435.html
./configure --prefix=/usr/local/python3 --enable-shared CFLAGS=-fPIC
======》注意安装 python3.6,我是 CentOS,不同的操作系统 python 版本也不一样。具体可以看下图,另外如果 configure 的时候不加--enable-shared CFLAGS=-fPIC,安装
openGauss 的时候会报错。
10、修改安装的配置文件
[root@opengauss01 conf]# cp cluster_config_template.xml cluster_config.xml
[root@opengauss02 opengauss]# cat cluster_config.xml
<DEVICE sn="opengauss02">
######节点2的主机名称 ######
<PARAM name="name" value="opengauss02"/>
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<PARAM name="backIp1" value="***.***.***.***"/>
<PARAM name="sshIp1" value="***.***.***.***"/>
</DEVICE>
[root@opengauss02 opengauss]# useradd omm -G dbgrp
[root@opengauss02 opengauss]# passwd omm
12、修改目录属组和权限
[root@opengauss01 bin]# chmod 755 -R /opengauss
[root@opengauss01 bin]# chown omm:dbgrp -R /opengauss
13、执行预检查
[root@opengauss01 /]# ./gs_preinstall -U omm -G dbgrp -X /opengauss_soft/cluster_config.xml
======》我在执行预检查的时候,碰到两次奇怪的问题:
A、 如果在预检查阶段有以下报错:
[FAILURE] opengauss01:
[GAUSS-50305] : The user is not matched with the user group.
[FAILURE] opengauss02:
[GAUSS-50305] : The user is not matched with the user group.
解决方案: 删除新建的 omm 用户,脚本会自动建 omm 用户,这一步挺奇怪,如果不执行第 11 步的创建 omm 用户,在执行预检查的时候又会报安装目录的属组不对。
B、 如果预检查阶段有以下报错:
[FAILURE] opengauss01:
[GAUSS-50200] : The /opengauss already exists. Please remove it. It should be a symbolic link to $GAUSSHOME if it exists
[FAILURE] opengauss02:
[GAUSS-50200] : The /opengauss already exists. Please remove it. It should be a symbolic link to $GAUSSHOME if it exists
解决方案:xml 中程序安装目录不能和其他目录在同一个层次下。这就是第 10 步中的 gaussdbAppPath 不要配置跟其他目录在同一个目录层中。
14、 查看检查的情况
[root@opengauss01 /]# /opengauss_soft/script/gs_checkos -i A -h opengauss01,opengauss02 –detail
15、执行安装脚本
[omm@opengauss01 script]$ ./gs_install -X /opengauss_soft/cluster_config.xml --gsinit-parameter="--encoding=UTF8"
注意需要 omm 用户执行,另外 database 密码需要至少大小写、数字、特殊字符中的三个。
16、查看集群状态
[omm@opengauss01 script]$ 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 opengauss01 ... 15400 6001 /opengauss/data/dn P Primary Normal
2 opengauss02 ... 15400 6002 /opengauss/data/dn S Standby Normal
======》节点 1 是 Primary Normal,节点 2 是 Standby Normal,这种状态是正确的。
======》如果有问题可以尝试卸载了重装
[omm@opengauss01 ~]$ gs_uninstall --delete-data
Checking uninstallation.
Successfully checked uninstallation.
Stopping the cluster.
Successfully stopped the cluster.
Successfully deleted instances.
Uninstalling application.
Successfully uninstalled application.
Uninstallation succeeded.
切换测试
1、执行 switchover
[omm@opengauss02 ~]$ gs_ctl switchover -D /opengauss/data/dn/
[2022-11-09 18:52:39.086][59376][][gs_ctl]: gs_ctl switchover ,datadir is /opengauss/data/dn
[2022-11-09 18:52:39.086][59376][][gs_ctl]: switchover term (1)
[2022-11-09 18:52:39.096][59376][][gs_ctl]: waiting for server to switchover........
[2022-11-09 18:52:44.180][59376][][gs_ctl]: done
[2022-11-09 18:52:44.180][59376][][gs_ctl]: switchover completed (/opengauss/data/dn)
======》这个命令要在当前的备库执行,不然没啥效果
2、确认主备状态
[omm@opengauss02 ~]$ 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 opengauss01 ... 15400 6001 /opengauss/data/dn P Standby Normal
2 opengauss02 ... 15400 6002 /opengauss/data/dn S Primary Normal
3、保存主备信息
[omm@opengauss02 ~]$ gs_om -t refreshconf
Generating dynamic configuration file for all nodes.
Successfully generated dynamic configuration file.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)