【我与openGauss的故事openGauss 5.0企业版主从部署,实战狂飙

2023年 9月 25日 80.0k 0

【我与openGauss的故事】openGauss 5.0企业版主从部署,实战狂飙

前言

2023年4月1日, openGauss 5.0正式发布,本博客介绍了openGauss 5.0企业版主从部署的详细过程。

01 openGauss 5.0

2023年4月1日,openGauss 5.0.0是openGauss发布的第三个LTS版本,版本生命周期为3年。openGauss 5.0.0版本与之前的版本功能特性保持兼容,在内核能力、工具链、兼容性方面全面增强。

官网下载地址:

https://opengauss.org/zh/download/

02 环境准备

操作系统

CentOS Linux release 7.9.2009 (Core)

主机IP

主库:hostnamectl set-hostname opengauss5M

备库:hostnamectl set-hostname opengauss5B

内存

[root@Jeames ~]# free -m
total used free shared buff/cache available
Mem: 3020 281 2630 7 107 2684
Swap: 10239 0 10239
字符集确认

字符集确认

[root@opengauss5m ~]# 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"

可以在/etc/profile文件中添加export.UTF-8

软件依赖要求

下列依赖软件的默认安装包,若不存在下列软件,可参看软件对应的建议版本。

2.1 关闭SeLinux

sed -i ‘s/^SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config
setenforce 0

注:主库和备库同时修改,然后重启服务器
[root@opengauss5m ~]# /usr/sbin/sestatus
SELinux status: disabled

2.2 关闭防火墙

注:主备库均做如下操作

1.检查防火墙是否关闭
[root@opengauss5m ~]# systemctl status firewalld
若防火墙状态显示为active (running),则表示防火墙未关闭
若防火墙状态显示为inactive (dead),则无需再关闭防火墙

2.关闭防火墙并禁止开机重启
systemctl disable firewalld.service
systemctl stop firewalld.service

2.3 关闭RemoveIPC

1.修改/etc/systemd/logind.conf文件中的“RemoveIPC”值为“no”
vi /etc/systemd/logind.conf
RemoveIPC=no

##重新加载配置参数
systemctl daemon-reload
systemctl restart systemd-logind

2.4 设置root用户远程登录

vi /etc/ssh/sshd_config
## 将“PermitRootLogin”改为“yes”
PermitRootLogin yes

## 注释掉“Banner”所在的行
#Banner none

## 重启生效
systemctl restart sshd.service

2.5 yum安装依赖

注:两个节点均做如下操作

##创建挂载目录
mkdir /cdrom

[root@opengauss5m ~]# ls -lrt /opt/CentOS-7-x86_64-DVD-2009.iso
-rw-r--r-- 1 root root 4712300544 Apr 8 09:28 /opt/CentOS-7-x86_64-DVD-2009.iso

##挂载目录
mount -o loop /opt/CentOS-7-x86_64-DVD-2009.iso /cdrom

[root@opengauss5m ~]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.5G 0 1.5G 0% /dev
tmpfs tmpfs 1.5G 0 1.5G 0% /dev/shm
tmpfs tmpfs 1.5G 11M 1.5G 1% /run
tmpfs tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 96G 6.8G 89G 8% /
/dev/sda1 xfs 1.1G 158M 906M 15% /boot
tmpfs tmpfs 297M 0 297M 0% /run/user/0
/dev/loop0 iso9660 4.8G 4.8G 0 100% /cdrom

##yum源配置文件
[root@opengauss5m ~]# cd /etc/yum.repos.d/
[root@opengauss5m yum.repos.d]# mkdir bak
[root@opengauss5m yum.repos.d]# mv CentOS* bak

[root@opengauss5m yum.repos.d]# vi local.repo
[base-local]
name=CentOS7-local
baseurl=file:///cdrom
enabled=1
gpgcheck=0

#清空并重载yum
yum clean all
yum makecache
##测试yum安装
yum -y install tree

##安装依赖包
yum install libaio-devel flex bison ncurses-devel glibc-devel patch redhat-lsb-core readline-devel libnsl -y
yum install net-tools -y

2.6 host设置

注:主备2个节点均做如下设置

