openEuler安装openGauss5.0单机数据库

打印 上一主题 下一主题

主题 1033|帖子 1033|积分 3099

1、操作系统设置

阐明:本次测试中,同时安装了两个版本的openEuler操作系统,分别是openEuler23.09和openEuler22.03。操作系统下载地点如下:
https://www.openeuler.org/en/download
  1. [gauss@openGauss:/home/gauss]$cat /etc/os-release
  2. NAME="openEuler"
  3. VERSION="23.09"
  4. ID="openEuler"
  5. VERSION_ID="23.09"
  6. PRETTY_NAME="openEuler 23.09"
  7. ANSI_COLOR="0;31"
复制代码
1.1、设置/etc/hosts

vi /etc/hosts
  1. 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
  2. ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
  3. 192.168.80.223 openGauss
复制代码
1.2、关闭防火墙

  1. -- 设置 /etc/selinux/config
  2. echo "SELINUX=disabled" > /etc/selinux/config
  3. echo "#SELINUXTYPE=targeted " >> /etc/selinux/config
  4. cat /etc/selinux/config
  5. -- 停止及关闭防火墙
  6. systemctl stop firewalld.service
  7. systemctl disable firewalld.service
复制代码
1.3、设置/etc/security/limits.conf和/etc/sysctl.conf

  1. cat >> /etc/security/limits.conf  << EOF
  2. *       soft    nproc   65535
  3. *       hard    nproc   65535
  4. *       soft    nofile  65535
  5. *       hard    nofile  65535
  6. *       soft   stack    65535
  7. *       hard   stack    65535
  8. *       hard memlock unlimited
  9. *       soft memlock unlimited
  10. EOF
  11. cat  /etc/security/limits.conf
  12. echo "vm.swappiness=1" >> /etc/sysctl.conf
  13. echo "fs.aio-max-nr = 1048576" >> /etc/sysctl.conf
  14. echo "fs.file-max = 6815744" >> /etc/sysctl.conf
  15. echo "net.ipv4.tcp_retries1=5" >> /etc/sysctl.conf
  16. echo "net.ipv4.tcp_syn_retries=5" >> /etc/sysctl.conf
  17. echo "net.ipv4.tcp_synack_retries=5" >> /etc/sysctl.conf
  18. echo "net.ipv4.tcp_retries2=12" >> /etc/sysctl.conf
  19. echo "net.ipv4.ip_local_port_range=26000 65535" >> /etc/sysctl.conf
  20. echo "vm.min_free_kbytes=512000" >> /etc/sysctl.conf
  21. echo "net.ipv4.tcp_fin_timeout=60" >> /etc/sysctl.conf
  22. echo "net.ipv4.tcp_sack=1" >> /etc/sysctl.conf
  23. echo "net.ipv4.tcp_timestamps=1" >> /etc/sysctl.conf
  24. echo "vm.extfrag_threshold=500" >> /etc/sysctl.conf
  25. echo "vm.overcommit_ratio=90" >> /etc/sysctl.conf
  26. sysctl -p
复制代码
1.5、挂载光驱及安装依赖包

  1. -- 挂载光驱
  2. mount /dev/cdrom /mnt
  3. cd /etc/yum.repos.d
  4. mkdir bk
  5. mv *.repo bk/
  6. vi /etc/yum.repos.d/yum.local.repo
  7. [local]
  8. name=yum local repo
  9. baseurl=file:///mnt
  10. gpgcheck=0
  11. enable=1
  12. -- 安装依赖包
  13. yum install -y libaio-devel libnsl flex bison ncurses-devel glibc-devel patch readline-devel
  14. yum install -y net-tools tar bzip2 python3 cmake make gcc zlib gcc-c++ perl  zlib-devel tcl openssl openldap pam
复制代码
1.6、创建gauss用户及目录

  1. mkdir /gauss
  2. mkdir -p /gauss/{gaussdb,archive,scripts,backup,soft}
  3. groupadd gauss
  4. useradd -g gauss -d /home/gauss -m -s /bin/bash gauss
  5. -- 设置gauss用户密码
  6. echo "gauss" |passwd --stdin gauss
  7. chown -R gauss:gauss /gauss
