当前位置:首页 > 技术文章 > 正文内容

centos下安装openGuass数据库

arlanguage4个月前 (01-05)技术文章27

  1. 背景

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


  1. 介绍

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

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

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

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

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

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

  1. 系统设置
  1. 关闭SELINUX
vi /etc/selinux/config

#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加
:wq! #保存退出
setenforce 0 #使配置立即生效


  1. 修改主机名
vim /etc/hostname 
opengauss-master

#实时修改
hostnamectl set-hostname opengauss-master

#编辑配置文件
vi /etc/hosts 
127.0.0.1 opengauss-master localhost #修改localhost.localdomain为opengauss-master
192.168.21.128 opengauss-master


  1. 开启防火墙5432端口

忽略


  1. 操作系统参数设置
cat>> /etc/sysctl.conf <<EOF
net.ipv4.tcp_retries1=5
net.ipv4.tcp_syn_retries=5
net.sctp.path_max_retrans=10
net.sctp.max_init_retransmits=10
kernel.shmmax = 17179869184
kernel.shmall = 4194304
kernel.sem=  500 5120000 2500 9000
EOF

其他修改:

lsmod |grep sctp
yum -y install lksctp*
modprobe sctp
sysctl -p #设置立即生效
echo 17179869184 > /proc/sys/kernel/shmmax
echo 4194304 > /proc/sys/kernel/shmall
echo "* soft stack 3072" >> /etc/security/limits.conf
echo "* hard stack 3072" >> /etc/security/limits.conf
echo "* soft nofile 1000000" >> /etc/security/limits.conf
echo "* hard nofile 1000000" >> /etc/security/limits.conf
echo "* soft nproc unlimited" >> /etc/security/limits.d/90-nproc.conf
echo never > /sys/kernel/mm/transparent_hugepage/defrag
echo never > /sys/kernel/mm/transparent_hugepage/enabled
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/sh /etc/rc.d/rc.local


  1. 设置操作系统字符集编码
LANG=en_US.UTF-8
echo "LANG=en_US.UTF-8" >> /etc/profile
source /etc/profile
echo $LANG


  1. 安装依赖包
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.bak
ln -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! 保存退出
  1. 创建数据用户和用户组并设置权限
groupadd dbgrp
useradd -g dbgrp omm
echo 'omm@a1b2c3' | passwd --stdin omm
mkdir -p /data/server/openGauss
chmod 775 /data/server/openGauss -R
chown omm:dbgrp /data/server/openGauss -R
  1. openGuass安装准备
  1. 软件准备
wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/x86/openGauss-3.1.0-CentOS-64bit-all.tar.gz


#解压
cd /usr/local/src/openGauss
tar -zxvf openGauss-3.1.0-CentOS-64bit-all.tar.gz
tar -zxvf openGauss-3.1.0-CentOS-64bit-om.tar.gz
  1. 目录和配置文件
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>


  1. 预备安装脚本
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.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 host ip env
Successfully set host ip env.
Are you sure you want to create the user[omm] (yes/no)? yes
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.
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 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.


  1. 检查系统环境
./gs_checkos -i A -h opengauss-master --detail

显示:

[root@localhost script]# ./gs_checkos -i A -h opengauss-master --detail
Checking 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.
  1. 安装数据库
su - omm
chown omm.dbgrp /usr/local/src/openGauss/ -R
su - 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.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..
...
...
end deploy..


  1. 启动数据库
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 status
gs_om -t status --detail
gs_om -t status --all
gs_checkperf

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


  1. 创建数据库命令等
gsql -d postgres -p 5432
create 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  #退出控制台


  1. 开始openGauss数据库监听 支持远程连接
cd /data/server/openGauss/data/dn

cp postgresql.conf postgresql.conf-bak
cp pg_hba.conf pg_hba.conf-bak
vi /data/server/openGauss/data/dn/postgresql.conf
ssl = off
listen_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 - omm
cd /openGauss/script
./gs_om -t restart  #重启数据库
./gs_om -t stop # 停止数据库


  1. 参考

错误参考:https://support.huaweicloud.com/rds_faq/rds_faq_0300.html

知乎参考:https://zhuanlan.zhihu.com/p/366112479

错误参考:https://blog.csdn.net/u011868279/article/details/130356440

高斯数据库适配:https://blog.csdn.net/u012785397/article/details/131483193

高斯数据库的java连接:https://www.zhihu.com/question/596567826/answer/3015566358?utm_id=0

高斯数据库的C连接:https://docs-opengauss.osinfra.cn/en/docs/3.1.1/docs/BriefTutorial/odbc.html

高斯数据库的odbc库:https://github.com/opengauss-mirror/openGauss-connector-odbc/blob/master/docs/msdtc_pgxalib_tracing_README.txt

安装第三方库的编译库工具:https://github.com/opengauss-mirror/openGauss-third_party

华为官方安装手册:http://staff.ustc.edu.cn/~ypb/exp/CentOS-openGauss.pdf

mariadb兼容插件:https://blog.csdn.net/gallopingdb/article/details/131825336 这个值得研究下。

官网学习文档:https://docs-opengauss.osinfra.cn/zh/docs/5.0.0/docs/DatabaseAdministrationGuide/%E5%88%9B%E5%BB%BA%E5%92%8C%E7%AE%A1%E7%90%86%E8%A1%A8%E7%A9%BA%E9%97%B4.html

扫描二维码推送至手机访问。

版权声明:本文由AR编程网发布,如需转载请注明出处。

本文链接:http://www.arlanguage.com/post/608.html

分享给朋友:

“centos下安装openGuass数据库” 的相关文章

nginx 多域名配置 nginx多站点配置示例

Nginx 可以配置多个域名,以便根据不同的域名来处理不同的请求。下面是一个配置多个域名的例子:server { listen 80; server_name example1.com; location / { root /var/www/example1...

为何说捣腾 Nginx 少不了 Nginx-ui ?还自带 GPT 助手?

大家好,很高兴又见面了,我是"高级前端进阶",由我带着大家一起关注前端前沿、深入前端底层技术,大家一起进步,也欢迎大家关注、点赞、收藏、转发!什么是 Nginx UINginx UI 是一个基于 Web 的管理界面,旨在简化 Nginx 服务器的管理和配置。Yet another N...

nginx location 多root理解location

由于应用需求,这个 r 目录需要单独拉出来做处理,nginx 最开始是这样写的: server { root /home/webadm/htdocs; index index.php; location /r/ { root /diska/htdocs; } location ~ \.php { f...

深入Docker容器之日志篇

操作系统流重定向在linux系统中,运行一个命令,通常会是以下的方式:在linux 和 Unix系统中,在运行程序时,通常会有三种io流: stdin, stdout,stderr 。 stdin 是从外部设备或是键盘获取输入,而 stdout 是标准输出,stderr 是标准错误输出。而不管是标准...

常见nginx配置文件的主上下文指令有哪些?

Nginx 由模块组成,这些模块由配置文件中指定的指令(directive)来控制。指令被分为简单指令和块指令。简单指令由名称和用空格分隔的参数组成,并以分号 (;) 结尾。块指令与简单指令具有相同的结构,但是在分号的位置,它以一组用大括号 ({ 和 }) 括起来的额外指令结束。如果块指令可以在大括...

NGINX最常用的指令(备用查询)

服务管理sudo systemctl status nginx # nginx当前状态 sudo systemctl reload nginx # 重新加载 nginx sudo systemctl restart nginx # 重启nginx sudo nginx -t # 检查语法 ng...