安装openGauss

2023-05-16

一、准备软硬件环境

1.新建用户组、用户

groupadd dbgroup

useradd -g dbgroup smis

passwd smis

新密码:smis@1qazxc

2.创建文件夹并授权

mkdir -p /opt/software/openGauss

chown 755 -R /opt/software

chown -R smis /opt/software/openGauss

3.下载安装包

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

下载【openGauss_3.1.0 极简版】

把下载文件拷贝到/opt/software/openGauss目录

4.关闭防火墙

systemctl disable firewalld.service

systemctl stop firewalld.service

5.关闭 selinux

将 SELINUX=enforcing 改为 SELINUX=disabled

vim /etc/selinux/config

SELINUX=disabled

6.关闭HISTORY记录

vim /etc/profile

HISTSIZE=0

source /etc/profile

7.将交换内存关闭

swapoff -a

8.重启操作系统

reboot

9: 切换smis用户

su smis

10.解压安装包

cd /opt/software/openGauss

tar -jxf openGauss-xxx-64bit.tar.bz2

ls -lb

11.使用有root权限的用户执行命令

cat /etc/sysctl.conf

sysctl -w kernel.sem="250 85000 250 330"

# 不执行,可能出现错误提示

# the maximum number of SEMMNI is not correct, the current SEMMNI is xxx. Please check it.

二、安装openGauss

  1. 切换到smis用户

su smis

  1. 执行脚本安装

cd /opt/software/openGauss/simpleInstall

sh install.sh -w "ynsmis@123" &&source ~/.bashrc

# 提示:Would you like to create a demo database (yes/no)?

# 输入【yes】

#参数说明

-w:初始化数据库密码(gs_initdb指定),安全需要必须设置。

-p:指定的openGauss端口号,如不指定,默认为5432。

-h|–help:打印使用说明。

安装后,该数据库部署结点的名称为sgnode(gs_initdb指定)。

如果安装报错:gs_initdb: error while loading shared libraries: libreadline.so.7: cannot open shared object file: No such file or directory。

解决方法:

cd /usr/lib64

ln -s libreadline.so.8 libreadline.so.7

如果出现:

Load demoDB [school,finance] success.

[complete successfully]: You can start or stop the database server using:

gs_ctl start|stop|restart -D $GAUSSHOME/data/single_node -Z single_node

那么安装成功了。

# 说明

openGauss端口号默认为5432

默认生成名称为postgres的数据库

数据库目录安装路径/opt/software/openGauss/data/single_node,其中/opt/software/openGauss为解压包路径,data/single_node为新创建的数据库节点目录。

# 执行ps命令,查看进程是否正常

ps ux | grep gaussdb

# 提示如下,安装成功

omm 23246 1.3 17.5 2841700 678364 ? Ssl 10:59 0:07 /opt/software/openGauss/bin/gaussdb -D /opt/software/openGauss/data/single_node

omm 79232 0.0 0.0 112724 984 pts/1 S+ 11:08 0:00 grep --color=auto gaussdb

# 执行gs_ctl命令,查看进程是否正常,如果没有找到 gs_ctl

# 解决方式:配置环境变量即可 export PATH=/opt/software/openGauss/bin:$PATH,如果缺失lib则配置LD_LIBRARY_PATH

#启动

gs_ctl start -D /opt/software/openGauss/data/single_node -Z single_node

#停止

gs_ctl stop -D /opt/software/openGauss/data/single_node -Z single_node

#重启

gs_ctl restart -D /opt/software/openGauss/data/single_node -Z single_node

#查看数据库主节点的端口号

cat /opt/software/openGauss/data/single_node/postgresql.conf | grep port

三、gsql 连接与使用方法

#查询所有的数据库,需要先切换smis用户,su smis

[smis@localhost /]$ gsql -d postgres -p 5432 -l【success,默认smis用户】

1.连接数据库,链接数据库

[smis@localhost /]$ gsql -d postgres -p 5432

2.创建用户

# 语法:create user 用户名 with password "密码";

openGauss=# CREATE USER gaussdb WITH CREATEDB password "gaussdb@1qazx";

#创建有“创建数据库”权限的用户,则需要加CREATEDB关键字。

# 将sysadmin权限授权给gaussdb ,授权成功后,用户gaussdb 会拥有sysadmin的所有权限

openGauss=# GRANT ALL PRIVILEGES TO gaussdb ;

3.查看数据库用户列表

openGauss=# select * from pg_user;

# 查看所有角色

openGauss=# select * from PG_ROLES;

# 删除数据库用户

openGauss=# drop user gaussdb cascade;

4.创建数据库,并指定所有者

语法:create database 数据库名 owner 用户名;

openGauss=# create database db_smis owner gaussdb;

5.删除数据库,注意加分号

语法:drop database 数据库名;

openGauss=# drop database db_smis;

6.创建表

连接到创建的数据库,

#语法:\c[onnect] [DBNAME|- USER|- HOST|- PORT|-]

openGauss=# \c db_smis;

创建表

db_smis=# CREATE TABLE dxc(id INTEGER,name CHARACTER VARYING(32)) ;

db_smis=# \d; # list tables, views, and sequences

7.查看对象

openGauss=# \l #查看数据库

openGauss=# \c school #查看数据库

openGauss=# \dt #查看数据库所有表名

openGauss=# \d student #查看表结构

openGauss=# \d+ student #查看表结构

8.修改密码

语法: ALTER USER 用户名 IDENTIFIED BY '新密码' REPLACE '旧密码';

postgres=# ALTER USER jim IDENTIFIED BY 'Abcd@123' REPLACE 'Bigdata@123';

alter user <用户名> identified by '密码';

9.退出

openGauss=# \q

四、使用Navicat连接openGauss

# 配置外网访问

1.文件 pg_hba.conf 修改

vim /opt/software/openGauss/data/single_node/pg_hba.conf

# 允许所有网段连接 在IPv4 local connections下添加

host all all 0.0.0.0/0 md5

2.文件postgresql.conf 修改

vim /opt/software/openGauss/data/single_node/postgresql.conf

password_encryption_type值设为0,即为md5。

输入【/】搜索 listen_addresses 变量,将前面#去掉,值修改为*

3.重启openGauss

gs_ctl restart -D /opt/software/openGauss/data/single_node -Z single_node

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

安装openGauss 的相关文章

随机推荐