openEuler部署openGauss

因为信创需求.
本次部署使用openEuler20.03LTS SP3 以及openEuler22.03LTS SP4版本部署openGauss5.0.0LTS.
步骤几乎相同,openEuler20.03会多出两两条命令,即对动态链接的共享对象文件创建软链接

openEuler的环境配置

配置IP地址和主机名

做bond需要重启,可以和selinux一起做完重启。
其他不再赘述

配置本地源

虽然一般情况下机器放在DMZ区域,但安装期间没有开放外部网络,因此部署挂载everything镜像做本地源使用。

1
2
mv /etc/yum.repos.d/openEuler.repo /etc/yum.repos.d/openEuler.repo.old
vim /etc/yum.repos.d/local.repo
1
2
3
4
5
[local]
name=local
baseurl=file:///mnt
gpgcheck=0
enable=1
1
2
mount /dev/cdrom /mnt
yum makecache

安装所需软件

1
2
3
4
### 个人习惯
yum -y install vim bash-completion
### 所需
yum -y install tar net-tools

tar用于解压,net-tools用于安装openGauss所需要的netstat
net-tools不安装安装openGauss会有对应提示,但不影响数据库安装

配置软硬件安装环境

根据openGauss极简版官方文档实施

1.关闭防火墙

1
2
systemctl disable firewalld.service
systemctl stop firewalld.service

2.设置字符集参数

vim /etc/profile

1
2
###在最后加入
export LANG=en_US.UTF-8

3.设置时区和时间

不再赘述

4.关闭swap交换内存(可选)

关闭swap交换内存是为了保障数据库的访问性能,避免把数据库的缓冲区内存淘汰到磁盘上。 如果服务器内存比较小,内存过载时,可打开swap交换内存保障正常运行。

1
swapoff -a

5.关闭RemoveIPC

a.修改/etc/systemd/logind.conf文件中的“RemoveIPC”值为“no”。
b.修改/usr/lib/systemd/system/systemd-logind.service文件中的“RemoveIPC”值为“no”。(部署过程中默认发现为no)
c.重新加载配置参数。

1
2
systemctl daemon-reload
systemctl restart systemd-logind

d.检查修改是否生效。

1
2
3
loginctl show-session | grep RemoveIPC
systemctl show systemd-logind | grep RemoveIPC
#### 结果应均为RemoveIPC=no

6.关闭selinux

1
2
3
vim /etc/selinux/config
SELINUX=disabled
reboot

7.关闭HISTORY记录

为避免指令历史记录安全隐患,需关闭各主机的history指令。
a.修改根目录下/etc/profile的HISTSIZE=0并保存

1
HISTSIZE=0

b.设置/etc/profile生效

1
source /etc/profile

单节点安装

因为本次项目使用单独一台机器进行安装,因此采用单节点安装.

创建用户

1
2
3
4
#创建组
groupadd dbgrp
#创建用户并归属组
useradd -g dbgrp omm

安装openGauss

a.创建openGauss安装目录

1
mkdir -p /opt/software/openGauss

并将opengauss数据库安装包上传至该目录,使用tar -jxvf进行解压

b.对omm用户分配可以访问/opt/software/openGauss的路径

1
2
chown omm:dbgrp /opt/ -R
chmod 775 /opt/ -R

c.执行install.sh安装脚本安装openGauss

openGauss只允许使用普通用户安装,切换到之前创建的用户

1
2
3
su - omm
cd /opt/software/openGauss/simpleInstall
sh install.sh -w "xxxx" &&source ~/.bashrc

-w后面指定数据库密码
注意:这里openEuler22.03 LTS SP3可以直接安装完成,openEuler20.03 LTS SP4会提示缺少libreadline.so.7
解决办法:

1
2
3
### 仅限于openEuler20.03 LTS SP4版本
ln -s /usr/lib64/libreadline.so.8.0 /usr/lib64/libreadline.so.7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
说明:
-w:初始化数据库密码(gs_initdb指定),因安全需要,此项必须设置。

-p:指定openGauss端口号,如不指定,默认为5432。

-h|--help:打印使用说明。

安装后,该数据库部署节点的名称为sgnode(gs_initdb指定)。

执行时,如果出现报错“the maximum number of SEMMNI is not correct, the current SEMMNI is xxx. Please check it.”,请使用有root权限的用户执行如下命令。
sysctl -w kernel.sem="250 85000 250 330"
安装后,数据库目录安装路径/opt/software/openGauss/data/single_node,其中/opt/software/openGauss为解压包路径,data/single_node为新创建的数据库节点目录。

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

d.查看进程是否正常

安装执行完成后,使用ps和gs_ctl查看进程是否正常

1
2
ps ux | grep gaussdb
gs_ctl query -D /opt/software/openGauss/data/single_node

执行ps命令,显示类似如下信息:

1
2
omm      24209 11.9  1.0 1852000 355816 pts/0  Sl   01:54   0:33 /opt/software/openGauss/bin/gaussdb -D /opt/software/openGauss/single_node
omm 20377 0.0 0.0 119880 1216 pts/0 S+ 15:37 0:00 grep --color=auto gaussdb

执行gs_ctl命令,显示类似如下信息:

1
2
3
4
5
6
7
8
9
10
11
12
gs_ctl query ,datadir is /opt/software/openGauss/data/single_node
HA state:
local_role : Normal
static_connections : 0
db_state : Normal
detail_information : Normal

Senders info:
No information

Receiver info:
No information

openGauss数据库部署完成

配置数据库

数据库的配置文件路径:/opt/software/openGauss/data/single_node

1.限制访问数据库的IP

修改配置文件pg_hba.conf,将需要访问数据库的IP添加到放行IP中,并开启密码验证。
e.g. 需要放行的IP段为192.168.10.1/32,修改或添加配置:

1
host all all 192.168.10.1/32 md5

2.修改数据库监听地址及加密方式

修改配置文件postgresql.conf
定位到listen_addresses

1
2
3
#listen_addresses = 'localhost'
####修改为
listen_addresses = '*'

一般情况下只需要修改监听地址,如果需要修改加密方式
e.g.将原来的加密方式md5修改成sha256+md5

1
2
3
#password_encryption_type = 0
###修改为
password_encryption_type = 1

openGauss部署完成
之后按照软件需求来配置数据库用户和权限

配置openGauss开机自启动

本次部署使用systemctl方式

配置opengauss.service

1
vim /etc/systemd/system/opengauss.service 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[Unit]
Description=openGauss
Documentation=openGauss
After=syslog.target
After=network.target

[Service]
Type=forking

User=omm
Group=dbgrp

Environment=PGDATA=/opt/software/openGauss/data
Environment=GAUSSHOME=/opt/software/openGauss
Environment=LD_LIBRARY_PATH=/opt/software/openGauss/lib

ExecStart=/opt/software/openGauss/bin/gs_ctl start -D /opt/software/openGauss/data/single_node
ExecReload=/opt/software/openGauss/bin/gs_ctl restart -D /opt/software/openGauss/data/single_node
ExecStop=/opt/software/openGauss/bin/gs_ctl stop -D /opt/software/openGauss/data/single_node

KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0

[Install]
WantedBy=multi-user.target

systemctl设置开机自启

1
2
systemctl daemon-reload
systemctl enable opengauss.service

部署全部结束