1. 配置操作系统满足安装要求
硬件环境:虚拟机的内存 8GB,4 核心 CPU,900G 磁盘(非必须)
软件环境:CentOS7.6
数据库版本:opengauss2.0 企业版
openGauss-2.0.0-CentOS-64bit-all.tar.gz
1.1. 关闭防火墙
#停止firewall
systemctl stop firewalld.service
#禁止firewall开机启动
systemctl disable firewalld.service
#检查防火墙是否关闭。
systemctl status firewalld
若防火墙状态显示为active (running),则表示防火墙未关闭。
若防火墙状态显示为inactive (dead),则无需再关闭防火墙。
1.2. 设置时区和时间
将各数据库节点的时区设置为相同时区,可以将/usr/share/zoneinfo/目录下的时区文件拷贝
为/etc/localtime 文件。
cp /usr/share/zoneinfo/$地区/$时区 /etc/localtime
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
1.3. 关闭 SELinux
getenforce
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0
getenforce
#检查
cat /etc/selinux/config|grep SELINUX
[root@node1 ~]# cat /etc/selinux/config|grep SELINUX
# SELINUX= can take one of these three values:
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
SELINUXTYPE=targeted
[root@node1 ~]#
1.4. 修改/etc/hosts
添加一行
cat >>/etc/hosts <<EOF
192.168.0.11 node1
EOF
cat /etc/hosts
1.5. 配置库路径
cat>> /etc/profile<<EOF
export LD_LIBRARY_PATH=/opt/software/openGauss/script/gspylib/clib:$LD_LIBRARY_PATH
EOF
1.6. 关闭 os 交换区
编辑/etc/fstab 文件,将交换区的那一行注释掉
vi /etc/fstab临时关闭交换区命令:
swapoff -a
free
1.7. 配置网络参数
cat>>/etc/sysctl.conf<<EOF
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
EOF
【注意】
[root@node1 ~]# ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.11 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::1f74:e8ed:4aba:e3c3 prefixlen 64 scopeid 0x20<link>
...
如果对外工作的网卡万兆网卡ens33,需要设计最大MTU为8192
虚拟机没有万兆网卡不能配置该项,否则认证报错!
1.8. 配置 NTPD(单机可以不用配置)
yum install ntp -y
vi /etc/ntp.conf
添加以下一行:
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap
添加以下3行,并注释掉所有的server行:
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
server node1
#启动ntpd时间服务器service ntpd start
#开机自启动
chkconfig ntpd on
或者
systemctl enable ntpd.service
1.9. 设置 root 用户远程登陆
sed -i "s/#Banner none/Banner none/g" /etc/ssh/sshd_config
cat >>/etc/ssh/sshd_config<<EOF
PermitRootLogin yes
EOF
systemctl restart sshd
#检查
cat /etc/ssh/sshd_config | grep PermitRootLogin
#PermitRootLogin yes
#检查
cat /etc/ssh/sshd_config | grep Banner
#Banner none
1.10. 文件系统参数、系统支持的最大进程数
echo "* soft nofile 1000000" >>/etc/security/limits.conf
echo "* hard nofile 1000000" >>/etc/security/limits.conf
echo "* soft nproc unlimited" >>/etc/security/limits.conf
echo "* hard nproc unlimited" >>/etc/security/limits.conf
1.11. 安装 python3.6.x 和依赖包
1)安装python3.6.x
2)
yum install openssl* -y
yum install python3* -y
说明:
也可以直接编译安装或者rpm包安装。
2)软件依赖要求
openGauss 的软件依赖要求如表所示。
建议:使用上述操作系统安装光盘或者源中,下列依赖软件的默认安装包,若不存在下列软
件,可参看软件对应的建议版本。
软件依赖要求
所需软件 建议版本
libaio-devel 建议版本:0.3.109-13
flex 要求版本:2.5.31 以上
bison 建议版本:2.7-4
ncurses-devel 建议版本:5.9-13.20130511
glibc-devel 建议版本:2.17-111
patch 建议版本:2.7.1-10
lsb_release 建议版本:4.1
readline-devel 建议版本 :7.0-13
检查软件依赖的包:
[root@node1 ~]# rpm -qa libaio-devel flex bison ncurses-devel glibc-devel patch
lsb_release readline-devel
如果少,则安装,或者全部安装:
例 如 : [root@node1 ~]# yum install libaio-devel flex bison ncurses-devel glibc-devel
patch lsb_release readline-devel
再次检查:
rpm -qa libaio-devel flex bison ncurses-devel glibc-devel patch lsb_release
readline-devel
[root@node1 ~]# rpm -qa libaio-devel flex bison ncurses-devel glibc-devel patch
lsb_release readline-develbison-3.0.4-2.el7.x86_64
patch-2.7.1-12.el7_7.x86_64
ncurses-devel-5.9-14.20130511.el7_4.x86_64
readline-devel-6.2-11.el7.x86_64
libaio-devel-0.3.109-13.el7.x86_64
flex-2.5.37-6.el7.x86_64
glibc-devel-2.17-307.el7.1.x86_64
注:lsb_release 包:默认已经安装
[root@node1 Packages]# lsb_release -v
LSB
Version:
:core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:
desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:print
ing-4.1-noarch
reboot
重新启动服务器
1.12. 创建安装包的存放目录
mkdir -p /opt/software/openGauss
chmod 755 -R /opt/software
1.13. 下载 openGauss 数据库软件
下载地址为:
https://opengauss.org/zh/download.html
<DEVICELIST>
<!-- 节点 1 上的部署信息 -->
<DEVICE sn="node1">
<!-- 节点 1 的主机名称 -->
<PARAM name="name" value="node1"/>
<!-- 节点 1 所在的 AZ 及 AZ 优先级 -->
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!-- 节点 1 的 IP,如果服务器只有一个网卡可用,将 backIP1 和 sshIP1 配置
成同一个 IP -->
<PARAM name="backIp1" value="192.168.0.11"/>
<PARAM name="sshIp1" value="192.168.0.11"/>
<!--dbnode-->
<PARAM name="dataNum" value="1"/>
<PARAM name="dataPortBase" value="26000"/>
<PARAM name="dataNode1" value="/opt/huawei/install/data/dn"/>
<PARAM name="dataNode1_syncNum" value="0"/>
</DEVICE>
</DEVICELIST>
</ROOT>
EOF
【说明】官方 xml 模板:
数据库登录端口是 15400,此处修改为 26000。
和官方文档后面描述一致。
2. 安装 openGauss 企业版单机数据库
2.1. 解压缩 openGauss DBMS 介质
cd /opt/software/openGauss
tar xf openGauss-2.0.0-CentOS-64bit-all.tar.gz
tar -zxvf openGauss-2.0.0-CentOS-64bit-om.tar.gz
2.2. 创建 XML 文件
cat > clusterconfig.xml<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<!-- openGauss 整体信息 -->
<CLUSTER>
<!-- 数据库名称 -->
<PARAM name="clusterName" value="dbCluster" />
<!-- 数据库节点名称(hostname) -->
<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" />
<!-- 数据库 core 文件目录-->
<PARAM name="corePath" value="/opt/huawei/corefile" />
<!-- 节点 IP,与数据库节点名称列表一一对应 -->
<PARAM name="backIp1s" value="192.168.0.11"/>
</CLUSTER>
<!-- 每台服务器上的节点部署信息 --><DEVICELIST>
<!-- 节点 1 上的部署信息 -->
<DEVICE sn="node1">
<!-- 节点 1 的主机名称 -->
<PARAM name="name" value="node1"/>
<!-- 节点 1 所在的 AZ 及 AZ 优先级 -->
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!-- 节点 1 的 IP,如果服务器只有一个网卡可用,将 backIP1 和 sshIP1 配置
成同一个 IP -->
<PARAM name="backIp1" value="192.168.0.11"/>
<PARAM name="sshIp1" value="192.168.0.11"/>
<!--dbnode-->
<PARAM name="dataNum" value="1"/>
<PARAM name="dataPortBase" value="26000"/>
<PARAM name="dataNode1" value="/opt/huawei/install/data/dn"/>
<PARAM name="dataNode1_syncNum" value="0"/>
</DEVICE>
</DEVICELIST>
</ROOT>
EOF
【说明】官方 xml 模板:
数据库登录端口是 15400,此处修改为 26000。
和官方文档后面描述一致。
2.3. 检查环境变量
echo $LD_LIBRARY_PATH
2.4. 安装前进行交互式检查
[root@node1 script]#
cd script
./gs_preinstall -U omm -G dbgrp -X /opt/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
Please enter password for cluster user.
Password: omm123
Please enter password for cluster user again.
Password: omm123
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 "/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.
Set ARM Optimization.
No need to set ARM Optimization.
Fixing server package owner.
Setting finish flag.
Successfully set finish flag.
Preinstallation succeeded查看具体的检查信息
/opt/software/openGauss/script/gs_checkos -i A -h node1 --detail
## 2.5. 开始安装 openGauss DBMS 和创建数据库
使用 root 执行如下命令
cd /opt/software/openGauss/script
chmod -R 755 /opt/software/openGauss/script
chown -R omm:dbgrp /opt/software/openGauss/script
使用 omm 用户安装 openGauss DBMS 和创建 openGauss 数据库
su - omm
cd /opt/software/openGauss/script
cp ../clusterconfig.xml .
gs_install -X /opt/software/openGauss/script/clusterconfig.xml
重要提示:用户需根据提示输入数据库的密码,密码需要具有一定的复杂度,为保证用户正
常使用该数据库,请记住输入的数据库密码。此处建议密码设置为 huawei@1234
(16G 内存创建就不会出错)
[omm@node1 ~]$ cd /opt/software/openGauss/script
[omm@node1 script]$ cp ../clusterconfig.xml .
[omm@node1 script]$ gs_install -X /opt/software/openGauss/script/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:huawei@1234
Please repeat for database:huawei@1234
begin to create CA cert filesThe sslcert will be generated in /opt/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..
[omm@node1 script]$
启动数据库:
[omm@node1 db1]$ gs_om -t start
Starting cluster.
=========================================
[SUCCESS] node1:
[2021-04-01 16:50:13.969][29784][][gs_ctl]: gs_ctl started,datadir is
/opt/huawei/install/data/dn
[2021-04-01 16:50:13.974][29784][][gs_ctl]: another server might be running; Please use
the restart command
=========================================
Successfully started.
[omm@node1 script]$
2.6. 首次登录数据库
在 centOS 中,使用 omm 用户执行下面的操作。
登录到数据库,修改数据库的密码:
[omm@node1 dn]$ 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.
检查数据库版本show server_version;
SELECT version();
postgres=# SELECT version();
version
-------------------------------------------------------------------------------
PostgreSQL 9.2.4 (openGauss 2.0.0 build 78689da9) compiled at 2021-03-31 21:04:03 commit
0 last mr
on x86_64-unknown-linux-gnu, compiled by g++ (GCC) 7.3.0, 64-bit
(1 row)
Invalid command \. Try \? for help.
postgres=#
postgres=# CREATE DATABASE mydb WITH ENCODING 'GBK' template = template0;
CREATE DATABASE
postgres=#
查看帮助
help
退出
\q
3. openGauss 的简单维护
3.1. 登录数据库
gsql -d postgres -p 26000 -r
3.2. 停止 openGauss 数据库
gs_om -t stop
3.3. 查看数据库的状态
gs_om -t status --detail
[omm@node1 db1]$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Unavailable
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state
---------------------------------------------------------------------------
1 node1 192.168.0.11 6001 /opt/gaussdb/data/db1 P Primary Manually stopped
[omm@node1 db1]$
启动 openGauss 数据库
gs_om -t start
再次查看数据库的状态
gs_om -t status --detail
[omm@node1 ~]$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL[ Datanode State ]
node node_ip instance state
---------------------------------------------------------------------------
1 node1 192.168.0.11 6001 /opt/gaussdb/data/db1 P Primary Normal
[omm@node1 ~]$
查看数据库系统的详细信息
gs_om -t status --all ##数据库停止状态
[omm@node1 db1]$ gs_om -t status --all
-----------------------------------------------------------------------
cluster_state : Unavailable
redistributing : No
-----------------------------------------------------------------------
node : 1
node_name : node1
node : 1
instance_id : 6001
node_ip : 192.168.0.11
data_path : /opt/gaussdb/data/db1
type : Datanode
instance_state : Down
static_connections : 0
HA_state : Manually stopped
reason : Unknown
sender_sent_location : 0/0
sender_write_location : 0/0
sender_flush_location : 0/0
sender_replay_location : 0/0
receiver_received_location: 0/0
receiver_write_location : 0/0
receiver_flush_location : 0/0
receiver_replay_location : 0/0
sync_state : Async
-----------------------------------------------------------------------
[omm@node1 db1]$
gs_om -t status --all ##数据库 nornal 启动状态
[omm@node1 db1]$ gs_om -t status --all
-----------------------------------------------------------------------
cluster_state : Normal
redistributing : No
-----------------------------------------------------------------------
node : 1node_name : node1
node : 1
instance_id : 6001
node_ip : 192.168.0.11
data_path : /opt/gaussdb/data/db1
type : Datanode
instance_state : Primary
static_connections : 0
HA_state : Normal
reason : Normal
sender_sent_location : 0/0
sender_write_location : 0/0
sender_flush_location : 0/0
sender_replay_location : 0/0
receiver_received_location: 0/0
receiver_write_location : 0/0
receiver_flush_location : 0/0
receiver_replay_location : 0/0
sync_state : Async
-----------------------------------------------------------------------
[omm@node1 db1]$
4. 【附录】
4.1. 查看 gs_om 命令的帮助
[omm@node1 db1]$ gs_om --help
gs_om is a utility to manage a cluster.
Usage:
gs_om -? | --help
gs_om -V | --version
OLAP scene:
gs_om -t start [-h HOSTNAME] [-D dataDir] [--time-out=SECS]
[--security-mode=MODE] [-l LOGFILE]
gs_om -t stop [-h HOSTNAME] [-D dataDir] [--time-out=SECS] [-m MODE]
[-l LOGFILE]
gs_om -t status [-h HOSTNAME] [-o OUTPUT] [--detail] [--all] [-l LOGFILE]
gs_om -t generateconf -X XMLFILE [--distribute] [-l LOGFILE]
gs_om -t cert [--cert-file=CERTFILE | --rollback] [-L] [-l LOGFILE]
gs_om -t kerberos -m [install|uninstall] -U USER [-l LOGFILE]
[--krb-server|--krb-client]
gs_om -t view [-o OUTPUT]
gs_om -t query [-o OUTPUT]
gs_om -t refreshconf
General options:




