openGauss安装使用(openEuler服务器)
openEuler服务器上安装使用openGauss数据库的步骤以及Django使用openGauss的方法
·
安装Guass数据库
修改python环境
[root@ecs-6d3f ~]# python -V --2.6.8
[root@ecs-6d3f ~]# cd /usr/bin
[root@ecs-6d3f bin]# mv python python.bak
[root@ecs-6d3f bin]# ln -s python3 /usr/bin/python
python -V --3.7.4
关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
# 关闭之后查看状态,应为inactive
systemctl status firewalld

修改/etc/selinux/config文件中的“SELINUX”值为“disabled”。
[root@ecs-6d3f ~]# vim /etc/selinux/config
SELINUX=disabled

在/etc/profile文件中添加环境变量
vim /etc/profile
# 设置 HISTSIZE=0
HISTSIZE=0
# 下面四行加到文件最后
export LANG=en_US.UTF‐8
export packagePath=/opt/software/openGauss
export LD_LIBRARY_PATH=$packagePath/lib:$LD_LIBRARY_PATH
export PATH=/opt/software/openGauss/bin:$PATH
# wq保存退出后执行下面的命令
source /etc/profile


将交换内存关闭
# 关闭交换内存
swapoff -a
调整系统参数值
# 执行如下命令打开performance.sh文件
vi /etc/profile.d/performance.sh
# 用#注释sysctl -w vm.min_free_kbytes=112640 &> /dev/null
#sysctl -w vm.min_free_kbytes=112640 &> /dev/null

安装软件依赖包
yum install
libaio-devel
flex
bison
ncurses-devel
glibc-devel
patch
readline-devel
libnsl
# 用yum命令安装这些包
准备安装包和数据库管理用户
# 创建安装目录
mkdir -p /opt/software/openGauss
# 进入安装目录
cd /opt/software/openGauss
# 将数据库安装包下载到该目录
wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/x86_openEuler/openGauss-3.1.0-openEuler-64bit.tar.bz2
# 将安装包解压
tar -jxf openGauss-3.1.0-openEuler-64bit.tar.bz2
# 更改权限
chmod 755 -R /opt/software
# 创建用户组
groupadd dbgroup
# 创建用户omm
useradd -g dbgroup omm
# 设置密码
passwd omm
新密码:rootScz123
# 更改权限
chown 755 -R /opt/software
# 更换文件拥有者为omm
chown -R omm /opt/software/openGauss
# 执行下面的命令
cat /etc/sysctl.conf
sysctl -w kernel.sem="250 85000 250 330"
安装
# 切换用户omm
su - omm
# 进入安装目录
cd /opt/software/openGauss/simpleInstall
# 执行下面命令安装 (-w后面为密码,可以自己设置)
sh install.sh -w rootScz123
安装执行完成后,使用ps和gs_ctl查看进程是否正常。
ps ux | grep gaussdb
gs_ctl query -D /opt/software/openGauss/data/single_node
执行ps命令,显示类似如下信息:

执行gs_ctl命令,显示类似如下信息:

启动数据库
# 启动/停止/重启数据库服务
gs_ctl start|stop/restart -D /opt/software/openGauss/data/single_node
连接数据库
# 连接命令,默认为omm用户
gsql -d postgres -p 5432

常用命令
\l --查看所有数据库
\c --进入某个数据库
\dt --查看数据库里面的表
\q --退出Gauss

Navicat或Data Studio远程连接管理数据库
首先,在服务器安全组上开放5432端口

切换omm用户
# 进入数据库节点目录内
cd /opt/software/openGauss/data/single_node

在pg_hba.conf中添加放行ip
vim pg_hba.conf
host all all 本机ip/32 md5
host all all 0.0.0.0/0 md5
本机ip在Windows上命令提示符上用 ipconfig 命令得到


修改postgresql.conf文件
vim postgresql.conf
将listen_address的值改为*

删除此行的注释,并将原本的password_encryption_type = 2更换为password_encryption_type = 0(使用md5加密)。

完成文件修改后,执行下列命令重启数据库服务
gs_ctl stop -D /opt/software/openGauss/data/single_node
gs_ctl start -D /opt/software/openGauss/data/single_node

创建远程连接角色
# omm用户连接数据库
gsql -d postgres -p 5432
# 创建用户并设置密码 (scz为用户名 ""内为密码,可以更改)
create user scz with password "rootScz123";
# 授予新建用户权限
GRANT ALL PRIVILEGES TO scz;
# 创建一个数据库所有者为scz用户
create database db1 owner scz;

连接
Data Studio
下载地址:


navicat(与上面相同填写ip,端口等)

django连接Gauss数据库
注:Django应在3.x版本,4.x版本不支持
1.安装psycopg2和sqlparse库
pip install psycopg2
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '', # 数据库名
'USER': '', # 用户名
'PASSWORD': '', # 密码
'HOST': '', # 服务器ip
'PORT': 5432 # openGauss数据口的端口
}
}
更多推荐
所有评论(0)