作者:葛二萌

一. openGauss单机版安装

硬件及软件环境:

硬件环境:虚拟机的内存8GB,4核心CPU,900G磁盘(非必须)<o:p></o:p>

软件环境:CentOS7.6<o:p></o:p>

数据库版本:opengauss2.0企业版:openGauss-2.0.0-CentOS-64bit-all.tar.gz

<o:p></o:p>

注:内存一定要8G以上,不然没有足够的内存安装会失败。

安装步骤:

1.1.  关闭防火墙

#停止firewall
systemctl stop firewalld.service
#禁止firewall开机启动

systemctl disable firewalld.service
#检查防火墙是否关闭。

systemctl status firewalld

说明:<o:p></o:p>

若防火墙状态显示为active (running),则表示防火墙未关闭。

若防火墙状态显示为inactive (dead),则无需再关闭防火墙。

1.2.  设置时区和时间<o:p></o:p>

将各数据库节点的时区设置为相同时区,可以将/usr/share/zoneinfo/目录下的时区文件拷贝为/etc/localtime文件。

cp /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime<o:p></o:p>

1.3.  关闭SELinux <o:p></o:p>

[root@node1 ~]#

getenforce
sed -i 's/^SELINUX=./SELINUX=disabled/’ /etc/selinux/config
setenforce 0
getenforce
#检查

cat /etc/selinux/config|grep SELINUX

输出:<o:p></o:p>

# SELINUX= can take one of these three values:<o:p></o:p>

SELINUX=disabled<o:p></o:p>

# SELINUXTYPE= can take one of three values:<o:p></o:p>

SELINUXTYPE=targeted <o:p></o:p>

[root@node1 ~]#

1.4.  修改/etc/hosts

#添加一行

cat >>/etc/hosts <<EOF
192.168.183.28 node1
EOF

1.5.  配置库路径

