国产开源数据库OpenGauss的安装运行
步骤一:OpenGauss 的安装
环境
OS:openEuler 20.03 64bit with ARM
架构:arm64
部署:单机
安装过程
1、环境配置
安装依赖包:
yum install libaio-devel flex bison ncurses-devel glibc-devel patch readline-devel
2、创建 xml 配置文件
创建 cluster_config.xml 配置文件并进行配置
<!--dbnode-->
<PARAM name="dataNum" value="1"/>
<!--DBnode端口号-->
<PARAM name="dataPortBase" value="26000"/>
<!--DBnode主节点上数据目录,及备机数据目录-->
<PARAM name="dataNode1" value="node1"/>
<!--DBnode节点上设定同步模式的节点数-->
<PARAM name="dataNode1_syncNum" value="0"/>
</DEVICE>
</DEVICELIST>
注意节点 hostname 应与/etc/hostname 中保持一致
3、初始化安装环境
1.以 root 用户登录待安装 openGauss 的任意主机,并按规划创建存放安装包的目录。
mkdir -p /opt/software/openGauss
chmod 755 -R /opt/software
2.下载安装包并将配置文件“cluster_config.xml”都上传至上一步所创建的目录中。
wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/2.0.1/arm/openGauss-2.0.1-openEuler-64bit-all.tar.gz
3.解压安装包。
tar -zxvf openGauss-2.0.1-openEuler-64bit-all.tar.gz
tar jxvf openGauss-2.0.1-openEuler-64bit.tar.bz2
tar -zxvf openGauss-2.0.1-openEuler-64bit-om.tar.gz
tar -zxvf upgrade_sql.tar.gz
4.进入到工具脚本存放目录下。
cd /opt/software/openGauss/script
5.如果是 openEuler 的操作系统为确保适配 python 版本,执行如下命令打开 gspylib/common/CheckPythonVersion.py 文件,将 if not pythonVersion = = (3, 6):修改为 if not pythonVersion > = (3, 6):,键入“ESC”键进入指令模式,执行:wq保存并退出修改。(我在实际操作中进入后发现无需修改)
vi gspylib/common/CheckPythonVersion.py
6.如果是 openEuler 的操作系统,执行如下命令打开 performance.sh 文件,用#注释 sysctl -w vm.min_free_kbytes=112640 &> /dev/null,键入“ESC”键进入指令模式,执行:wq保存并退出修改。
vi /etc/profile.d/performance.sh
7.为确保 openssl 版本正确,执行预安装前请加载安装包中 lib 库。执行命令如下,其中{packagePath}为用户安装包放置的路径,本示例中为/opt/software/openGauss。
export LD_LIBRARY_PATH=/opt/software/openGauss/script/gspylib/clib:$LD_LIBRARY_PATH
8.为确保成功安装,检查 hostname 与 /etc/hostname 是否一致。预安装过程中,会对 hostname 进行检查。
9.使用 gs_preinstall 准备好安装环境。若为共用环境需加入--sep-env-file=ENVFILE 参数分离环境变量,避免与其他用户相互影响,ENVFILE 为用户自行指定的环境变量分离文件的路径。
采用交互模式执行前置,并在执行过程中自动创建操作系统 root 用户互信和 omm 用户互信:
./gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/cluster_config.xml
在执行中会要求输入 omm 用户的密码。
运行结果应类似:
plat1:/opt/software/openGauss/script # ./gs_preinstall -U omm -G dbgrp -X /opt/software/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.
Are you sure you want to create trust for root (yes/no)? yes
Please enter password for root.
Password:
Creating SSH trust for the root permission user.
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.
Successfully distributed SSH trust file to all node.
Verifying SSH trust on all hosts.
Successfully verified SSH trust on all hosts.
Successfully created SSH trust.
Successfully created SSH trust for the root permission user.
Setting pssh path
Successfully set core path.
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
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.
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.
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.
Successfully distributed SSH trust file to all node.
Verifying SSH trust on all hosts.
Successfully verified SSH trust on all hosts.
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.
Setting SCTP service.
Successfully set SCTP service.
Set and check OS parameter.
Setting OS parameters.
Successfully set OS parameters.
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.
4、执行安装
内存小于安装要求的 32G 应该做一些配置修改:
vim /etc/sysctl.conf
kernel.shmall = 1125899906842624
kernel.shmmax = 1351079888211149
vim /opt/huawei/install/data/db1/postgresql.conf
cstore_buffers=16MB
bulk_write_ring_size=128MB
shared_buffers=128MB
max_process_memory=2GB
max_connections=10
切换到 omm 用户下执行安装:
su - omm
gs_install -X /opt/software/openGauss/cluster_config.xml
步骤二 数据库的简单链接与使用
1、创建新用户,新数据库并赋予权限
使用 gsql 用 omm 管理账号登陆,创建新用户 jack,创建新数据库 testjack,赋予权限,执行
CREATE USER jack PASSWORD 'Gaussdba@Mpp';
CREATE DATABASE testjack OWNER jack;
GRANT SELECT ON pg_catalog.pg_roles to jack;
GRANT SELECT ON pg_catalog.pg_user_status to jack;
GRANT ALL PRIVILEGES on TABLESPACE pg_default,pg_global TO jack;
然后退出,使用 jack 用户登录 gsql
gsql -U jack -d testjack -p "Gaussdba@Mpp"
创建 SCHEMA
CREATE SCHEMA jack AUTHORIZATION jack;
退出 gsql,赋予 jack 权限,这里 client_address 是客户端的地址
gs_guc set -N all -I all -h "host all jack client_address/32 sha256
或者也可以修改 pg_hba.conf,添加
host all jack client_address/32 sha256
2、允许客户端访问数据库
执行,这里的 client_address 是要客户端的地址, listen_addresses 是参数名。
gs_guc set -I all -c "listen_addresses='client_address'"
或在使用 omm 账号在 gsql 中
ALTER SYSTEM SET listen_addresses TO "client_address";
之后重启数据库
3、关闭防火墙,打开端口
4、使用 Data Studio 访问数据库
可在 opengauss 官网下载 DATA STUDIO 应用
填入对应参数,注意这里应去掉启用 SSL 的选项,因为 SSL 还需要配置证书或密钥。
连接后的界面
5、使用 JDBC 访问数据库
我这里使用 windows 系统作为客户端连接数据库。
在 opengauss 网站下载对应的 JDBC 包,并解压。
创建 Gauss.java 文件
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.CallableStatement;
import java.sql.Types;
import java.util.Collections;
import java.util.Properties;
public class Gauss {
public static void main(String[] args) {
Connection connection;
ResultSet resultSet;
String url = "jdbc:postgresql://address:port/testjack"; //address 地址 port 端口 testjack 数据库名
String user = "××××"; // 数据库用户名
String password = "××××"; // 对应密码
String sql;
if(args.length > 0)
{
sql = args[0];
}
else
{
System.out.println("输入一条sql语句");
return;
}
if ((connection = getConnect(user, password, url)) != null) {
System.out.println(connection.toString());
}
if ((resultSet = execSql(connection, sql)) != null)
{
}
}
// 以下代码将获取数据库连接操作封装为一个接口,可通过给定用户名和密码来连接数据库。
public static Connection getConnect(String username, String passwd, String url) {
// 驱动类。
String driver = "org.postgresql.Driver";
// 数据库连接描述符。
String sourceURL = url;
Connection conn = null;
try {
// 加载驱动。
Class.forName(driver);
} catch (Exception e) {
e.printStackTrace();
return null;
}
try {
// 创建连接。
conn = DriverManager.getConnection(sourceURL, username, passwd);
System.out.println("Connection succeed!");
} catch (Exception e) {
e.printStackTrace();
return null;
}
return conn;
};
// 以下代码将使用Properties对象作为参数建立连接
public static Connection getConnectUseProp(String username, String passwd, String url) {
// 驱动类。
String driver = "org.postgresql.Driver";
// 数据库连接描述符。
String sourceURL = url + "?";
Connection conn = null;
Properties info = new Properties();
try {
// 加载驱动。
Class.forName(driver);
} catch (Exception e) {
e.printStackTrace();
return null;
}
try {
info.setProperty("user", username);
info.setProperty("password", passwd);
// 创建连接。
conn = DriverManager.getConnection(sourceURL, info);
System.out.println("Connection succeed!");
} catch (Exception e) {
e.printStackTrace();
return null;
}
return conn;
};
public static ResultSet execSql(Connection conn, String sql) {
Statement stmt = null;
ResultSet rs = null;
SQLWarning sqlw = null;
try {
stmt = conn.createStatement();
// 执行普通SQL语句。
stmt.execute(sql);
if((sqlw = stmt.getWarnings()) != null)
System.out.println(sqlw.toString());
if((rs = stmt.getResultSet()) != null)
printResultSet(rs);
stmt.close();
} catch (SQLException e) {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
e.printStackTrace();
}
return rs;
}
private static void printResultSet(ResultSet rs)
{
String line = "";
try {
ResultSetMetaData rsmd = rs.getMetaData();
for(int i = 1; i <= rsmd.getColumnCount(); i ++)
{
String label = rsmd.getColumnLabel(i).toString();
System.out.print(label + "\t");
line += String.join("", Collections.nCopies(label.length(), "-")) + "\t";
}
System.out.println("\n" + line);
while(rs.next())
{
for(int i = 1; i <= rsmd.getColumnCount(); i ++)
{
System.out.print(rs.getObject(i).toString() + "\t");
}
System.out.println("");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
编译
javac .\Gauss.java -encoding "utf-8"
运行,我这里将 postgresql.jar 放在同一目录下,创建一个表 nt 作为测试
java -cp ".;postgresql.jar" Gauss "CREATE TABLE nt(id INTEGER, name VARCHAR(20))"
java -cp ".;postgresql.jar" Gauss "INSERT into nt(id, name) VALUES (1,'n1'),(2,'n2'),(3,'n3');"
java -cp ".;postgresql.jar" Gauss "SELECT * FROM nt;"
最后一句输出结果为,可以看到成功进行了连接和操作。
九月 13, 2021 11:58:25 上午 org.postgresql.core.v3.ConnectionFactoryImpl openConnectionImpl
信息: [75000bb7-1475-4579-94cb-f53a01bec9eb] Try to connect. IP: ...***
九月 13, 2021 11:58:26 上午 org.postgresql.core.v3.ConnectionFactoryImpl openConnectionImpl
信息: [...:/...:**] Connection is established. ID: 75000bb7-1475-4579-94cb-f53a01bec9eb
九月 13, 2021 11:58:26 上午 org.postgresql.core.v3.ConnectionFactoryImpl openConnectionImpl
信息: Connect complete. ID: 75000bb7-1475-4579-94cb-f53a01bec9eb
Connection succeed!
id name
1 n1
2 n2
3 n3
国产开源数据库OpenGauss的安装运行的更多相关文章
- 国产开源数据库:腾讯云TBase在分布式HTAP领域的探索与实践
导语 | TBase 是腾讯TEG数据平台团队在开源 PostgreSQL 的基础上研发的企业级分布式 HTAP 数据库系统,可在同一数据库集群中同时为客户提供强一致高并发的分布式在线事务能力以及高 ...
- 小试国产开源HTAP分布式NewSQL数据库TiDB-v5.3.0
概述 定义 TiDB官网 https://pingcap.com/zh/ 最新版本为5.3.0 TiDB GitHub源码 https://github.com/pingcap/tidb TiDB是由 ...
- NoSQL数据库之国产开源产品:SequoiaDB 分析前言
随着互联网技术的发展,面对海量数据的存储和分析,传统关系型数据库已经无法满足,由此衍生出一种与关系型数据库区别开的数据库NoSQL(Not Only SQL). 国外做的比较成熟的NoSQL有Mong ...
- Mycat分布式数据库架构解决方案--Linux安装运行Mycat
echo编辑整理,欢迎转载,转载请声明文章来源.欢迎添加echo微信(微信号:t2421499075)交流学习. 百战不败,依不自称常胜,百败不颓,依能奋力前行.--这才是真正的堪称强大!!! Myc ...
- 2015年热门的国产开源软件TOP 50
2015年热门的国产开源软件TOP 50 开源中国在 2015 年得到了快速的发展,单开源软件收藏量就接近 40000 款,其中不乏优质的国产开源项目.本文从软件的收藏.下载.访问等多角度挑选出了 2 ...
- MySQL、PostgreSQL、Ingres r3、MaxDB等开源数据库的详细比较
1.MySQL 5 作为当今最流行的开放源码数据库之一,MySQL数据库为用户提供了一个相对简单的 解决方案,适用于广泛的应用程序部署,能够降低用户的TCO.MySQL是一个多线程.结构化查询语言(S ...
- MySQL全世界最流行的开源数据库软件
誉天全国首推全球市场占有率第二的数据库——MySQL培训课程,阿里巴巴.新浪等知名企业正在使用MySQL数据库系统,而这方面的人才需求也是供不应求,誉天作为国内2014年首批ORACLE官方授权MyS ...
- Mac 下安装运行Rocket.chat
最近花了一周的时间,复习了HTML.CSS.原生JS,并学习了Node.js.CoffeeScript.js.MongoDB,入了下门. 因为准备在Rocket.chat 上做二次开发,所以先下载和安 ...
- 数据库MySql的安装
1.MySQL概述 MySQL最初是由“MySQL AB公司”开发的一套关系型数据库管理系统(RDBMS-Relation DataBase Management System).MySQL不仅是最流 ...
- Activity工作流(2)-入门安装运行第一个例子
转: Activity工作流(2)-入门安装运行第一个例子 置顶 2017年05月24日 15:58:50 li_ch_ch 阅读数:24432 版权声明:本文为博主原创文章,未经博主允许不得转载 ...
随机推荐
- 【Azure Developer】在使用中国区 Azure AD B2C时, AUTHORITY的值是什么呢?
问题描述 使用MSAL4J的SDK调用(源码地址:https://github.com/Azure-Samples/ms-identity-msal-java-samples/tree/main/3. ...
- 【Azure 应用服务】Azure Function 不能被触发
问题描述 Azure Function 不能被Postman 触发,错误信息如下: Error: write EPROTO 4020778632:error:100000f7:SSL routines ...
- 【Azure 应用服务】如何为Web Jobs 安装Python包呢?
问题描述 WebJobs 怎么安装Python包? 问题解答 第一步:登录到App Service的高级管理工具(Kudu:https://<webappname>.scm.chinacl ...
- Linux安装Docker教程
介绍 Docker利用Linux核心中的资源分脱机制,例如cgroups,以及Linux核心名字空间(name space),来创建独立的软件容器(containers).可以在单一Linux实体下运 ...
- 10、zookeeper客户端curator
curator介绍 https://blog.csdn.net/wo541075754/article/details/68067872 关于第三方客户端的小介绍 zkClient有对dubbo的一些 ...
- QT 使用QPixmap自定义光标 缩放图像模糊问题
QT中定义光标可以使用 Qt::CursorShape 预定义 的光标,也可以使用 QBitmap 和 QPixmap 自己绘制光标.QBitmap 只有黑白2色,QPixmap可以绘制彩色光标.使用 ...
- day01-数据库的安装和使用
Java数据库的安装和使用 1.数据库的作用 一个问题:淘宝网.京东.微信抖音,都有各自的功能,那么我们退出系统的时候,为什么信息还在? 解决之道-文件,数据库 为了解决上诉问题,使用更加利于管理数据 ...
- zhelper-cvtool
https://github.com/bbqz007/zhelper-cvtool cvtool images/SuperMario.mp4 anno,cascade cvtool images/Su ...
- 自己想到的几道Java面试题
1.在抽象类中能否写main方法,为什么? 2.在接口中能否写main方法,为什么? 3.Java能否使用静态局部变量,为什么? 4.Java类变量,实例变量,局部变量在多线程环境下是否线程安全,为什 ...
- 记录--关于前端的音频可视化-Web Audio
这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 背景 最近听音乐的时候,看到各种动效,突然好奇这些音频数据是如何获取并展示出来的,于是花了几天功夫去研究相关的内容,这里只是给大家一些代码 ...