数据库
专栏收录该内容
1 篇文章0 订阅
订阅专栏
华为GAUSSDB集成
安装Centos7
Centos7
关闭防火墙服务
systemctl stop firewalld.service
systemctl disabled firewalld.service
systemctl status firewalld
1
2
3
禁用Swap交换内存
swapoff -a
swapoff -av
1
2
修改配置文件
# 修改selinux配置文件
vim /etc/selinux/config
# 修改SELINUX配置值为disabled
SELINUX=disabled
# 修改profile文件
vim /etc/profile
# 末尾添加
ulimit -c unlimited
# 重启系统
reboot
1
2
3
4
5
6
7
8
9
10
配置hostname和ip映射
# 配置主机名,自由配置,不能使用默认配置
vim /etc/hostname
# 配置地址映射
vim /etc/hosts
1
2
3
4
安装依赖
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/
wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
"""
注:提示-bash: wget: command not found (这是在Mini版本下)
解决办法:http://mirrors.163.com/.help/centos.html,下载对应的版本
将文件上传至/etc/yum.repos.d/
yum clean all
yum makecache
yum -y install wget
再重新执行即可
"""
yum clean all
yum install -y lksctp*
yum install -y java-1.8.0-openjdk* psmisc bzip2 python3 python3-devel
yum install -y libaio-devel flex bison ncurses-devel glibc-devel patch redhat-lsb-core
rpm -qa java-1.8.0-openjdk psmisc bzip2 libaio-devel flex bison ncurses-devel glibc-devel patch redhat-lsb-core lksctp-tools* python3 python3-develchecksctp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
配置时区、添加用户和用户组
# 配置时区
echo "export LANG=en_US.UTF-8" >> ~/.bash_profile
source ~/.bash_profile
env|grep LANG
rm -fr /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ll /etc/localtime
# 添加用户和用户组
groupadd dbgrp
useradd -g dbgrp omm
passwd omm
1
2
3
4
5
6
7
8
9
10
11
安装opengaussdb
# 创建存储目录
mkdir /opt/module/opengauss/
# 解压openGauss-3.0.0-CentOS-64bit-all.tar.gz
tar -zxvf /opt/software/openGauss-3.0.0-CentOS-64bit-all.tar.gz -C /opt/module/opengauss/
# 解压openGauss-3.0.0-CentOS-64bit-om.tar.gz
cd /opt/module/opengauss/
tar -zxvf openGauss-3.0.0-CentOS-64bit-om.tar.gz
# 配置环境变量
vi /etc/profile
export LD_LIBRARY_PATH=/opt/module/opengauss/script/gspylib/clib:$LD_LIBRARY_PATH
source /etc/profile
# 创建gaussdb单节点配置文件
vim /opt/module/opengauss/clusterconfig.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
# 配置信息
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<CLUSTER>
<!-- 数据库名称 -->
<PARAM name="clusterName" value="dbCluster" />
<!--数据库节点名称(配置的hostname) -->
<PARAM name="nodeNames" value="gaussdb" />
<!--数据库安装目录-->
<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.5.69"/>
</CLUSTER>
每台服务器上的节点部署信息 -->
<DEVICELIST>
<!--节点1上的部署信息 -->
<DEVICE sn="node1_hostname">
<!--节点1的主机名称 -->
<PARAM name="name" value="gaussdb"/>
<!--节点1所在的AZ及AZ优先级 -->
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!--节点1的IP,如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
<PARAM name="backIp1" value="192.168.5.69"/>
<PARAM name="sshIp1" value="192.168.5.69"/>
<!--dbnode-->
<PARAM name="dataNum" value="1"/>
<!--数据库端口-->
<PARAM name="dataPortBase" value="15400"/>
<PARAM name="dataNode1" value="/opt/huawei/install/data/dn"/>
<PARAM name="dataNode1_syncNum" value="0"/>
</DEVICE>
</DEVICELIST>
</ROOT>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 使用root权限,执行gs_preinstall脚本
cd /opt/module/opengauss/script
./gs_preinstall -U omm -G dbgrp -X /opt/module/openGauss/clusterconfig.xml
# 修改opengauss读写权限和用户和用户组
chmod -R 755 /opt/module/opengauss/
chown -R omm /opt/module/opengauss/
chgrp -R dbgrp /opt/module/opengauss/
# 执行安装脚本
su - omm
cd /opt/module/opengauss/script
# 注意安装过程中需要配置数据库密码
./gs_install -X /opt/module/opengauss/clusterconfig.xml
1
2
3
4
5
6
7
8
9
10
11
12
启动opengaussdb、配置加密方式、添加用户、配置远程连接
# 启动
./gs_om -t start
# 修改密码加密类型为MD5(默认时sha256)
gs_guc reload -N all -I all -c 'password_encryption_type=0'
# 连接
gsql -d postgres -p 15400
# 查看加密类型,若输出值为0则配置成功
show password_encryption_type;
# 由于加密规则改变,需要修改用户密码
alter user omm password 'gauss@123';
# 添加test用户
create user test with password 'test@1234';
# 授权
GRANT omm TO test;
# 退出
\q
# 配置远程连接,具体路径查看clusterconfig.xml配置文件
vim /opt/huawei/install/data/dn/pg_hba.conf
# 末尾加入
host all all 0.0.0.0/0 md5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
使用navicat连接
数据库类型: postgresql
ip: 宿主机ip
port: 配置文件中配置的port
username: test
password: test@1234
1
2
3
4
5
opengauss相关指令
# 启动
gs_om -t start
# 重启
gs_om -t restart
# 停止
gs_om -t stop
# 检查数据库性能
gs_om -t status --detail
gs_om -t status --all
1
2
3
4
5
6
7
8
9
JDBC连接
依赖配置
<dependency>
<groupId>org.opengauss</groupId>
<artifactId>opengauss-jdbc</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.6</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.0.M3</version>
</dependency>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
postgresql方式连接
public class PostgresqlTest {
public static void main(String[] args) {
ResultSet tablesResult = null;
try {
String driver = "org.postgresql.Driver";
String sourceURL = "jdbc:postgresql://192.168.5.69:15400/postgres";
String username = "name";
String passwd = "pwd";
Class.forName(driver);
Connection connection = DriverManager.getConnection(sourceURL, username, passwd);
DatabaseMetaData metaData = connection.getMetaData();
System.out.println(connection.getSchema());
tablesResult = metaData.getTables(null,"public", null, new String[]{"TABLE"});
while (tablesResult.next()) {
String tableName = tablesResult.getString("TABLE_NAME");
System.out.println(tableName);
}
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}finally {
IoUtil.close(tablesResult);
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
官方数据库驱动
public class GaussDbTest {
public static void main(String[] args) {
ResultSet tablesResult = null;
try {
String driver = "org.opengauss.Driver";
String sourceURL = "jdbc:opengauss://192.168.5.69:15400/postgres?schema=public";
String username = "name";
String passwd = "pwd";
Class.forName(driver);
Connection connection = DriverManager.getConnection(sourceURL, username, passwd);
DatabaseMetaData metaData = connection.getMetaData();
System.out.println(connection.getSchema());
tablesResult = metaData.getTables(null,"public", null, new String[]{"TABLE"});
while (tablesResult.next()) {
String tableName = tablesResult.getString("TABLE_NAME");
System.out.println(tableName);
}
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}finally {
IoUtil.close(tablesResult);
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Datax集成
模板文件
{
"job": {
"content": [
{
"reader": {
"name": "postgresqlreader",
"parameter": {
"column": [
"\"id\"","\"name\"","\"desc\""
],
"connection": [
{
"jdbcUrl": ["jdbc:postgresql://192.168.5.69:15400/postgres"],
"table": ["\"user\""]
}
],
"password": "test",
"username": "test@1234"
}
},
"writer": {
"name": "streamwriter",
"parameter": {
"encoding": "",
"print": true
}
}
}
],
"setting": {
"speed": {
"channel": "1"
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
注意:列名和表名需要使用双引号包围
执行结果
资源、参考博客路径
opengauss下载地址: https://opengauss.org/zh/download.html
clusterconfig.xml配置文件:https://www.bookstack.cn/read/openGauss-2.1-zh/installation-%E5%88%9B%E5%BB%BAXML%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6.md#单节点配置文件
opengauss安装1:https://blog.csdn.net/yxzone/article/details/115057333?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1-115057333-blog-112973261.pc_relevant_aa&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1-115057333-blog-112973261.pc_relevant_aa&utm_relevant_index=1
opengauss安装2:https://blog.csdn.net/qq_41619524/article/details/109722264
opengauss密码模式修改:https://cdn.modb.pro/db/393744
%7Edefault%7ECTRLIST%7Edefault-1-115057333-blog-112973261.pc_relevant_aa&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1-115057333-blog-112973261.pc_relevant_aa&utm_relevant_index=1
opengauss安装2:https://blog.csdn.net/qq_41619524/article/details/109722264
opengauss密码模式修改:https://cdn.modb.pro/db/393744