cat>> /etc/profile<<EOF
export LD_LIBRARY_PATH=/opt/software/openGauss/script/gspylib/clib:KaTeX parse error: Expected 'EOF', got '&' at position 51: …><!--[if-->1.6.&̲nbsp;<!--[endif… python3 -V

Python 3.6.8

其他软件包,如需要可以安装(也可以直接使用安装):

yum install -y libaio-devel flex bison ncurses-devel glibc-devel patch redhat-lsb-core readline-devel
yum install openssl -y
yum install -y java-1.8.0-openjdk* psmisc bzip2 python3 python3-devel lksctp*
reboot #重新启动服务器

<o:p></o:p>

1.10.  创建安装包的存放目录

mkdir -p /opt/software/openGauss
chmod 755 -R /opt/software

1.11.  下载openGauss数据库软件<o:p></o:p>

下载地址为:https://opengauss.org/zh/download.html

<o:p></o:p>

下载完成后上传到centos中。 

1.12.  解压缩openGauss DBMS介质

cd /opt/software/openGauss
tar -zxvf openGauss-2.0.0-CentOS-64bit-all.tar.gz
tar -zxvf openGauss-2.0.0-CentOS-64bit-om.tar.gz

1.13.  创建XML文件<o:p></o:p>

<o:p>下面是xml文件官方模板,一般只需要改一下自己centos机器的IP</o:p>

<o:p></o:p>

cat > clusterconfig.xml<<EOF
<?xml version=“1.0” encoding=“UTF-8”?>
<ROOT>

<!-- openGauss整体信息 -->
<CLUSTER>
<!-- 数据库名称 -->
<PARAM name=“clusterName” value=“dbCluster” />
<!-- 数据库节点名称(hostname) -->
<PARAM name=“nodeNames” value=“node1” />
<!-- 数据库安装目录–>
<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.183.28”/>
</CLUSTER>
<!-- 每台服务器上的节点部署信息 -->
<DEVICELIST>
<!-- 节点1上的部署信息 -->
<DEVICE sn=“node1”>
<!-- 节点1的主机名称 -->
<PARAM name=“name” value=“node1”/>
<!-- 节点1所在的AZ及AZ优先级 -->
<PARAM name=“azName” value=“AZ1”/>
<PARAM name=“azPriority” value=“1”/>
<!-- 节点1的IP,如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
<PARAM name=“backIp1” value=“192.168.183.28”/>
<PARAM name=“sshIp1” value=“192.168.183.28”/>
<!–dbnode–>
<PARAM name=“dataNum” value=“1”/>
<PARAM name=“dataPortBase” value=“26000”/>
<PARAM name=“dataNode1” value="/opt/huawei/install/data/dn"/>
<PARAM name=“dataNode1_syncNum” value=“0”/>
</DEVICE>
</DEVICELIST>
</ROOT>
EOF

1.14.  检查环境变量

echo KaTeX parse error: Undefined control sequence: \Users at position 59: …src="file:///C:\̲U̲s̲e̲r̲s̲\ADMINI~1\AppDa… cd /opt/software/openGauss/script
[omm@node1 script]$ cp …/clusterconfig.xml .
[omm@node1 script]$ gs_install -X /opt/software/openGauss/script/clusterconfig.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:huawei@1234
Please repeat for database:huawei@1234
begin to create CA cert files
The sslcert will be generated in /opt/huawei/install/app/share/sslcert/om
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.
Configuring pg_hba on all nodes.
Configuration is completed.
Successfully started cluster.
Successfully installed application.
end deploy…

查看数据库状态:

[omm@node1 script]$ gs_om -t status

会出现以下内容:

<o:p> </o:p>-----------------------------------------------------------------------

cluster_name    : dbCluster
cluster_state : Normal
redistributing : No
---------------------------------------------------------------------
[omm@node1 script] < / s p a n > < / c o d e > < / p r e > < p > < b > 启 动 数 据 库 ( 安 装 完 默 认 已 经 启 动 ) : < / b > < / p > < p r e t y p e = " S h e l l S e s s i o n " > < c o d e > [ o m m @ n o d e 1 d b 1 ] </span></code></pre><p><b>启动数据库(安装完默认已经启动):</b></p><pre type="Shell Session"><code>[omm@node1 db1] </span></code></pre><p><b></b></p><pretype="ShellSession"><code>[omm@node1db1] gs_om -t start

Starting cluster.<o:p></o:p>

=<o:p></o:p>

[SUCCESS] node1:<o:p></o:p>

[2021-04-01 16:50:13.969][29784][][gs_ctl]: gs_ctl started,datadir is /opt/huawei/install/data/dn <o:p></o:p>

[2021-04-01 16:50:13.974][29784][][gs_ctl]:  another server might be running; Please use the restart command<o:p></o:p>

=<o:p></o:p>

Successfully started.<o:p></o:p>


使用omm用户执行下面的操作。

登录到数据库

gsql -d postgres -p 26000 -r
#执行上条命令会出现以下提示内容。gsql ((openGauss 2.0.0 build 78689da9) compiled at 2021-03-31 21:04:03 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type “help” for help.

其他基本的命令

\q  #退出会话
gs_om -t stop #关闭数据库
gs_om -t restart #重启数据库

二.Python连接openGauss

以下环境也在centos7.6中。

遇到过的问题踩坑记录:解决过程:

    第一次远程连接openGauss时使用的是omm初始用户,结果报错:不允许使用omm用户来远程连接

    为此我们新建一个gem用户。

    新建用户gem: 

    CREATE USER gem with sysadmin PASSWORD ‘huawei@1234’;

    配置文件/opt/huawei/install/data/dn/pg_hba.conf 追加:host all all 0.0.0.0/0 sha256 ,如下图所示:


    其中,第一个all代表任意数据库   第二个all代表任何用户(除了初始用户)   0.0.0.0/0代表任意主机  加密仅支持sha256。

    修改配置后重启数据库

        gs_om -t restart

2.1 安装python相关依赖包

python可以借助jaydebeapi第三方库来连接openGauss,搭建过程如下:

 pip3 install prometheus_client
 pip3 install Jpype1
 pip3 install jaydebeapi

<o:p></o:p>

  如果linux下没有安装pip,安装方法:<o:p></o:p>

    wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo<o:p></o:p>

    yum -y install python-pip<o:p></o:p>

  在官网下载openGauss JDBC驱动(postgresql.jar):https://opengauss.org/zh/download.html

    解压到某个目录,如/root

2.2 编写测试连接脚本

在/root下编写测试脚本demo.py :

import jaydebeapi
url = ‘jdbc:postgresql://192.168.183.28:26000/postgres’
user = ‘gem’
password = ‘huawei@1234’
dirver = ‘org.postgresql.Driver’
jarFile = ‘/root/postgresql.jar’
sqlStr = “”“SELECT 666;”""
conn = jaydebeapi.connect(dirver, url, [user, password], jarFile)
curs = conn.cursor()
curs.execute(sqlStr)
result = curs.fetchall()
print(result)
curs.close()
conn.close()

 在命令行demo脚本当前目录执行 python3 demo.py,结果如下:

[(666,)]

此时连接成功

三. 总结
本文提供了Python连接openGauss的一种方式。个人认为过程中比较重要的点是虚拟机内存设置一定要到8G,第一次安装openGauss单机版由于内存没给到8G而导致安装失败。另外,不能使用初始用户来远程连接openGauss,并且配置文件/opt/huawei/install/data/dn/pg_hba.conf 要追加:host all all 0.0.0.0/0 sha256 。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