openEuler安装openGauss5.0单机数据库

1、操作系统配置

说明:本次测试中,同时安装了两个版本的openEuler操作系统,分别是openEuler23.09和openEuler22.03。操作系统下载地址如下:
https://www.openeuler.org/en/download

[gauss@openGauss:/home/gauss]$cat /etc/os-release
NAME="openEuler"
VERSION="23.09"
ID="openEuler"
VERSION_ID="23.09"
PRETTY_NAME="openEuler 23.09"
ANSI_COLOR="0;31"

1.1、配置/etc/hosts

vi /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.80.223 openGauss

1.2、关闭防火墙

-- 设置 /etc/selinux/config
echo "SELINUX=disabled" > /etc/selinux/config
echo "#SELINUXTYPE=targeted " >> /etc/selinux/config
cat /etc/selinux/config

-- 停止及关闭防火墙
systemctl stop firewalld.service

systemctl disable firewalld.service

1.3、配置/etc/security/limits.conf和/etc/sysctl.conf

cat >> /etc/security/limits.conf  << EOF
*       soft    nproc   65535 
*       hard    nproc   65535
*       soft    nofile  65535
*       hard    nofile  65535
*       soft   stack    65535
*       hard   stack    65535
*       hard memlock unlimited
*       soft memlock unlimited
EOF

cat  /etc/security/limits.conf

echo "vm.swappiness=1" >> /etc/sysctl.conf
echo "fs.aio-max-nr = 1048576" >> /etc/sysctl.conf
echo "fs.file-max = 6815744" >> /etc/sysctl.conf
echo "net.ipv4.tcp_retries1=5" >> /etc/sysctl.conf
echo "net.ipv4.tcp_syn_retries=5" >> /etc/sysctl.conf
echo "net.ipv4.tcp_synack_retries=5" >> /etc/sysctl.conf
echo "net.ipv4.tcp_retries2=12" >> /etc/sysctl.conf
echo "net.ipv4.ip_local_port_range=26000 65535" >> /etc/sysctl.conf
echo "vm.min_free_kbytes=512000" >> /etc/sysctl.conf
echo "net.ipv4.tcp_fin_timeout=60" >> /etc/sysctl.conf
echo "net.ipv4.tcp_sack=1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_timestamps=1" >> /etc/sysctl.conf
echo "vm.extfrag_threshold=500" >> /etc/sysctl.conf
echo "vm.overcommit_ratio=90" >> /etc/sysctl.conf

sysctl -p

1.5、挂载光驱及安装依赖包

-- 挂载光驱
mount /dev/cdrom /mnt

cd /etc/yum.repos.d
mkdir bk
mv *.repo bk/

vi /etc/yum.repos.d/yum.local.repo 

[local]
name=yum local repo
baseurl=file:///mnt
gpgcheck=0
enable=1

-- 安装依赖包
yum install -y libaio-devel libnsl flex bison ncurses-devel glibc-devel patch readline-devel
 
yum install -y net-tools tar bzip2 python3 cmake make gcc zlib gcc-c++ perl  zlib-devel tcl openssl openldap pam

1.6、创建gauss用户及目录

mkdir /gauss

mkdir -p /gauss/{gaussdb,archive,scripts,backup,soft}

groupadd gauss
useradd -g gauss -d /home/gauss -m -s /bin/bash gauss

-- 设置gauss用户密码
echo "gauss" |passwd --stdin gauss

chown -R gauss:gauss /gauss

2、安装openGauss数据库

2.1、下载数据库软件及上传并解压

https://opengauss.org/zh/download/

上传到 /gauss/soft 目录

[gauss@openGauss:/home/gauss]$cd /gauss/soft
[gauss@openGauss:/gauss/soft]$tar zxvf openGauss-5.0.0-CentOS-64bit-all.tar.gz
openGauss-5.0.0-CentOS-64bit-cm.tar.gz
openGauss-5.0.0-CentOS-64bit-om.tar.gz
openGauss-5.0.0-CentOS-64bit.tar.bz2
openGauss-5.0.0-CentOS-64bit-cm.sha256
openGauss-5.0.0-CentOS-64bit-om.sha256
openGauss-5.0.0-CentOS-64bit.sha256
upgrade_sql.tar.gz
upgrade_sql.sha256
[gauss@openGauss:/gauss/soft]$tar jxvf openGauss-5.0.0-CentOS-64bit.tar.bz2 -C /gauss/gaussdb/