##主库
[root@opengauss5m ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.6.10 opengauss5m

##备库
[root@opengauss5b ~]# more /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.6.11 opengauss5b

2.7 Python安装

CentOS:支持Python 3.6.X,python需要通过--enable-shared方式编译
1.依赖包安装
[root@opengauss5m ~]# yum install -y zlib*
[root@opengauss5m ~]# rpm -qa | grep zlib
zlib-1.2.7-18.el7.x86_64
zlib-devel-1.2.7-18.el7.x86_64

2.安装包下载
python官网 https://www.python.org/downloads/release/python-3615/下载安装包即可
安装包为:Python-3.6.15.tgz

3.解压并编译
cd /opt
tar -zxvf Python-3.6.15.tgz
cd Python-3.6.15/
./configure --prefix=/usr/local/python3 --enable-shared

make
make install
注意:make编译时间比较长,耐心等待

4.OS上设置python的软连接
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip

5.环境校验
[root@opengauss5m ~]# python -V
python: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory

出现以上报错处理方法,libpython3.6m.so.1.0复制到/usr/lib64/目录下即可

[root@opengauss5m ~]# find / -name libpython3.6m.so.1.0
/usr/local/python3/lib/libpython3.6m.so.1.0
/opt/Python-3.6.15/libpython3.6m.so.1.0

[root@opengauss5m ~]# cp /usr/local/python3/lib/libpython3.6m.so.1.0 /usr/lib64

[root@opengauss5m ~]# python3 -V
Python 3.6.15

[root@opengauss5m ~]# python
Python 3.6.15 (default, Apr 8 2023, 11:45:45)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

03 目录创建

##创建存放安装包的目录
mkdir -p /opt/software/openGauss
chmod 755 -R /opt/software

##创建数据库软件相关目录
mkdir -p /opt/openGauss
chmod -R 755 /opt/openGauss

04 安装包解压

安装包下载地址: https://opengauss.org/zh/download/
注:从以上网站下载企业版即可

上传到主库所在的目录:/opt/software/openGauss

##解压安装包
cd /opt/software/openGauss
tar -zxvf openGauss-5.0.0-CentOS-64bit-all.tar.gz
tar -zxvf openGauss-5.0.0-CentOS-64bit-om.tar.gz

05 XML配置文件

安装openGauss前需要创建cluster_config.xml文件。cluster_config.xml文件包含部署openGauss的服务器信息、安装路径、IP地址以及端口号等。
用于告知openGauss如何部署。用户需根据不同场景配置对应的XML文件。

本次部署以一主一备的方式创建XML配置文件

## 配置数据库名称及各项目录
[root@opengauss5m ~]# find / -name cluster_config_template.xml
/opt/software/openGauss/script/gspylib/etc/conf/cluster_config_template.xml
说明:获取XML文件模板,按照实际环境配置

编辑配置XML文件:
vi /opt/software/openGauss/cluster_config.xml

06 初始化安装

采用交互模式执行前置,并在执行过程中自动创建操作系统root用户互信和omm用户互信
#主库执行即可
[root@opengauss5m ~]# cd /opt/software/openGauss/script
[root@opengauss5m script]# ./gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/cluster_config.xml
[GAUSS-51405] : You need to install software:expect
#解决办法是安装如下依赖包
yum install expect

输入集群密码:omm123

[FAILURE] opengauss5m:
[GAUSS-50202] : The /opt/openGauss must be empty. Or user [omm] has write permission to directory /opt/openGauss. Because it will create symbolic link [/opt/openGauss/app] to install path [/opt/openGauss/app_a07d57c3] in gs_install process with this user.
[FAILURE] opengauss5b:
[GAUSS-50202] : The /opt/openGauss must be empty. Or user [omm] has write permission to directory /opt/openGauss. Because it will create symbolic link [/opt/openGauss/app] to install path [/opt/openGauss/app_a07d57c3] in gs_install process with this user.

#以上报错处理方法,然后再重新执行
[root@opengauss5m script]# rm -rf /opt/openGauss
[root@opengauss5m script]# chmod 775 /opt -R
[root@opengauss5m script]# chown omm:dbgrp /opt -R

07 执行安装

/opt/openGauss/app

#主库执行即可,在执行过程中,用户需根据提示输入数据库的密码,密码具有一定的复杂度,为保证用户正常使用该数据库,请记住输入的数据库密码

设置的密码要符合复杂度要求:
最少包含8个字符,最多包含16个字符。
不能和用户名、当前密码(ALTER)、或当前密码反序相同。
至少包含大写字母(A-Z)、小写字母(a-z)、数字、非字母数字字符(限定为~!@#$%^&*()-_=+|[{}];:,/?)四类字符中的三类字符。

08 安装验证

1.集群状态检查
## 通过openGauss提供的gs_om工具可以完成数据库状态检查

以omm用户身份登录服务器。
执行如下命令检查数据库状态是否正常,“cluster_state ”显示“Normal”表示数据库可正常使用

[root@opengauss5m ~]# su - omm
Last login: Sat Apr 8 12:56:31 CST 2023 on pts/0
[omm@opengauss5m ~]$ gs_om -t status
-----------------------------------------------------------------------

cluster_name : opengauss
cluster_state : Normal
redistributing : No

-----------------------------------------------------------------------
[omm@opengauss5m ~]$ 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 opengauss5m 192.168.6.10 15400 6001 /opt/openGauss/data/dn P Primary Normal
2 opengauss5b 192.168.6.11 15400 6002 /opt/openGauss/data/dn S Standby Normal

3.gs_om -t stop
[omm@opengauss5m ~]$ gs_om -t stop

4.启动集群
[omm@opengauss5m ~]$ gs_om -t start

5.登录数据库
[omm@opengauss5m ~]$ gsql -d postgres -p 15400
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:07:56 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 | omm | SQL_ASCII | C | C |
template0 | omm | SQL_ASCII | C | C | =c/omm +
| | | | | omm=CTc/omm
template1 | omm | SQL_ASCII | C | C | =c/omm +
| | | | | omm=CTc/omm
(3 rows)

复制搜一搜分享收藏划线

人划线

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论