复制代码
2、安装openGauss数据库

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

https://opengauss.org/zh/download/
上传到 /gauss/soft 目录
  1. [gauss@openGauss:/home/gauss]$cd /gauss/soft
  2. [gauss@openGauss:/gauss/soft]$tar zxvf openGauss-5.0.0-CentOS-64bit-all.tar.gz
  3. openGauss-5.0.0-CentOS-64bit-cm.tar.gz
  4. openGauss-5.0.0-CentOS-64bit-om.tar.gz
  5. openGauss-5.0.0-CentOS-64bit.tar.bz2
  6. openGauss-5.0.0-CentOS-64bit-cm.sha256
  7. openGauss-5.0.0-CentOS-64bit-om.sha256
  8. openGauss-5.0.0-CentOS-64bit.sha256
  9. upgrade_sql.tar.gz
  10. upgrade_sql.sha256
  11. [gauss@openGauss:/gauss/soft]$tar jxvf openGauss-5.0.0-CentOS-64bit.tar.bz2 -C /gauss/gaussdb/
复制代码
2.2、设置情况变量

su - gauss
vi ~/.bash_profile
  1. export LANG=en_US.UTF8
  2. export PS1="[`whoami`@`hostname`:"'$PWD]$'
  3. export GAUSSHOME=/gauss/gaussdb
  4. export LD_LIBRARY_PATH=/gauss/gaussdb/lib
  5. export PATH=/gauss/gaussdb/bin:$PATH:$HOME/.local/bin:$HOME/bin
复制代码
编辑 .bashrc 注释 ulimit -n 1000000
  1. [gauss@openGauss:/gauss/soft]$cd
  2. [gauss@openGauss:/gauss/soft]$ls -alk
  3. [gauss@openGauss:/gauss/soft]$vi .bashrc
  4. export GAUSSHOME=/gauss/gaussdb
  5. export PATH=$GAUSSHOME/bin:$PATH
  6. export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH
  7. export GS_CLUSTER_NAME=dbCluster
  8. # ulimit -n 1000000
复制代码
查察打开文件数
  1. [gauss@openGauss:/gauss/soft]$ulimit -a
  2. open files                      (-n) 65535
复制代码
2.3、安装数据库

cd /gauss/gaussdb/simpleInstall/
  1. [gauss@openGauss:/gauss/soft]$cd /gauss/gaussdb/simpleInstall/
  2. [gauss@openGauss:/gauss/gaussdb/simpleInstall]$sh install.sh -w Rootroot@2024
  3. [step 1]: check parameter
  4. [step 2]: check install env and os setting
  5. [step 3]: change_gausshome_owner
  6. [step 4]: set environment variables
  7. [step 6]: init datanode
  8. The files belonging to this database system will be owned by user "gauss".
  9. This user must also own the server process.
  10. The database cluster will be initialized with locale "en_US.UTF-8".
  11. The default database encoding has accordingly been set to "UTF8".
  12. The default text search configuration will be set to "english".
  13. fixing permissions on existing directory /gauss/gaussdb/data/single_node ... ok
  14. creating subdirectories ... in ordinary occasionok
  15. creating configuration files ... ok
  16. selecting default max_connections ... 100
  17. selecting default shared_buffers ... 1024MB
  18. Begin init undo subsystem meta.
  19. [INIT UNDO] Init undo subsystem meta successfully.
  20. creating template1 database in /gauss/gaussdb/data/single_node/base/1 ... The core dump path is an invalid directory
  21. 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
  22. ok
  23. initializing pg_authid ... ok
  24. setting password ... ok
  25. initializing dependencies ... ok
  26. loading PL/pgSQL server-side language ... ok
  27. creating system views ... ok
  28. creating performance views ... ok
  29. loading system objects' descriptions ... ok
  30. creating collations ... ok
  31. creating conversions ... ok
  32. creating dictionaries ... ok
  33. setting privileges on built-in objects ... ok
  34. initialize global configure for bucketmap length ... ok
  35. creating information schema ... ok
  36. loading foreign-data wrapper for distfs access ... ok
  37. loading foreign-data wrapper for log access ... ok
  38. loading hstore extension ... ok
  39. loading foreign-data wrapper for MOT access ... ok
  40. loading security plugin ... ok
  41. update system tables ... ok
  42. creating snapshots catalog ... ok
  43. vacuuming database template1 ... ok
  44. copying template1 to template0 ... ok
  45. copying template1 to postgres ... ok
  46. freezing database template0 ... ok
  47. freezing database template1 ... ok
  48. freezing database postgres ... ok
  49. WARNING: enabling "trust" authentication for local connections
  50. You can change this by editing pg_hba.conf or using the option -A, or
  51. --auth-local and --auth-host, the next time you run gs_initdb.
  52. Success. You can now start the database server of single node using:
  53.     gaussdb -D /gauss/gaussdb/data/single_node --single_node
  54. or
  55.     gs_ctl start -D /gauss/gaussdb/data/single_node -Z single_node -l logfile
  56. [step 7]: start datanode
  57. ************************
  58. [2024-08-23 10:35:34.687][11552][][gs_ctl]:  done
  59. [2024-08-23 10:35:34.687][11552][][gs_ctl]: server started (/gauss/gaussdb/data/single_node)
  60. import sql file
  61. Would you like to create a demo database (yes/no)? yes -- yes 创建示例数据库 no不创建
  62. Load demoDB [school,finance] success.
  63. [complete successfully]: You can start or stop the database server using:
  64.     gs_ctl start|stop|restart -D $GAUSSHOME/data/single_node -Z single_node