2.2、配置环境变量

su - gauss

vi ~/.bash_profile

export LANG=en_US.UTF8
export PS1="[`whoami`@`hostname`:"'$PWD]$'
export GAUSSHOME=/gauss/gaussdb
export LD_LIBRARY_PATH=/gauss/gaussdb/lib
export PATH=/gauss/gaussdb/bin:$PATH:$HOME/.local/bin:$HOME/bin

编辑 .bashrc 注释 ulimit -n 1000000

[gauss@openGauss:/gauss/soft]$cd 
[gauss@openGauss:/gauss/soft]$ls -alk

[gauss@openGauss:/gauss/soft]$vi .bashrc

export GAUSSHOME=/gauss/gaussdb
export PATH=$GAUSSHOME/bin:$PATH
export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH
export GS_CLUSTER_NAME=dbCluster
# ulimit -n 1000000

查看打开文件数

[gauss@openGauss:/gauss/soft]$ulimit -a 

open files                      (-n) 65535

2.3、安装数据库

cd /gauss/gaussdb/simpleInstall/

[gauss@openGauss:/gauss/soft]$cd /gauss/gaussdb/simpleInstall/

[gauss@openGauss:/gauss/gaussdb/simpleInstall]$sh install.sh -w Rootroot@2024
[step 1]: check parameter
[step 2]: check install env and os setting
[step 3]: change_gausshome_owner
[step 4]: set environment variables

[step 6]: init datanode
The files belonging to this database system will be owned by user "gauss".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

