龙空技术网

centos下安装openGuass数据库

码农世界 118

前言:

如今大家对“java连接高斯数据库配置”都比较关心,朋友们都想要剖析一些“java连接高斯数据库配置”的相关资讯。那么小编也在网上收集了一些对于“java连接高斯数据库配置””的相关知识,希望你们能喜欢,你们一起来学习一下吧!

背景

国产信创需要选择一个国产免费的数据库使用,openGuass是华为开源的数据库,相对比较成熟点,基于postgresql开发。

介绍

openGauss的数据库节点负责存储数据,其存储介质也是磁盘,本节主要从逻辑视角介绍数据库节点都有哪些对象,以及这些对象之间的关系。数据库逻辑结构如图1

Tablespace,即表空间,是一个目录,可以存在多个,里面存储的是它所包含的数据库的各种物理文件。每个表空间可以对应多个Database。

Database,即数据库,用于管理各类数据对象,各数据库间相互隔离。数据库管理的对象可分布在多个Tablespace上。

Datafile Segment,即数据文件,通常每张表只对应一个数据文件。如果某张表的数据大于1GB,则会分为多个数据文件存储。

Table,即表,每张表只能属于一个数据库,也只能对应到一个Tablespace。每张表对应的数据文件必须在同一个Tablespace中。

Block,即数据块,是数据库管理的基本单位,默认大小为8KB。

系统设置关闭SELINUX

vi /etc/selinux/config#SELINUX=enforcing #注释掉#SELINUXTYPE=targeted #注释掉SELINUX=disabled #增加:wq! #保存退出setenforce 0 #使配置立即生效

修改主机名

vim /etc/hostname opengauss-master#实时修改hostnamectl set-hostname opengauss-master#编辑配置文件vi /etc/hosts 127.0.0.1 opengauss-master localhost #修改localhost.localdomain为opengauss-master192.168.21.128 opengauss-master

开启防火墙5432端口

忽略

操作系统参数设置

cat>> /etc/sysctl.conf <<EOFnet.ipv4.tcp_retries1=5net.ipv4.tcp_syn_retries=5net.sctp.path_max_retrans=10net.sctp.max_init_retransmits=10kernel.shmmax = 17179869184kernel.shmall = 4194304kernel.sem=  500 5120000 2500 9000EOF

其他修改:

lsmod |grep sctpyum -y install lksctp*modprobe sctpsysctl -p #设置立即生效echo 17179869184 > /proc/sys/kernel/shmmaxecho 4194304 > /proc/sys/kernel/shmallecho "* soft stack 3072" >> /etc/security/limits.confecho "* hard stack 3072" >> /etc/security/limits.confecho "* soft nofile 1000000" >> /etc/security/limits.confecho "* hard nofile 1000000" >> /etc/security/limits.confecho "* soft nproc unlimited" >> /etc/security/limits.d/90-nproc.confecho never > /sys/kernel/mm/transparent_hugepage/defragecho never > /sys/kernel/mm/transparent_hugepage/enabledecho 'echo never > /sys/kernel/mm/transparent_hugepage/defrag' >> /etc/rc.d/rc.localecho 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.d/rc.localchmod +x /etc/rc.d/rc.local/usr/bin/sh /etc/rc.d/rc.local

设置操作系统字符集编码

LANG=en_US.UTF-8echo "LANG=en_US.UTF-8" >> /etc/profilesource /etc/profileecho $LANG

安装依赖包

yum install libaio-devel flex bison ncurses-devel glibc-devel patch redhat-lsb python3 bzip2#服务器需要用到Python-3.x命令,但CentOS 7.x 默认版本Python-2.7.x,需要切换到Python-3.x版本mv /usr/bin/python /usr/bin/python.bakln -s python3 /usr/bin/python#yum 安装vim /usr/bin/yum#!/usr/bin/python2.7:wq! 保存退出vim /usr/libexec/urlgrabber-ext-down/usr/bin/python2.7:wq! 保存退出
创建数据用户和用户组并设置权限
groupadd dbgrpuseradd -g dbgrp ommecho 'omm@a1b2c3' | passwd --stdin ommmkdir -p /data/server/openGausschmod 775 /data/server/openGauss -Rchown omm:dbgrp /data/server/openGauss -R
openGuass安装准备软件准备
wget 解压cd /usr/local/src/openGausstar -zxvf openGauss-3.1.0-CentOS-64bit-all.tar.gztar -zxvf openGauss-3.1.0-CentOS-64bit-om.tar.gz
目录和配置文件
vi /usr/local/src/openGauss/cluster_config.xml

配置文件:

<?xml version="1.0" encoding="UTF-8"?><ROOT><!-- openGauss整体信息 --><CLUSTER><!-- 数据库名称 --><PARAM name="clusterName" value="huaweidbCluster" /><!-- 数据库节点名称(主机的hostname名称) --><PARAM name="nodeNames" value="opengauss-master" /><!-- 数据库安装目录--><PARAM name="gaussdbAppPath" value="/data/server/openGauss/app" /><!-- 日志目录--><PARAM name="gaussdbLogPath" value="/data/server/openGauss/log/omm" /><!-- 临时文件目录--><PARAM name="tmpMppdbPath" value="/data/server/openGauss/tmp" /><!-- 数据库工具目录--><PARAM name="gaussdbToolPath" value="/data/server/openGauss/om" /><!-- 数据库core文件目录--><PARAM name="corePath" value="/data/server/openGauss/corefile" /><!-- 节点IP,与数据库节点名称列表一一对应 --><PARAM name="opengauss-master" value="10.22.18.235"/></CLUSTER><!-- 每台服务器上的节点部署信息 --><DEVICELIST><!-- 节点1上的部署信息 --><DEVICE sn="opengauss-master"><!-- 节点1的主机名称 --><PARAM name="name" value="opengauss-master"/><!-- 节点1所在的AZ及AZ优先级 --><PARAM name="azName" value="AZ1"/><PARAM name="azPriority" value="1"/><!-- 节点1的IP,如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP --><PARAM name="backIp1" value="10.22.18.235"/><PARAM name="sshIp1" value="10.22.18.235"/><!--dbnode--><PARAM name="dataNum" value="1"/><PARAM name="dataPortBase" value="5432"/><PARAM name="dataNode1" value="/data/server/openGauss/data/dn"/><PARAM name="dataNode1_syncNum" value="0"/></DEVICE></DEVICELIST></ROOT>

预备安装脚本

cd /openGuass/script; ./gs_preinstall -U omm -G dbgrp -X /usr/local/src/openGauss/cluster_config.xml

显示:

[root@localhost script]# ./gs_preinstall -U omm -G dbgrp -X /usr/local/src/openGauss/cluster_config.xmlParsing the configuration file.Successfully parsed the configuration file.Installing the tools on the local node.Successfully installed the tools on the local node.Setting host ip envSuccessfully set host ip env.Are you sure you want to create the user[omm] (yes/no)? yesPreparing 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.Set and check OS parameter.Setting OS parameters.Successfully set OS parameters.Warning: Installation environment contains some warning messages.Please get more details by "/openGuass/script/gs_checkos -i A -h opengauss-master --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 fileSuccessfully set core path.Setting pssh pathSuccessfully 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.

检查系统环境

./gs_checkos -i A -h opengauss-master --detail

显示:

[root@localhost script]# ./gs_checkos -i A -h opengauss-master --detailChecking items:    A1. [ OS version status ]                                   : Normal             [opengauss-master]        centos_7.9.2009_64bit      A2. [ Kernel version status ]                               : Normal             The names about all kernel versions are same. The value is "3.10.0-1160.105.1.el7.x86_64".    A3. [ Unicode status ]                                      : Normal             The values of all unicode are same. The value is "LANG=en_US.UTF-8".   ...   ...    A13.[ Firewall service status ]                             : Normal             The firewall service is stopped.                       A14.[ THP service status ]                                  : Normal             The THP service is stopped.                        Total numbers:14. Abnormal numbers:0. Warning numbers:3.
安装数据库
su - ommchown omm.dbgrp /usr/local/src/openGauss/ -Rsu - omm #切换到omm用户cd /usr/local/src/openGauss/script/gs_install -X /usr/local/src/openGauss/cluster_config.xml  --gsinit-parameter="--encoding=UTF8" -- dn-guc="max_process_memory=2GB" --dn-guc="shared_buffers=128MB" --dnguc="bulk_write_ring_size=128MB" --dn-guc="cstore_buffers=16MB" encoding 设置字符集; max_process_memory 设置一个数据库节点可用的最大物理内存;shared_buffers 设置 openGauss 使用的共享内存大小; bulk_write_ring_size 大批量数据写入触发时,该操作使用的环形缓冲区大小;cstore_buffers 设置列存所使用的共享缓冲区的大小。  #输入两次密码omm的用户密码:Dus^12345

显示:

[omm@opengauss-master script]$ gs_install -X /usr/local/src/openGauss/cluster_config.xmlParsing 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........end deploy..

启动数据库

gs_ctl start -D /data/server/openGauss/data/dn

显示:

[omm@opengauss-master script]$ gs_ctl start -D /data/server/openGauss/data/dn[2024-02-22 11:28:06.262][263602][][gs_ctl]: gs_ctl started,datadir is /data/server/openGauss/data/dn [2024-02-22 11:28:06.273][263602][][gs_ctl]:  another server might be running; Please use the restart command

常用命令:

#查看数据库状态gs_om -t statusgs_om -t status --detailgs_om -t status --allgs_checkperf#查看进程ps -ef | grep gaussdb | egrep -v "grep"#查看实例状态gs_om -t status --detail#进入控制台gsql -d postgres -p 5432select version(); #查看版本SHOW server_version;SELECT * FROM pg_settings WHERE NAME='server_version';\q  #退出控制台

创建数据库命令等

gsql -d postgres -p 5432create user admin with password "Dus^12345";create database testdb owner admin;GRANT ALL PRIVILEGES TO admin;-- GRANT ALL ON SCHEMA public TO admin;-- 记得在创建数据库后再次执行一次,不然无法创建表GRANT ALL PRIVILEGES to admin;\c testdb admin;create schema testdb authorization admin;create table test(id int,name varchar(200));insert into test values (1,'myname');select * from test;\q  #退出控制台

开始openGauss数据库监听 支持远程连接

cd /data/server/openGauss/data/dncp postgresql.conf postgresql.conf-bakcp pg_hba.conf pg_hba.conf-bakvi /data/server/openGauss/data/dn/postgresql.confssl = offlisten_addresses = 'localhost,192.168.21.100' #192.168.21.100需要替换为openGauss所在节点实际IP。password_encryption_type = 1  #修改为1,同时支持sha256 + md5加密,支持用pgsql客户端连接工具#Password storage type, 0 is md5 for PG, 1 is sha256 + md5, 2 is sha256 only:wq! 保存退出vi /data/server/openGauss/data/dn/pg_hba.conf# IPv4 local connections:host all all 0.0.0.0/0 sha256#host all admin 0.0.0.0/0 md5:wq! 保存退出增加Data Studio所在Windows 机器的IP远程访问连接许可,新增一行然后保存退出。su - ommcd /openGauss/script./gs_om -t restart  #重启数据库./gs_om -t stop # 停止数据库

参考

错误参考:

知乎参考:

错误参考:

高斯数据库适配:

高斯数据库的java连接:

高斯数据库的C连接:

高斯数据库的odbc库:

安装第三方库的编译库工具:

华为官方安装手册:

mariadb兼容插件: 这个值得研究下。

官网学习文档:

标签: #java连接高斯数据库配置