UOS Server V20
系统特性
架构:x86_64 & aarch64 & loongarch64 & sw_64 CPU平台:支持Intel、AMD、海光、兆芯、鲲鹏、飞腾、龙芯、申威等国内外CPU平台 内核:默认使用kernel-4.19;在ISO中提供kernel-5.10(可选择安装),kernel-5.10适用于云计算等场景,提供更多经过测试验证后合入的高版本内核特性
https://www.chinauos.com/resource/download-server
openGauss介绍
openGauss是一个高性能、高可用、高扩展性的开源关系型数据库管理系统,采用木兰宽松许可证v2发行。openGauss对postgresql语法、生态保持高度兼容,是独立发展的数据库开源根社区。它支持多种索引结构,提供高效的查询性能,并通过数据复制和故障切换机制确保系统的高可用性。openGauss内核深度融合华为在数据库领域多年的经验,结合企业级场景需求,持续构建竞争力特性。
openGauss 官网
https://opengauss.org/zh/
openGauss 软件包下载
https://opengauss.org/zh/download/
openGauss 官方手册
https://docs-opengauss.osinfra.cn/zh/
openGauss安装包下载
下载openGauss_5.0.2企业版openEuler_20.03_LTS版本
openGauss主备节点信息
操作系统版本信息
cat /etc/os-release
PRETTY_NAME="UOS Server 20"
NAME="UOS Server 20"
VERSION_ID="20"
VERSION="20"
ID=uos
HOME_URL="https://www.chinauos.com/"
BUG_REPORT_URL="https://bbs.chinauos.com/"
VERSION_CODENAME=fuyu
PLATFORM_ID="platform:uel20"
一、操作系统基础环境(主、备节点配置一致)
1. 设置字符集参数
localectl set-locale en_US.UTF-8
localectl status
设置英文字符集(openGauss安装要求英文字符集)
export LANG=en_US.UTF-8
echo $LANG
设置中文字符集
localectl set-locale zh_CN.utf8
export LANG=zh_CN.utf8
2. 设置时区和时间
设置时区亚洲上海
timedatectl set-timezone Asia/Shanghai
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
设置日期时间
timedatectl set-time "YYYY-MM-DD HH:MM:SS"
手动设置时间需要关闭ntp时钟(true开启 、false关闭)
timedatectl set-ntp false
验证时区和时间
timedatectl status
3. 关闭防火墙
systemctl disable firewalld.service
systemctl stop firewalld.service
4. 关闭selinux
编辑配置文件关闭selinux重启系统生效
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
临时关闭selinux立即生效
setenforce 0
查看selinux状态
getenforce
5. 修改系统主机名
修改主机名
主节点
hostnamectl set-hostname og-node1
备节点
hostnamectl set-hostname og-node2
6. 配置hosts文件
cat >> /etc/hosts<<EOF
192.168.188.185 og-node1
192.168.188.186 og-node2
EOF
查看hosts文件
cat /etc/hosts
7. 关闭透明大页面(transparent_hugepage)
临时关闭透明大页面
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
添加/etc/rc.d/rc.local开机启动
/etc/rc.local是/etc/rc.d/rc.local的软连接
echo 'echo never > /sys/kernel/mm/transparent_hugepage/defrag' /etc/rc.d/rc.local
echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
/usr/bin/bash /etc/rc.d/rc.local
8. 设置会话超时时间
vim /etc/profile
export TMOUT=300
或
sed -i "s/TMOUT.*/TMOUT=300/g" /etc/profile
使用source命令生效配置
source /etc/profile
9. 设置history记录
修改/etc/profile中HISTSIZE值
vim /etc/profile
HISTSIZE默认值为1000 更改为 HISTSIZE=100
sed -i "s/HISTSIZE=100.*/HISTSIZE=100/g" /etc/profile
使用source命令生效配置
source /etc/profile
10. 关闭RemoveIPC
echo "RemoveIPC=no" /etc/systemd/logind.conf
echo "RemoveIPC=no" /usr/lib/systemd/system/systemd-logind.service
重新加载服务配置文件
systemctl daemon-reload
重启systemd-logind服务
systemctl restart systemd-logind
验证生效参数
loginctl show-session | grep RemoveIPC
systemctl show systemd-logind | grep RemoveIPC
11. core dump日志格式修改
core_pattern 设置
echo "/data/core_pattern/core-%e-%p-%t" > /proc/sys/kernel/core_pattern
12. 安装依赖包
dnf install -y zlib-devel libaio libuuid readline-devel krb5-libs expect
dnf install -y libicu libxslt tcl perl openldap pam openssl-devel libxml2 python3
13. 建依赖库软连接
ln -s /usr/lib64/libreadline.so.8 /usr/lib64/libreadline.so.7
14. 操作系统重启
操作系统基础环境参数配置优化完成后重启操作系统
systemctl reboot
二、创建用户组&用户(主、备节点执行)
创建用户组dbgroup
groupadd -g 1000 dbgrp
创建用户组dbgroup下的普通用户omm
useradd -u 1000 omm -g dbgrp
设置 omm 用户密码(可自定义密码)
echo "omm@P@ssw0rd" | passwd omm --stdin
三、openGauss 数据库预安装(主、备执行)
1. 创建安装目录、授权目录
mkdir -p /data/{openGauss,backup,archive_wals,core_pattern}
chmod 700 /data/{openGauss,backup,archive_wals,core_pattern}
chown -R omm:dbgrp /data/{openGauss,backup,archive_wals,core_pattern}
mkdir -p /opt/openGauss
chown omm:dbgrp -R /opt/openGauss/
chmod 755 /opt/openGauss/
2. 上传openGauss安装包并解压(主、备节点执行)
cd /opt/openGauss/
tar -zxvf openGauss-5.0.2-openEuler-64bit-all.tar.gz
tar -zxvf openGauss-5.0.2-openEuler-64bit-om.tar.gz
3. 创建cluster_config.xml文件
vim /home/omm/cluster_config.xml
<ROOT>
<!-- openGauss整体信息 -->
<CLUSTER>
<PARAM name="clusterName" value="openGauss_cluster" />
<PARAM name="nodeNames" value="og-node1,og-node2" />
<PARAM name="gaussdbAppPath" value="/opt/openGauss/app" />
<PARAM name="gaussdbLogPath" value="/var/log/omm" />
<PARAM name="tmpMppdbPath" value="/opt/openGauss/tmp"/>
<PARAM name="gaussdbToolPath" value="/opt/openGauss/install/om" />
<PARAM name="corePath" value="/opt/openGauss/corefile"/>
<PARAM name="backIp1s" value="192.168.188.185,192.168.188.186"/>
</CLUSTER>
<!-- 每台服务器上的节点部署信息 -->
<DEVICELIST>
<!-- node1上的节点部署信息 -->
<DEVICE sn="og-node1">
<PARAM name="name" value="og-node1"/>
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
<PARAM name="backIp1" value="192.168.188.185"/>
<PARAM name="sshIp1" value="192.168.188.185"/>
<!--dn-->
<PARAM name="dataNum" value="1"/>
<PARAM name="dataPortBase" value="15400"/>
<PARAM name="dataNode1" value="/data/openGauss/dn,og-node2,/data/openGauss/dn"/>
<PARAM name="dataNode1_syncNum" value="0"/>
</DEVICE>
<!-- node2上的节点部署信息,其中“name”的值配置为主机名称 -->
<DEVICE sn="og-node2">
<PARAM name="name" value="og-node2"/>
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
<PARAM name="backIp1" value="192.168.188.186"/>
<PARAM name="sshIp1" value="192.168.188.186"/>
</DEVICE>
</DEVICELIST>
</ROOT>
四、openGauss预安装脚本
1. root 用户执行预安装脚本 (主节点执行)
cd /opt/openGauss/script/
./gs_preinstall -U omm -G dbgrp -X /home/omm/cluster_config.xml
[root@og-node1 ~]# cd /opt/openGauss/script/
[root@og-node1 script]# ./gs_preinstall -U omm -G dbgrp -X /home/omm/cluster_config.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.
Are you sure you want to create trust for root (yes/no)?yes
Please enter password for root
Password:
Successfully created SSH trust for the root permission user.
Setting host ip env
Successfully set host ip env.
Distributing package.
Begin to distribute package to tool path.
Successfully distribute package to tool path.
Begin to distribute package to package path.
Successfully distribute package to package path.
Successfully distributed package.
Are you sure you want to create the user[omm] and create trust for it (yes/no)? yes
Preparing SSH service.
Successfully prepared SSH service.
Installing the tools in the cluster.
Successfully installed the tools in the cluster.
Checking hostname mapping.
Successfully checked hostname mapping.
Creating SSH trust for [omm] user.
Please enter password for current user[omm].
Password:
Checking network information.
All nodes in the network are Normal.
Successfully checked network information.
Creating SSH trust.
Creating the local key file.
Successfully created the local key files.
Appending local ID to authorized_keys.
Successfully appended local ID to authorized_keys.
Updating the known_hosts file.
Successfully updated the known_hosts file.
Appending authorized_key on the remote node.
Successfully appended authorized_key on all remote node.
Checking common authentication file content.
Successfully checked common authentication content.
Distributing SSH trust file to all node.
Distributing trust keys file to all node successfully.
Successfully distributed SSH trust file to all node.
Verifying SSH trust on all hosts.
Successfully verified SSH trust on all hosts.
Start set cron for omm
Warning: The omm user does not have permission for crontab.
Successfully created SSH trust.
Successfully created SSH trust for [omm] user.
Checking OS software.
Successfully check os software.
Checking OS version.
Successfully checked OS version.
Creating cluster's path.
Successfully created cluster's path.
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/openGauss/script/gs_checkos -i A -h og-node1,og-node2 --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.
Setting Cgroup.
Successfully set Cgroup.
Set ARM Optimization.
No need to set ARM Optimization.
Fixing server package owner.
Setting finish flag.
Successfully set finish flag.
Preinstallation succeeded.
2. 设置安装目录属主(主、备节点执行)
chown omm:dbgrp -R /opt/openGauss/
chmod 755 /opt/openGauss/
3. 检测操作系统安装环境(主节点可选执行)
/opt/openGauss/script/gs_checkos -i A --detail
/opt/openGauss/script/gs_checkos -i A -h og-node1,og-node2 --detail
五、openGauss集群数据库安装
切换omm用户执行安装脚本(主节点执行)
su - omm
cd /opt/openGauss/script/
-X /home/omm/cluster_config.xml
注意:执行过程中根据提示配置数据库管理员密码。
[omm@og-node1 script]$ ./gs_install -X /home/omm/cluster_config.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 /opt/openGauss/app/share/sslcert/om
Create CA files for cm beginning.
Create CA files on directory [/opt/openGauss/app_48a25b11/share/sslcert/cm]. file list: ['cacert.pem', 'server.key', 'server.crt', 'client.key', 'client.crt', 'server.key.cipher', 'server.key.rand', 'client.key.cipher', 'client.key.rand']
Non-dss_ssl_enable, no need to create CA for DSS
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.
Successful check consistence of memCheck and coresCheck on all nodes.
Configuring pg_hba on all nodes.
Configuration is completed.
Starting cluster.
======================================================================
Successfully started primary instance. Wait for standby instance.
======================================================================
.
Successfully started cluster.
======================================================================
cluster_state : Normal
redistributing : No
node_count : 2
Datanode State
primary : 1
standby : 1
secondary : 0
cascade_standby : 0
building : 0
abnormal : 0
down : 0
Successfully installed application.
end deploy..
六、openGauss数据库集群验证
1. 检查集群状态
gs_om查询集群状态
gs_om -t status --detail
gs_ctl查询集群状态
gs_ctl query -Cv -D /data/openGauss/dn
2. 连接数据库
gsql -d postgres -p 15400 -r
3. 数据主备库同步验证
主库创建库表,备库查看同步状态
创建数据库
create database datahub with dbcompatibility='PG' encoding='UTF8';
创建数据表
\c datahub
CREATE TABLE subjects ( id int, name varchar(255), age int, sex int, address varchar(255) );
插入数据
INSERT INTO subjects VALUES (1,'uos',13,3,'Shanghai');
查看数据表结构和查询数据
备节点查看数据同步信息
备库只读,无法创建、删除对象
INSERT INTO subjects VALUES (2,'gauss',10,2,'Shenzhen');
DELETE FROM subjects WHERE name = 'uos';
删除数据表
DROP TABLE IF EXISTS subjects;
删除数据库
DROP DATABASE IF EXISTS datahub;
七、openGauss数据库创建、用户授权、账户管理
创建uos用户
create user uos with password 'openGauss@uos';
创建数据库database_openGauss
openGauss=# CREATE DATABASE database_openGauss;
修改数据库OWNER所有者
openGauss=# ALTER DATABASE database_opengauss OWNER TO uos;
删除数据库
openGauss=# DROP DATABASE database_openGauss;
授权uos用户database_openGauss数据库管理员权限
grant all privileges on database database_openGauss to uos;
修改omm账户密码
openGauss=# ALTER USER omm WITH PASSWORD 'openGauss@omm';
手动锁定
openGauss=# ALTER USER uos ACCOUNT LOCK;
手动解锁
openGauss=# ALTER USER uos ACCOUNT UNLOCK;
查看用户状态
rolstatus 字段显示角色的状态
0:正常状态
1:由于登录失败次数超过阈值被锁定了一定的时间
2:被管理员锁定
查看roloid 对应的用户
SELECT usename,usesysid,usesuper,valuntil FROM pg_user;
八、openGauss常用命令
查看数据库版本
/opt/openGauss/app/bin/gsql --version
select version();
登陆数据库
gsql -h 127.0.0.1 -U omm -d postgres
查看帮助
\h
查看用户
\du
查看当前用户
\c 或 select current_user;
退出
\q
查看数据库、所有者、字符集
\l
切换数据库
\c database_openGauss
列举表
\dt
查看表结构
\d users
查看索引
\di
查看当前数据存储目录
show data_directory;
查看文件路径
show config_file;
show hba_file;
show ident_file;
查看用户列表
SELECT * FROM pg_user;
查看用户属性
SELECT * FROM pg_authid;
查看数据库角色
SELECT * FROM PG_ROLES;
查看数据库时间
SELECT CURRENT_TIMESTAMP;
SELECT CURRENT_DATE;
SELECT CURRENT_TIME;