复制代码
2.4、启动数据据服务

  1. [gauss@openGauss:/home/gauss]$gs_ctl start -D $GAUSSHOME/data/single_node -Z single_node
  2. [2024-08-23 10:52:30.812][12820][][gs_ctl]: gs_ctl started,datadir is /gauss/gaussdb/data/single_node
  3. [2024-08-23 10:52:30.821][12820][][gs_ctl]:  another server might be running; Please use the restart command
  4. [gauss@openGauss:/home/gauss]$gs_ctl status -D $GAUSSHOME/data/single_node -Z single_node
  5. [2024-08-23 10:52:42.474][12838][][gs_ctl]: gs_ctl status,datadir is /gauss/gaussdb/data/single_node
  6. gs_ctl: server is running (PID: 11555)
  7. /gauss/gaussdb/bin/gaussdb "-D" "/gauss/gaussdb/data/single_node"
复制代码
2.5、gsql连接到openGauss数据库

  1. [gauss@openGauss:/home/gauss]$gsql -d postgres -p 5432
  2. gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:07:56 commit 0 last mr  )
  3. Non-SSL connection (SSL connection is recommended when requiring high-security)
  4. Type "help" for help.
  5. openGauss=# select version();
  6.                                                                        version
  7. ------------------------------------------------------------------------------------------------------------------------
  8. ------------------------------
  9. (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
  10. ed by g++ (GCC) 7.3.0, 64-bit
  11. (1 row)
  12. openGauss-# \q
  13. [gauss@openGauss:/home/gauss]$gsql -h 127.0.0.1 -p 5432 -U gauss -d postgres
  14. Password for user gauss:
  15. gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:07:56 commit 0 last mr  )
  16. Non-SSL connection (SSL connection is recommended when requiring high-security)
  17. Type "help" for help.
  18. openGauss=# \l
  19.                               List of databases
  20.    Name    | Owner | Encoding |   Collate   |    Ctype    | Access privileges
  21. -----------+-------+----------+-------------+-------------+-------------------
  22. finance   | gauss | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
  23. postgres  | gauss | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
  24. school    | gauss | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
  25. template0 | gauss | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/gauss         +
  26.            |       |          |             |             | gauss=CTc/gauss
  27. template1 | gauss | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/gauss         +
  28.            |       |          |             |             | gauss=CTc/gauss
  29. (5 rows)
  30. openGauss=# \q
