1. 首页 > 软件安装教程 > 正文

opengauss安装-opengauss 3.1.0 for RHEL 9安装配置及升级迁移详细过程

1. 硬件环境检查

在安装openGauss数据库之前,必须对服务器的硬件环境进行全面检查,确保满足openGauss 3.1.0的最低要求。更多学习教程www.fgedu.net.cn

# 检查内存大小
# free -h
total used free shared buff/cache available
Mem: 16G 2.1G 12G 8.5M 1.8G 13G
Swap: 8G 0B 8G

# 检查磁盘空间
# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 8G 0 8G 0% /dev
tmpfs 8G 0 8G 0% /dev/shm
tmpfs 8G 8.5M 8G 1% /run
tmpfs 8G 0 8G 0% /sys/fs/cgroup
/dev/sda1 50G 15G 36G 30% /
/dev/sdb1 200G 20G 180G 10% /data

# 检查CPU核心数
# nproc
8

# 检查系统架构
# uname -m
x86_64

生产环境建议:最小内存8GB(测试环境),生产环境建议16GB以上。磁盘空间:系统盘至少50GB,数据盘根据业务需求配置,建议至少100GB。CPU:测试环境至少4核心,生产环境建议8核心以上。

2. 操作系统检查

openGauss 3.1.0支持RHEL 7.3+、RHEL 8.0+、RHEL 9.0+等操作系统。本文以RHEL 9为例。学习交流加群风哥微信: itpux-com

# 检查操作系统版本
# cat /etc/redhat-release
Red Hat Enterprise Linux release 9.0 (Plow)

# 检查内核版本
# uname -r
5.14.0-70.22.1.el9_0.x86_64

# 检查SELinux状态
# getenforce
Disabled

# 关闭SELinux(如未关闭)
# vi /etc/selinux/config
SELINUX=disabled

# 检查防火墙状态
# systemctl status firewalld

# 关闭防火墙(生产环境建议开放特定端口而非完全关闭)
# systemctl stop firewalld
# systemctl disable firewalld

3. 安装准备

在安装openGauss之前,需要进行一系列准备工作,包括安装依赖包、创建用户和目录结构等。

# 安装依赖包
# dnf install -y libaio-devel flex bison ncurses-devel glibc-devel patch redhat-lsb-core readline-devel
libnsl

# 创建用户组
# groupadd dbgrp

# 创建用户
# useradd -g dbgrp omm

# 设置密码
# passwd omm
Changing password for user omm.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

# 创建安装目录
# mkdir -p /opt/opengauss

# 创建数据目录
# mkdir -p /data/opengauss

# 设置权限
# chown -R omm:dbgrp /opt/opengauss
# chown -R omm:dbgrp /data/opengauss
# chmod -R 755 /opt/opengauss
# chmod -R 755 /data/opengauss

风哥提示:openGauss安装需要omm用户权限,建议使用omm账户进行安装。

4. openGauss软件安装

现在开始安装openGauss 3.1.0软件,按照以下步骤进行。

# 切换到omm用户
# su – omm

# 下载openGauss安装包
$ wget https://opengauss.org/en/downloads.html -O opengauss-3.1.0.tar.gz

# 解压安装包
$ tar -zxvf opengauss-3.1.0.tar.gz -C /opt/opengauss

# 创建配置文件
$ cat > /opt/opengauss/install_config.xml << EOF
















EOF

# 执行安装脚本
$ cd /opt/opengauss
$ ./script/install.sh -X install_config.xml

# 安装输出
[GAUSS-51800] : Installation is successful. Please check the log file for details:
/opt/opengauss/log/install.log

5. 数据库配置

配置openGauss数据库,包括修改配置文件和访问控制。

# 编辑postgresql.conf文件
# vi /data/opengauss/postgresql.conf

# 修改以下参数
listen_addresses = ‘*’
max_connections = 1000
shared_buffers = 4GB
work_mem = 32MB
maintenance_work_mem = 1GB
random_page_cost = 1.1
effective_cache_size = 12GB
wal_buffers = 16MB
checkpoint_completion_target = 0.9
max_wal_size = 1GB
min_wal_size = 80MB

# 编辑pg_hba.conf文件
# vi /data/opengauss/pg_hba.conf

# 添加以下内容
host all all 0.0.0.0/0 md5

# 重启数据库
# su – omm -c “/opt/opengauss/bin/gs_ctl restart -D /data/opengauss”

6. 测试验证

创建测试数据库和表,验证openGauss功能正常。学习交流加群风哥QQ113257174

# 连接openGauss
# su – omm -c “/opt/opengauss/bin/gsql -d postgres -p 5432”

# 创建数据库
postgres=# CREATE DATABASE fgedudb;

# 创建用户
postgres=# CREATE USER fgedu WITH PASSWORD ‘fgedu123’;

# 授权
postgres=# GRANT ALL PRIVILEGES ON DATABASE fgedudb TO fgedu;

# 连接到测试数据库
postgres=# \c fgedudb;

