CentOS上安装openGauss

一、准备软硬件环境

1.新建用户组、用户

groupadd dbgroup

useradd -g dbgroup smis

passwd smis

新密码:123456

2.创建文件夹并授权

mkdir -p /opt/module/openGauss

chown 755 -R /opt/module

chown -R smis /opt/module/openGauss

3.下载安装包

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

下载【openGauss 极简版】

把下载文件拷贝到/opt/module/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

HISTSIZE=0
source /etc/profile

7.将交换内存关闭

swapoff -a

8.重启操作系统

reboot

9.切换smis用户

su smis

10.解压安装包

cd /opt/module/openGauss
tar -jxf openGauss-xxx-64bit.tar.bz2
ls -lb

image-20230317173256252

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

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

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

cat /etc/sysctl.conf

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

二、安装openGauss

1. 切换到smis用户

su smis

2.执行脚本安装

cd /opt/module/openGauss/simpleInstall

sh install.sh -w "Og123456" &&source ~/.bashrc

# 注意:密码长度至少为8,且至少有三种类型
# [step 1]: check parameter
# password must be at least 8 character and at least three kinds
# 提示:Would you like to create a demo database (yes/no)?
# 输入【yes】
参数说明
-w 初始化数据库密码(gs_initdb指定),安全需要必须设置。
-p 指定的openGauss端口号,如不指定,默认为5432。
-h|–help 打印使用说明。

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

3.如果安装报错:

gs_initdb: error while loading shared libraries: libreadline.so.7: cannot open shared object file: No such file or directory。

解决方法:

扫描二维码关注公众号,回复: 16186239 查看本文章
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/module/openGauss/data/single_node:为数据库目录安装路径
/opt/module/openGauss:为解压包路径
data/single_node:为新创建的数据库节点目录。

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

ps ux | grep gaussdb

提示如下,安装成功

smis       2363  1.7  5.0 6079220 815204 ?      Ssl  02:48   0:01 /opt/module/openGauss/bin/gaussdb -D /opt/module/openGauss/data/single_node
smis       2607  0.0  0.0 110372   900 pts/0    S+   02:50   0:00 grep --color=auto gaussdb

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

解决方式:配置环境变量即可

export PATH=/opt/module/openGauss/bin:$PATH

如果缺失lib则配置LD_LIBRARY_PATH

6.启动 / 停止 / 重启

# 启动
gs_ctl start -D /opt/module/openGauss/data/single_node -Z single_node

# 停止
gs_ctl stop -D /opt/module/openGauss/data/single_node -Z single_node

#重启
gs_ctl restart -D /opt/module/openGauss/data/single_node -Z single_node

#查看数据库主节点的端口号
cat /opt/module/openGauss/data/single_node/postgresql.conf | grep port

三、gsql 连接与使用方法

#查询所有的数据库,需要先切换smis用户,su smis
[smis@localhost /]$ gsql -d postgres -p 5432 -l
# 连接数据库,链接数据库
[smis@localhost /]$ gsql -d postgres -p 5432
# 1.创建用户语法:create user 用户名 with password "密码";
openGauss=# CREATE USER gaussdb WITH CREATEDB password "Og123456";

# 创建有“创建数据库”权限的用户,则需要加CREATEDB关键字。
# 将sysadmin权限授权给gaussdb ,授权成功后,用户gaussdb 会拥有sysadmin的所有权限
openGauss=# GRANT ALL PRIVILEGES TO gaussdb ;

# 2.查看数据库用户列表
openGauss=# select * from pg_user;

# 3.查看所有角色
openGauss=# select * from PG_ROLES;

# 4.删除数据库用户
openGauss=# drop user gaussdb cascade;

# 5.创建数据库,并指定所有者 语法:create database 数据库名 owner 用户名;
openGauss=# create database db_smis owner gaussdb;

# 6.删除数据库,注意加分号 语法:drop database 数据库名;
openGauss=# drop database db_smis;

# 7.连接到创建的数据库,
#语法:\c[onnect] [DBNAME|- USER|- HOST|- PORT|-]
openGauss=# \c db_smis;

# 8.创建表
db_smis=# CREATE TABLE dxc(id INTEGER,name CHARACTER VARYING(32)) ;
db_smis=# \d; # list tables, views, and sequences


# 9.查看对象
openGauss=# \l #查看数据库
openGauss=# \c school #查看数据库
openGauss=# \dt #查看数据库所有表名
openGauss=# \d student #查看表结构
openGauss=# \d+ student #查看表结构

# 10.修改密码 语法: ALTER USER 用户名 IDENTIFIED BY '新密码' REPLACE '旧密码';
postgres=# ALTER USER jim IDENTIFIED BY 'Abcd@123' REPLACE 'Bigdata@123';

# 9.退出
openGauss=# \q

四、使用Navicat连接openGauss

1.文件 pg_hba.conf 修改

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

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

host all all 0.0.0.0/0 md5

2.文件postgresql.conf 修改

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

# password_encryption_type值设为0,即为md5。
# 输入【/】搜索 listen_addresses 变量,将前面#去掉,值修改为*

3.重启openGauss

猜你喜欢

转载自blog.csdn.net/twi_twi/article/details/129627553