复制代码
2.6、创建数据库superdb授权给用户super

  1. create user super with password 'Rootgauss@2024';
  2. CREATE DATABASE superdb OWNER super;
  3. GRANT ALL PRIVILEGES ON all tables in schema public TO super;
  4. GRANT ALL PRIVILEGES ON DATABASE superdb TO super;
  5. GRANT ALL PRIVILEGES TO super;
复制代码
2.7、安装碰到的lib*依赖问题

我解决的方法是从Centos7.9中download下载后,上传到openEuler22.03以及opEuler23.09的操作系统 /usr/lin64/ 并创建软链接。
  1. ln -sf /usr/lib64/libreadline.so.6.2 /usr/lib64/libreadline.so.6
  2. ln -sf /usr/lib64/libncurses.so.5.9 /usr/lib64/libncurses.so.5
  3. ln -sf /usr/lib64/libtinfo.so.5.9 /usr/lib64/libtinfo.so.5
  4. ln -sf /usr/lib64/libcrypto.so.1.0.2k /usr/lib64/libcrypto.so.10
  5. ln -sf /usr/lib64/libnsl-2.17.so /usr/lib64/libnsl.so.1
  6. 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/并创建软链接
  1. 支持的硬件平台
  2. openGauss支持运行在ARM服务器和通用的x86服务器上:
  3. 支持ARM服务器和基于x86_64的通用PC服务器。
  4. 支持本地存储(SATA、SAS、SSD)。
  5. 支持千兆、万兆Ethernet网络。
  6. 支持的操作系统
  7. ARM:
  8. openEuler 20.03 LTS(推荐采用此操作系统)
  9. openEuler 22.03 LTS
  10. 统信V20
  11. 麒麟V10
  12. Asianux 7.5
  13. X86:
  14. openEuler 20.03 LTS
  15. openEuler 22.03 LTS
  16. CentOS 7.6
  17. Asianux 7.6
复制代码
3. openGauss的gsql命令行数据库连接工具

openGauss的gsql是一个功能强盛的命令行数据库连接工具,它允许用户连接到openGauss数据库服务器,实行SQL语句,以及利用元命令举行数据库管理和维护。以下是对gsql的详细先容:
3.1、gsql的根本功能


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


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


  • \connect 或 \c:连接到指定的数据库。
  • \copy:用于在openGauss数据库和文件之间导入或导出数据。这是数据迁徙和备份的紧张工具。
  • \d:列出表、视图、索引等数据库对象的界说。
  • \di:列出索引的界说。
  • \dt:列出所有表。
  • \du:列出所有数据库用户。
  • \l:列出所有数据库。
  • \q:退出gsql。
3.4、使用gsql导入数据的示例

假设有一个名为example_table的表,并盼望从本地文件data.csv中导入数据到该表。可以使用以下gsql命令:
  1. 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 地点访问数据库,由于这可能会使数据库面临安全风险。但如果你确实需要这样做(例如在测试情况中),你可以按照以下步骤操作:

  • 找到 pg_hba.conf 文件:这个文件通常位于 openGauss 数据目录的 postgresql.conf 文件的同一目录下。数据目录的位置取决于你的安装方式和设置。
  • 编辑 pg_hba.conf 文件:使用文本编辑器打开 pg_hba.conf 文件。在文件的末尾或适当的位置,添加一行规则来允许从任何 IP 地点访问。例如,如果你想要允许所有用户从任何 IP 地点通过暗码认证方式访问所有数据库,你可以添加如下行:
    [gauss@openGauss:/home/gauss]$vi /gauss/gaussdb/data/single_node/pg_hba.conf
    1. # TYPE  DATABASE        USER            ADDRESS                 METHOD
    2. 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
    1. # 设置如下参数
    2. listen_addresses = '*'
    3. port = 5432
    复制代码
  • 重启 openGauss 服务:修改 pg_hba.conf 文件后,你需要重启 openGauss 服务以使更改见效。重启服务的方法取决于你的安装方式和操作系统。例如,在某些 Linux 发行版上,你可能需要使用 systemctl 命令(如果 openGauss 被设置为 systemd 服务)或直接运行 openGauss 的启动脚本。
    1. [gauss@openGauss:/home/gauss]$gs_ctl stop -D /gauss/gaussdb/data/single_node -Z single_node
    2. [gauss@openGauss:/home/gauss]$gs_ctl start -D /gauss/gaussdb/data/single_node -Z single_node
    3. -- OR
    4. [gauss@openGauss:/home/gauss]$gs_ctl restart -D /gauss/gaussdb/data/single_node -Z single_node
    复制代码
  • 验证更改:实验从远程客户端连接到 openGauss 数据库,以验证你的更改是否已见效。