# 创建测试表
fgedudb=# CREATE TABLE fgedu_employees (
id INT PRIMARY KEY,
name VARCHAR(100),
salary DECIMAL(10,2)
);

# 插入测试数据
fgedudb=# INSERT INTO fgedu_employees VALUES (1, ‘张三’, 5000.00);
fgedudb=# INSERT INTO fgedu_employees VALUES (2, ‘李四’, 6000.00);
fgedudb=# INSERT INTO fgedu_employees VALUES (3, ‘王五’, 7000.00);

# 查询测试数据
fgedudb=# SELECT * FROM fgedu_employees;
+—-+——+——–+
| id | name | salary |
+—-+——+——–+
| 1 | 张三 | 5000.0 |
| 2 | 李四 | 6000.0 |
| 3 | 王五 | 7000.0 |
+—-+——+——–+

7. 备份配置

配置openGauss数据库备份策略,确保数据安全。

# 创建备份目录
# mkdir -p /backup/opengauss
# chown -R omm:dbgrp /backup/opengauss

# 执行逻辑备份
# su – omm -c “/opt/opengauss/bin/gs_dumpall -p 5432 -f /backup/opengauss/opengauss_backup_20260331.sql”

# 验证备份文件
# ls -la /backup/opengauss/
-rw-r–r– 1 omm dbgrp 123456 Mar 31 10:20 opengauss_backup_20260331.sql

# 配置自动备份
# 创建备份脚本
# vi /root/backup_opengauss.sh

#!/bin/bash

DATE=$(date +%Y%m%d)
BACKUP_DIR=”/backup/opengauss”

# 创建备份目录(如果不存在)
mkdir -p $BACKUP_DIR

# 执行备份
su – omm -c “/opt/opengauss/bin/gs_dumpall -p 5432 -f $BACKUP_DIR/opengauss_backup_$DATE.sql”

# 保留最近7天的备份
find $BACKUP_DIR -name “opengauss_backup_*.sql” -mtime +7 -delete

# 给脚本添加执行权限
# chmod +x /root/backup_opengauss.sh

# 添加到crontab
# crontab -e

# 添加以下内容(每天凌晨2点执行备份)
0 2 * * * /root/backup_opengauss.sh

8. 升级迁移

openGauss数据库的升级和迁移过程。

# 升级openGauss版本
# 1. 备份数据库
# su – omm -c “/opt/opengauss/bin/gs_dumpall -p 5432 -f
/backup/opengauss/opengauss_backup_before_upgrade.sql”

# 2. 停止数据库
# su – omm -c “/opt/opengauss/bin/gs_ctl stop -D /data/opengauss”

# 3. 下载新版本安装包
# wget https://opengauss.org/en/downloads.html -O opengauss-3.2.0.tar.gz

# 4. 解压安装包
# tar -zxvf opengauss-3.2.0.tar.gz -C /opt/opengauss-3.2.0

# 5. 执行升级脚本
# cd /opt/opengauss-3.2.0
# ./script/upgrade.sh -X /opt/opengauss/install_config.xml

# 6. 启动数据库
# su – omm -c “/opt/opengauss/bin/gs_ctl start -D /data/opengauss”

# 7. 验证升级结果
# su – omm -c “/opt/opengauss/bin/gsql -d postgres -p 5432 -c ‘SELECT version();'”

+———————————————————-+
| version() |
+———————————————————-+
| openGauss 3.2.0 build 10a1c8c0 (Jul 15 2023 02:52:48) |
+———————————————————-+

# 数据库迁移
# 从旧版本openGauss迁移到openGauss 3.1.0

# 1. 在旧系统上创建备份
# su – omm -c “/opt/opengauss/bin/gs_dumpall -p 5432 -f /backup/opengauss/opengauss_migration.sql”

# 2. 将备份文件复制到新系统
# scp /backup/opengauss/opengauss_migration.sql omm@192.168.1.51:/backup/opengauss/

# 3. 在新系统上恢复备份
# su – omm -c “/opt/opengauss/bin/gsql -d postgres -p 5432 -f /backup/opengauss/opengauss_migration.sql”

# 4. 验证迁移结果
# su – omm -c “/opt/opengauss/bin/gsql -d fgedudb -p 5432 -c ‘SELECT * FROM fgedu_employees;'”

风哥提示:数据库升级和迁移前,建议先在测试环境进行演练,确保升级过程顺利。同时,备份所有重要数据,以防万一。

9. 总结

本文详细介绍了openGauss 3.1.0 for RHEL 9的安装、配置、升级和迁移过程。通过按照本文的步骤操作,可以成功部署openGauss数据库并确保其稳定运行。from:fengge

生产环境建议:
– 定期备份数据库,建议每天执行一次全备份
– 监控数据库性能,定期检查数据库日志和错误信息
– 定期更新openGauss版本,确保系统安全性和性能
– 合理规划数据库存储,避免空间不足
– 配置合适的参数,优化数据库性能
– 对于生产环境,建议部署主从复制架构,提高可用性和可靠性

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息