fixing permissions on existing directory /gauss/gaussdb/data/single_node ... ok
creating subdirectories ... in ordinary occasionok
creating configuration files ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 1024MB
Begin init undo subsystem meta.
[INIT UNDO] Init undo subsystem meta successfully.
creating template1 database in /gauss/gaussdb/data/single_node/base/1 ... The core dump path is an invalid directory
2024-08-23 10:35:13.319 [unknown] [unknown] localhost 140215162937536 0[0:0#0]  [BACKEND] WARNING:  macAddr is 21/1574709769, sysidentifier is 1400284/705262976, randomNum is 1651078528
ok
initializing pg_authid ... ok
setting password ... ok
initializing dependencies ... ok
loading PL/pgSQL server-side language ... ok
creating system views ... ok
creating performance views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
initialize global configure for bucketmap length ... ok
creating information schema ... ok
loading foreign-data wrapper for distfs access ... ok
loading foreign-data wrapper for log access ... ok
loading hstore extension ... ok
loading foreign-data wrapper for MOT access ... ok
loading security plugin ... ok
update system tables ... ok
creating snapshots catalog ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
freezing database template0 ... ok
freezing database template1 ... ok
freezing database postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run gs_initdb.

Success. You can now start the database server of single node using:

    gaussdb -D /gauss/gaussdb/data/single_node --single_node
or
    gs_ctl start -D /gauss/gaussdb/data/single_node -Z single_node -l logfile

[step 7]: start datanode

 ************************
 
[2024-08-23 10:35:34.687][11552][][gs_ctl]:  done
[2024-08-23 10:35:34.687][11552][][gs_ctl]: server started (/gauss/gaussdb/data/single_node)
import sql file
Would you like to create a demo database (yes/no)? yes -- yes 创建示例数据库 no不创建
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

2.4、启动数据据服务

[gauss@openGauss:/home/gauss]$gs_ctl start -D $GAUSSHOME/data/single_node -Z single_node
[2024-08-23 10:52:30.812][12820][][gs_ctl]: gs_ctl started,datadir is /gauss/gaussdb/data/single_node
[2024-08-23 10:52:30.821][12820][][gs_ctl]:  another server might be running; Please use the restart command

[gauss@openGauss:/home/gauss]$gs_ctl status -D $GAUSSHOME/data/single_node -Z single_node
[2024-08-23 10:52:42.474][12838][][gs_ctl]: gs_ctl status,datadir is /gauss/gaussdb/data/single_node
gs_ctl: server is running (PID: 11555)
/gauss/gaussdb/bin/gaussdb "-D" "/gauss/gaussdb/data/single_node"

2.5、gsql连接到openGauss数据库

[gauss@openGauss:/home/gauss]$gsql -d postgres -p 5432
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:07:56 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=# select version();
                                                                       version

------------------------------------------------------------------------------------------------------------------------
------------------------------
 (openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:07:56 commit 0 last mr   on x86_64-unknown-linux-gnu, compil
ed by g++ (GCC) 7.3.0, 64-bit
(1 row)


openGauss-# \q

[gauss@openGauss:/home/gauss]$gsql -h 127.0.0.1 -p 5432 -U gauss -d postgres
Password for user gauss:
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:07:56 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.


openGauss=# \l
                              List of databases
   Name    | Owner | Encoding |   Collate   |    Ctype    | Access privileges
-----------+-------+----------+-------------+-------------+-------------------
 finance   | gauss | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 postgres  | gauss | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 school    | gauss | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | gauss | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/gauss         +
           |       |          |             |             | gauss=CTc/gauss
 template1 | gauss | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/gauss         +
           |       |          |             |             | gauss=CTc/gauss
(5 rows)

openGauss=# \q

2.6、创建数据库superdb授权给用户super

create user super with password 'Rootgauss@2024';

CREATE DATABASE superdb OWNER super;

GRANT ALL PRIVILEGES ON all tables in schema public TO super;

GRANT ALL PRIVILEGES ON DATABASE superdb TO super;

GRANT ALL PRIVILEGES TO super;

2.7、安装遇到的lib*依赖问题

我解决的方法是从Centos7.9中download下载后,上传到openEuler22.03以及opEuler23.09的操作系统 /usr/lin64/ 并创建软链接。

ln -sf /usr/lib64/libreadline.so.6.2 /usr/lib64/libreadline.so.6
ln -sf /usr/lib64/libncurses.so.5.9 /usr/lib64/libncurses.so.5
ln -sf /usr/lib64/libtinfo.so.5.9 /usr/lib64/libtinfo.so.5
ln -sf /usr/lib64/libcrypto.so.1.0.2k /usr/lib64/libcrypto.so.10
ln -sf /usr/lib64/libnsl-2.17.so /usr/lib64/libnsl.so.1
ln -sf /usr/lib64/libssl.so.1.0.2k /usr/lib64/libssl.so.10

官方文档中显示的运行环境,自己安装openEuler 22.03 LTS SP4,还是需要libreadline.so.6,因此把openEuler 23.09上传的包直接同步到/usr/lib64/并创建软链接

支持的硬件平台
openGauss支持运行在ARM服务器和通用的x86服务器上:

支持ARM服务器和基于x86_64的通用PC服务器。
支持本地存储(SATA、SAS、SSD)。
支持千兆、万兆Ethernet网络。
支持的操作系统
ARM:

openEuler 20.03 LTS(推荐采用此操作系统)
openEuler 22.03 LTS
统信V20
麒麟V10
Asianux 7.5
X86:

openEuler 20.03 LTS
openEuler 22.03 LTS
CentOS 7.6
Asianux 7.6

3. openGauss的gsql命令行数据库连接工具

openGauss的gsql是一个功能强大的命令行数据库连接工具,它允许用户连接到openGauss数据库服务器,执行SQL语句,以及利用元命令进行数据库管理和维护。以下是对gsql的详细介绍:

3.1、gsql的基本功能

  1. 连接数据库:gsql提供了灵活的连接方式,支持通过命令行参数指定数据库名称、用户名、主机名和端口号等信息,以便连接到openGauss数据库服务器。
  2. 执行SQL语句:gsql支持交互式地键入并执行SQL语句,也支持执行文件中的SQL语句。这为用户提供了灵活的数据操作方式。
  3. 执行元命令:gsql还提供了许多元命令,这些命令用于查询数据库对象的信息、查询缓存区信息、格式化SQL输出结果、连接到新的数据库等。这些元命令大大增强了gsql的功能性和便利性。

3.2、gsql的高级特性

  1. 变量支持:gsql提供了类似于Linux shell命令的变量特性,用户可以使用\set命令设置变量,并在SQL语句中引用这些变量。这有助于简化复杂的SQL操作。
  2. 命令自动补齐:根据openGauss的语法规则,gsql支持使用Tab键进行命令的自动补齐。这大大提高了用户输入命令的效率和准确性。
  3. 操作历史记录:gsql支持客户端操作历史记录功能,用户可以通过\set命令设置记录历史的条数,并可以通过上下翻键查看历史命令。

3.3、gsql的常用元命令

  1. \connect 或 \c:连接到指定的数据库。
  2. \copy:用于在openGauss数据库和文件之间导入或导出数据。这是数据迁移和备份的重要工具。
  3. \d:列出表、视图、索引等数据库对象的定义。
  4. \di:列出索引的定义。
  5. \dt:列出所有表。
  6. \du:列出所有数据库用户。
  7. \l:列出所有数据库。
  8. \q:退出gsql。

3.4、使用gsql导入数据的示例

假设有一个名为example_table的表,并希望从本地文件data.csv中导入数据到该表。可以使用以下gsql命令:

gsql -d your_database -U your_username -p your_port -c "\copy example_table FROM '/path/to/data.csv' WITH (delimiter ',', csv header)"

在这个命令中,-d指定数据库名称,-U指定数据库用户名,-p指定端口号,-c后面跟要执行的SQL命令。\copy命令用于从文件导入数据到表,WITH子句中的delimiter ','指定了字段分隔符为逗号,csv header表示数据文件的第一行是标题行(列名)。

3.5、总结

gsql是openGauss提供的一个强大而灵活的命令行数据库连接工具,它支持执行SQL语句、管理数据库对象以及导入导出数据等多种功能。通过学习和掌握gsql的使用,用户可以更加高效地管理和操作openGauss数据库。

4、配置客户端认证文件

在 openGauss(类似于 PostgreSQL)中,要让客户端从任何 IP 地址都能访问数据库,你需要修改 pg_hba.conf 文件,该文件控制着客户端认证。然而,出于安全考虑,通常不建议直接允许从任何 IP 地址访问数据库,因为这可能会使数据库面临安全风险。但如果你确实需要这样做(例如在测试环境中),你可以按照以下步骤操作:

  1. 找到 pg_hba.conf 文件:这个文件通常位于 openGauss 数据目录的 postgresql.conf 文件的同一目录下。数据目录的位置取决于你的安装方式和配置。

  2. 编辑 pg_hba.conf 文件:使用文本编辑器打开 pg_hba.conf 文件。在文件的末尾或适当的位置,添加一行规则来允许从任何 IP 地址访问。例如,如果你想要允许所有用户从任何 IP 地址通过密码认证方式访问所有数据库,你可以添加如下行:
    [gauss@openGauss:/home/gauss]$vi /gauss/gaussdb/data/single_node/pg_hba.conf

    # TYPE  DATABASE        USER            ADDRESS                 METHOD
    host    all             all             0.0.0.0/0              sha256
    

    这里,host 表示这是一个针对 TCP/IP 连接的规则;all 表示这条规则适用于所有数据库;第二个 all 表示这条规则适用于所有用户;0.0.0.0/0 表示这条规则适用于所有 IP 地址;md5 表示使用 MD5 加密的密码进行认证。
    [gauss@openGauss:/home/gauss]$vi /gauss/gaussdb/data/single_node/postgresql.conf

    # 设置如下参数
    listen_addresses = '*'
    port = 5432 
    
  3. 重启 openGauss 服务:修改 pg_hba.conf 文件后,你需要重启 openGauss 服务以使更改生效。重启服务的方法取决于你的安装方式和操作系统。例如,在某些 Linux 发行版上,你可能需要使用 systemctl 命令(如果 openGauss 被配置为 systemd 服务)或直接运行 openGauss 的启动脚本。

    [gauss@openGauss:/home/gauss]$gs_ctl stop -D /gauss/gaussdb/data/single_node -Z single_node
    [gauss@openGauss:/home/gauss]$gs_ctl start -D /gauss/gaussdb/data/single_node -Z single_node
    -- OR 
    [gauss@openGauss:/home/gauss]$gs_ctl restart -D /gauss/gaussdb/data/single_node -Z single_node
    
  4. 验证更改:尝试从远程客户端连接到 openGauss 数据库,以验证你的更改是否已生效。

注意:虽然允许从任何 IP 地址访问数据库可能很方便,但这也会大大增加数据库被未授权访问的风险。因此,在生产环境中,你应该始终限制访问数据库的 IP 地址范围,并使用强密码和其他安全措施来保护你的数据库。

此外,如果你的 openGauss 实例位于防火墙后面,你还需要确保防火墙规则允许来自远程 IP 地址的入站连接(通常是 TCP 端口 5432,除非你在 postgresql.conf 文件中更改了端口)。

5、创建测试表

[gauss@dbtest:/home/gauss]$gsql -h 192.168.80.223 -p 5432 -U super -d superdb
Password for user super:**** -- 此时输入之前设置的密码
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:07:56 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

superdb=>create table t_opengauss (id bigint primary key,infoname varchar(50));
CREATE TABLE
superdb=> insert into t_opengauss values(1,'opengauss5.0');
INSERT 0 1
superdb=> insert into t_opengauss values(2,'openEuler23.09');
INSERT 0 1
superdb=> insert into t_opengauss values(3,'openEuler22.03');
INSERT 0 1
superdb=> select * from t_opengauss;
 id |    infoname
----+----------------
  1 | opengauss5.0
  2 | openEuler23.09
  3 | openEuler22.03
(3 rows)

superdb=> comment on table t_opengauss is 'test';
COMMENT
superdb=> comment on column t_opengauss.id is 'primary key';
COMMENT
superdb=> comment on column t_opengauss.infoname is 'decriptions';
COMMENT
superdb=> \dt t_opengauss;
                            List of relations
 Schema |    Name     | Type  | Owner |             Storage
--------+-------------+-------+-------+----------------------------------
 public | t_opengauss | table | super | {orientation=row,compression=no}
(1 row)

superdb=> \dt+ t_opengauss
                                         List of relations
 Schema |    Name     | Type  | Owner |    Size    |             Storage              | Description
--------+-------------+-------+-------+------------+----------------------------------+-------------
 public | t_opengauss | table | super | 8192 bytes | {orientation=row,compression=no} | test
(1 row)

superdb=> \d t_opengauss
          Table "public.t_opengauss"
  Column  |         Type          | Modifiers
----------+-----------------------+-----------
 id       | bigint                | not null
 infoname | character varying(32) |
Indexes:
    "t_opengauss_pkey" PRIMARY KEY, btree (id) TABLESPACE pg_default

superdb=> \d+ t_opengauss
                              Table "public.t_opengauss"
  Column  |         Type          | Modifiers | Storage  | Stats target | Description
----------+-----------------------+-----------+----------+--------------+-------------
 id       | bigint                | not null  | plain    |              | primary key
 infoname | character varying(32) |           | extended |              | decriptions
Indexes:
    "t_opengauss_pkey" PRIMARY KEY, btree (id) TABLESPACE pg_default
Has OIDs: no
Options: orientation=row, compression=no

dbeaver数据库工具配置连接openGauss5.0请参考我的这篇文章
https://blog.csdn.net/zxrhhm/article/details/141465182?spm=1001.2014.3001.5501

  • 13
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装opengauss5.0的过程可以分为以下几个步骤: 1. 首先,需要重启docker服务以确保修改生效。可以使用以下命令完成重启: ``` systemctl daemon-reload systemctl restart docker ``` 2. 如果你的系统是基于arm平台的,你可以使用以下命令从华为云镜像仓库拉取opengauss5.0的镜像,并为其打上tag: ``` docker pull swr.cn-south-1.myhuaweicloud.com/opengauss/arm/opengauss:5.0.0 docker tag swr.cn-south-1.myhuaweicloud.com/opengauss/arm/opengauss:5.0.0 opengauss:5.0.0 ``` 3. 接着,你可以使用docker-compose.yml文件来进行微服务项目容器编排,并使用Dockerfile文件模板、相关配置文件和shell脚本来配置opengauss5.0容器。确保这些文件的正确性和完整性,并根据你的具体需求进行相应的修改和配置。 综上所述,你可以通过重启docker服务、拉取opengauss5.0镜像并打上tag,以及使用相应的容器编排和配置文件来安装opengauss5.0。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [openGauss5.0之学习环境 Docker安装](https://blog.csdn.net/wangshuai6707/article/details/131148834)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [微服务项目容器编排docker-compose.yml、Dockerfile文件模板、相关配置文件、shell脚本](https://download.csdn.net/download/qq_45629145/88248761)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值