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的根本功能
- 连接数据库: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命令:
- 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
- # 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
复制代码 - 重启 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
复制代码 - 验证更改:实验从远程客户端连接到 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
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |