一、安装前环境准备
1.操作系统:CentOS 7.6 (虚拟机,IP:192.168.172.151)
(1)操作系统关闭防火墙:
[root@local151 ~]# systemctl stop firewalld.service
[root@local151 ~]# systemctl disable firewalld.service
[root@local151 ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
(2)检查系统时区:
[root@local151 ~]# date -R
Mon, 24 May 2021 09:46:32 +0800
时区主要是用于集群安装时保证所有节点是相同时区。另外系统时间也要一致。
(3)关闭selinux
[root@local151 ~]# cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled # 设置为disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
设置完需要重启操作系统才会生效,也可以临时处理:
setenforce 0
详细可取查询Linux配置selinux了解。
(4)修改hosts文件,添加主机名、IP映射:
[root@local151 ~]# hostname
local151
[root@local151 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.172.151 local151
(5)关闭操作系统交换分区swap(官方建议):
[root@local151 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Feb 3 10:10:08 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=fcfca156-8754-48a7-bc9f-490f54e23ccc /boot xfs defaults 0 0
#/dev/mapper/centos-swap swap swap defaults 0 0
修改后重启操作系统,如不重启可以修改后手动关闭swap:
[root@local151 ~]# free -m
total used free shared buff/cache available
Mem: 3771 409 2253 14 1107 3036
Swap: 4096 0 4096
[root@local151 ~]# swapoff -a
[root@local151 ~]# free -m
total used free shared buff/cache available
Mem: 3771 409 2253 14 1107 3036
Swap: 0 0 0
2.openGuess安装包:openGauss-2.0.0-CentOS-64bit-all.tar.gz
下载地址:openGuess官网 包中含有多个文件:
openGauss-2.0.0-CentOS-64bit-om.sha256
openGauss-2.0.0-CentOS-64bit-om.tar.gz
openGauss-2.0.0-CentOS-64bit.sha256
openGauss-2.0.0-CentOS-64bit.tar.bz2
upgrade_sql.sha256
upgrade_sql.tar.gz
将下载的安装包上传至部署服务器上。
简单了解一下openGuess安装用户和用户组:
dbgrp:初始化安装环境时,由-G参数所指定的安装用户所属的用户组。该用户组如果不存在,则会自动创建,也可提前创建好用户组。在执行gs_preinstall脚本时会检查权限。gs_preinstall脚本会自动赋予此组中的用户对安装目录、数据目录的访问和执行权限。
创建dbgrp用户组命令:
groupadd dbgrp
omm:初始化安装环境时,由-U参数所指定和自动创建的操作系统用户,如果已经存在该用户,请清理该用户或更换初始化用户。从安全性考虑,对此用户的所属组规划如下:
所属组:dbgrp
二、安装openGuess
1.初始化操作系统环境配置
(1)配置网络内核参数
[root@local151 ~]# vim /etc/sysctl.conf
......
# 添加如下参数
net.ipv4.ip_local_port_range = 26000 65500
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.ipv4.conf. ens33.rp_filter = 1
net.ipv4.tcp_fin_timeout=60
net.ipv4.tcp_retries1=5
net.ipv4.tcp_syn_retries=5
net.sctp.path_max_retrans=10
net.sctp.max_init_retransmits=10
[root@local151 ~]# sysctl -p # 使内核参数生效
官方文档里参数如下:
net.ipv4.tcp_max_tw_buckets = 10000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_retries1 = 5
net.ipv4.tcp_syn_retries = 5
net.ipv4.tcp_synack_retries = 5
net.sctp.path_max_retrans = 10
net.sctp.max_init_retransmits = 10
net.sctp.association_max_retrans = 10
net.sctp.hb_interval = 30000
net.ipv4.tcp_retries2 = 12
vm.overcommit_memory = 0
net.sctp.sndbuf_policy = 0
net.sctp.rcvbuf_policy = 0
net.sctp.sctp_mem = 94500000 915000000 927000000
net.sctp.sctp_rmem = 8192 250000 16777216
net.sctp.sctp_wmem = 8192 250000 16777216
net.ipv4.tcp_rmem = 8192 250000 16777216
net.ipv4.tcp_wmem = 8192 250000 16777216
net.core.wmem_max = 21299200
net.core.rmem_max = 21299200
net.core.wmem_default = 21299200
net.core.rmem_default = 21299200
net.ipv4.ip_local_port_range = 26000-65535
kernel.sem = 250 6400000 1000 25600
vm.min_free_kbytes = # 系统总内存的5%
net.core.somaxconn = 65535
net.ipv4.tcp_syncookies = 1
net.sctp.addip_enable = 0
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_fin_timeout = 60
kernel.shmall = 1.15292E+18
kernel.shmmax = 1.84467E+19
net.ipv4.tcp_sack = 1
net.ipv4.tcp_timestamps = 1
vm.extfrag_threshold = 500
vm.overcommit_ratio = 90
(2)修改文件系统内核参数
[root@local151 ~]# echo "* soft nofile 1000000" >>/etc/security/limits.conf
[root@local151 ~]# echo "* hard nofile 1000000" >>/etc/security/limits.conf
[root@local151 ~]# echo "* soft nproc unlimited" >>/etc/security/limits.conf
[root@local151 ~]# echo "* hard nproc unlimited" >>/etc/security/limits.conf
(3)安装依赖包
[root@local151 ~]# yum install -y libaio-devel flex bison ncurses-devel glibc-devel patch redhat-lsb-core readline-devel openssl* java-1.8.0-openjdk* psmisc bzip2 python3 python3-devel lksctp*
以上是在联网配置了清华镜像站yum源的情况下安装的,如果是离线安装需要将全部安装包以及所依赖包下载后上传服务器配置自定义yum源来进行安装。
2.初始化安装环境
(1)创建安装包存放目录:
[root@local151 ~]# mkdir -p /data/software/openGauss
[root@local151 ~]# chmod 755 -R /data/software
(2)将安装包openGauss-2.0.0-CentOS-64bit-all.tar.gz上传至上一步所创建的目录中。解压。
[root@local151 openGauss]# tar -zxvf openGauss-2.0.0-CentOS-64bit-all.tar.gz
[root@local151 openGauss]# tar -zxvf openGauss-2.0.0-CentOS-64bit-om.tar.gz
继续解压OM安装包,会在/data/software/openGauss路径下自动生成script子目录,并且在script目录下生成gs_preinstall等各种OM工具脚本。
(3)创建xml配置文件
[root@local151 ~]# cd /data/software/openGauss/
[root@local151 openGauss]# vim clusterconfig.xml
<?xml version="2.0" encoding="UTF-8"?>
<ROOT>
<!-- openGauss整体信息 -->
<CLUSTER>
<!-- 数据库名称 -->
<PARAM name="clusterName" value="dbCluster" />
<!-- 数据库节点名称(hostname) -->
<PARAM name="nodeNames" value="local151" />
<!-- 数据库安装目录-->
<PARAM name="gaussdbAppPath" value="/data/huawei/install/app" />
<!-- 日志目录-->
<PARAM name="gaussdbLogPath" value="/data/huawei/log/omm" />
<!-- 临时文件目录-->
<PARAM name="tmpMppdbPath" value="/data/huawei/tmp" />
<!-- 数据库工具目录-->
<PARAM name="gaussdbToolPath" value="/data/huawei/install/om" />
<!-- 数据库core文件目录-->
<PARAM name="corePath" value="/data/huawei/corefile" />
<!-- 节点IP,与数据库节点名称列表一一对应 -->
<PARAM name="backIp1s" value="192.168.172.151"/>
</CLUSTER>
<!-- 每台服务器上的节点部署信息 -->
<DEVICELIST>
<!-- 节点1上的部署信息 -->
<DEVICE sn="node1">
<!-- 节点1的主机名称 -->
<PARAM name="name" value="local151"/>
<!-- 节点1所在的AZ及AZ优先级 -->
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!-- 节点1的IP,如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
<PARAM name="backIp1" value="192.168.172.151"/>
<PARAM name="sshIp1" value="192.168.172.151"/>
<!--dbnode-->
<PARAM name="dataNum" value="1"/>
<PARAM name="dataPortBase" value="26000"/>
<PARAM name="dataNode1" value="/data/huawei/install/data/dn"/>
<PARAM name="dataNode1_syncNum" value="0"/>
</DEVICE>
</DEVICELIST>
</ROOT>
注意:xml文件要跟解压后的目录在同一级目录。其中的/data/huawei下的目录不要提前创建,尤其是数据库安装目录,如果提前创建会在使用命令gs_preinstall时报错。
(4)进入script目录下
cd /opt/software/openGauss/script
使用gs_preinstall准备好安装环境,采用交互模式执行前置,并在执行过程中自动创建root用户互信和openGauss用户互信,omm为数据库管理员(也是运行openGauss的操作系统用户),dbgrp为运行openGauss的操作系统用户的群组名称,/data/software/openGauss/clusterconfig.xml为openGauss配置文件路径。在执行过程中,用户根据提示选择是否创建互信,并输入操作系统root用户或omm用户的密码:
(需要注意的是xml文件和解压的om包文件在同一级目录下执行一下命令。)
[root@local151 script]# ./gs_preinstall -U omm -G dbgrp -X /data/software/openGauss/clusterconfig.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 pssh path
Successfully set core path.
Are you sure you want to create the user[omm] and create trust for it (yes/no)? yes # 输入yes
Please enter password for cluster user.
Password: # 按提示输入密码
Please enter password for cluster user again.
Password: # 按提示输入密码
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.
Setting SCTP service.
Successfully set SCTP service.
Set and check OS parameter.
Setting OS parameters.
Successfully set OS parameters.
Warning: Installation environment contains some warning messages.
Please get more details by "/data/software/openGauss/script/gs_checkos -i A -h local151 --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.
Set ARM Optimization.
No need to set ARM Optimization.
Fixing server package owner.
Setting finish flag.
Successfully set finish flag.
Preinstallation succeeded.
2.执行安装数据库
(1)切换到omm用户,1-(4)执行成功后,会自动将openGuess的环境变量写入到omm用户的 .bashrc 下:
[root@local151 openGauss]# su - omm
Last login: Mon May 24 13:41:34 CST 2021 on pts/0
[omm@local151 ~]$ cat .bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
export GPHOME=/data/huawei/install/om
export PATH=$GPHOME/script/gspylib/pssh/bin:$GPHOME/script:$PATH
export LD_LIBRARY_PATH=$GPHOME/lib:$LD_LIBRARY_PATH
export PYTHONPATH=$GPHOME/lib
export GAUSSHOME=/data/huawei/install/app
export PATH=$GAUSSHOME/bin:$PATH
export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH
export S3_CLIENT_CRT_FILE=$GAUSSHOME/lib/client.crt
export GAUSS_VERSION=2.0.0
export PGHOST=/data/huawei/tmp
export GAUSSLOG=/data/huawei/log/omm/omm
umask 077
export GAUSS_ENV=2
export GS_CLUSTER_NAME=dbCluster
(2)使用gs_install安装openGauss。
[omm@local151 ~]$ gs_install -X /data/software/openGauss/clusterconfig.xml
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 /data/huawei/install/app/share/sslcert/om
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..
(3)安装成功后查看openGuess状态:
[omm@local151 ~]$ gs_om -t status
-----------------------------------------------------------------------
cluster_name : dbCluster
cluster_state : Normal
redistributing : No
-----------------------------------------------------------------------
数据库安装完成后,默认生成名称为postgres的数据库。第一次连接数据库时可以连接到此数据库。其中postgres为需要连接的数据库名称,26000为数据库主节点的端口号,即XML配置文件中的dataPortBase的值。请根据实际情况替换。
[omm@local151 ~]$ gsql -d postgres -p 26000 -r
gsql ((openGauss 2.0.0 build 78689da9) compiled at 2021-03-31 21:04:03 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
postgres=# \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)
postgres=#
三、openGuess数据库相关目录介绍