留意:虽然允许从任何 IP 地点访问数据库可能很方便,但这也会大大增加数据库被未授权访问的风险。因此,在生产情况中,你应该始终限定访问数据库的 IP 地点范围,并使用强暗码和其他安全步伐来保护你的数据库。
别的,如果你的 openGauss 实例位于防火墙背面,你还需要确保防火墙规则允许来自远程 IP 地点的入站连接(通常是 TCP 端口 5432,除非你在 postgresql.conf 文件中更改了端口)。
5、创建测试表

  1. [gauss@dbtest:/home/gauss]$gsql -h 192.168.80.223 -p 5432 -U super -d superdb
  2. Password for user super:**** -- 此时输入之前设置的密码
  3. gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:07:56 commit 0 last mr  )
  4. Non-SSL connection (SSL connection is recommended when requiring high-security)
  5. Type "help" for help.
  6. superdb=>create table t_opengauss (id bigint primary key,infoname varchar(50));
  7. CREATE TABLE
  8. superdb=> insert into t_opengauss values(1,'opengauss5.0');
  9. INSERT 0 1
  10. superdb=> insert into t_opengauss values(2,'openEuler23.09');
  11. INSERT 0 1
  12. superdb=> insert into t_opengauss values(3,'openEuler22.03');
  13. INSERT 0 1
  14. superdb=> select * from t_opengauss;
  15. id |    infoname
  16. ----+----------------
  17.   1 | opengauss5.0
  18.   2 | openEuler23.09
  19.   3 | openEuler22.03
  20. (3 rows)
  21. superdb=> comment on table t_opengauss is 'test';
  22. COMMENT
  23. superdb=> comment on column t_opengauss.id is 'primary key';
  24. COMMENT
  25. superdb=> comment on column t_opengauss.infoname is 'decriptions';
  26. COMMENT
  27. superdb=> \dt t_opengauss;
  28.                             List of relations
  29. Schema |    Name     | Type  | Owner |             Storage
  30. --------+-------------+-------+-------+----------------------------------
  31. public | t_opengauss | table | super | {orientation=row,compression=no}
  32. (1 row)
  33. superdb=> \dt+ t_opengauss
  34.                                          List of relations
  35. Schema |    Name     | Type  | Owner |    Size    |             Storage              | Description
  36. --------+-------------+-------+-------+------------+----------------------------------+-------------
  37. public | t_opengauss | table | super | 8192 bytes | {orientation=row,compression=no} | test
  38. (1 row)
  39. superdb=> \d t_opengauss
  40.           Table "public.t_opengauss"
  41.   Column  |         Type          | Modifiers
  42. ----------+-----------------------+-----------
  43. id       | bigint                | not null
  44. infoname | character varying(32) |
  45. Indexes:
  46.     "t_opengauss_pkey" PRIMARY KEY, btree (id) TABLESPACE pg_default
  47. superdb=> \d+ t_opengauss
  48.                               Table "public.t_opengauss"
  49.   Column  |         Type          | Modifiers | Storage  | Stats target | Description
  50. ----------+-----------------------+-----------+----------+--------------+-------------
  51. id       | bigint                | not null  | plain    |              | primary key
  52. infoname | character varying(32) |           | extended |              | decriptions
  53. Indexes:
  54.     "t_opengauss_pkey" PRIMARY KEY, btree (id) TABLESPACE pg_default
  55. Has OIDs: no
  56. Options: orientation=row, compression=no
复制代码
dbeaver数据库工具设置连接openGauss5.0请参考我的这篇文章
https://blog.csdn.net/zxrhhm/article/details/141465182?spm=1001.2014.3001.5501

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

圆咕噜咕噜

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表