【我和openGauss的故事】openGauss5.0企业版集群一主一备安装V1.0

2023/07/29 17:57
阅读数 89

一、基本环境

文档说明:

本方案只有主备数据同步,没有自动故障诊断、切换。

安装方式:利用 xml配置文件

管理工具:om方式

二、系统环境设置


类型

系统版本

IP

用户名/密码

备注

Primary

CentOS7.9

10.10.80.236

root/xxxxx


Standby

CentOS7.9

10.10.80.237

root/xxxxx












操作系统版本

cat /etc/redhat-release

CentOS Linux release 7.9.2009 (Core)


数据库版本

openGauss 5.0 企业版


设置主机名、 ip、  hosts文件


关闭防火墙、selinux


设置时区、时间同步


关闭SWAP分区(建议要求)

注释 swap 行

vim /etc/fstab


查看

free -h 查看 swap一行全是 0 表示swap关闭

安装系统软件包:

yum install -y libaio-devel flex bison ncurses-devel glibc-devel patch lsb_release readline-devel expect bzip2 ntp lsof

检查是否已安装

rpm -qa libaio-devel flex bison ncurses-devel glibc-devel patch lsb_release readline-devel expect bzip2

修改操作系统参数

cat >>/etc/sysctl.conf<<EOFnet.ipv4.tcp_fin_timeout=60net.ipv4.tcp_retries1=5net.ipv4.tcp_syn_retries=5#net.sctp.path_max_retrans=10#net.sctp.max_init_retransmits=10vm.min_free_kbytes=408677net.ipv4.ip_local_port_range=26000 65535net.ipv4.tcp_max_tw_buckets=10000net.ipv4.tcp_tw_reuse=0net.ipv4.tcp_tw_recycle=0net.ipv4.tcp_keepalive_time=30net.ipv4.tcp_keepalive_intvl=30net.ipv4.tcp_retries2=12net.ipv4.tcp_rmem=8192 250000 16777216net.ipv4.tcp_wmem=8192 250000 16777216net.core.wmem_max=21299200net.ipv4.tcp_tw_reuse=1net.ipv4.tcp_tw_recycle=1net.core.netdev_max_backlog=65535net.ipv4.tcp_max_syn_backlog=65535net.core.somaxconn=65535EOF

检查

cat /etc/sysctl.conf

使其生效

sysctl -p

如果有提示不存在的直接注释掉,再执行

关闭透明大页和设置网卡mtu(网卡名词根据实际修改)

-- openGauss默认关闭使用transparent_hugepage服务,并将关闭命令写入操作系统启动文件

cat >> /etc/rc.d/rc.local<<EOFif test -f /sys/kernel/mm/transparent_hugepage/enabled;thenecho never > /sys/kernel/mm/transparent_hugepage/enabledfiif test -f /sys/kernel/mm/transparent_hugepage/defrag;thenecho never > /sys/kernel/mm/transparent_hugepage/defragfiifconfig ens32 mtu 8192EOF
chmod 755 /etc/rc.d/rc.localsystemctl enable rc-localsystemctl start rc-local

-- 查看是否关闭:

cat /sys/kernel/mm/transparent_hugepage/enabledcat /sys/kernel/mm/transparent_hugepage/defrag

用户打开文件数和用户最大进程数

echo "* soft nofile 1000000" >>/etc/security/limits.confecho "* hard nofile 1000000" >>/etc/security/limits.conf echo "* hard  nproc  unlimited" >>/etc/security/limits.conf echo "* soft   nproc  unlimited" >>/etc/security/limits.conf

修改系统字符集

cat>> /etc/profile<<EOFexport LANG=en_US.UTF-8EOFsource /etc/profile

检查

cat /etc/profile | grep LANG

安装python3

服务器需要用到Python-3.x命令,但CentOS 7.x 默认版本Python-2.7.x,需要切换到Python-3.x版本

yum install libaio-devel flex bison ncurses-devel glibc-devel patch redhat-lsb python3 bzip2 –y
mv /usr/bin/python /usr/bin/python.bakln -s /usr/bin/python3 /usr/bin/python

设置yum使用python2.7否则无法通过yum install安装软件

vim /usr/bin/yum#!/usr/bin/python2.7:wq! 保存退出
vim /usr/libexec/urlgrabber-ext-down/usr/bin/python2.7:wq! 保存退出

测试一下yum是否可以正常使用

yum makecache

设置完成之后重启下系统,继续操作

重启主机系统

三、数据库安装

目录

对应名称

目录作用

/opt/software/openGauss

software

数据库软件存放目录

/opt/openGauss/app

gaussdbAppPath

数据库安装目录

/opt/openGauss/log

gaussdbLogPath

日志目录

/opt/openGauss/dn

dataNode1

主备节点数据存放目录

/opt/openGauss/tmp

tmpMppdbPath

临时文件目录

/opt/openGauss /om

gaussdbToolPath

数据库工具目录

/opt/gaussdb /corefile

corePath

数据库core文件目录

创建安装包存放目录(只在主节点上即可)

mkdir -p /opt/software/openGauss

将安装包上传到此目录

解压安装包

# tar -zxvf openGauss-5.0.0-CentOS-64bit-all.tar.gz# tar -zxvf openGauss-5.0.0-CentOS-64bit-om.tar.gz

创建数据库软件相关目录

(用户存储数据库数据、日志、工具、临时文件等) 两个节点

创建数据库软件相关目录

mkdir -p /opt/openGausschmod -R 755 /opt/openGauss

集群xml配置文件

可以参考官方文档 配置示例

 # find / -name cluster_config_template.xml
# cp /opt/software/openGauss/script/gspylib/etc/conf/cluster_config_template.xml /opt/software/openGauss/cluster_config.xml

# vi cluster_config.xml

主要分为两部分<CLUSTER>和<CEVICELIST>

部分参数解释


参数

参数值

作用

sn

主机名

节点的唯一标识  用主机名即可

dataPortBase

15400

数据库对外提供的访问端口

backIp1

IP 地址

后台通讯地址

dataNode1

主节点数据目录,备节点主机名,备节点数据目录

数据存放目录,




执行预检查

# /opt/software/openGauss/script/gs_checkos   -i A -h gaussdb01  --detail

说明事项:
Normal 为正常项,Abnormal为必须处理项,Warning可以不处理。

根据报错 修改两个节点

比如

/etc/sysctl.confvm.min_free_kbytes=408677net.ipv4.ip_local_port_range=26000 65535………………………………………………………………………………………
# blockdev --setra 16384 /dev/sdb……………………………………………..

预先安装

# /opt/software/openGauss/script/gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/cluster_config.xml

预安装失败

rm -rf /opt/openGauss/*chown omm:dbgrp -R /opt/openGausschown omm:dbgrp -R /opt/software/openGauss# chmod -R 755  /opt/openGauss# chmod -R 755  /opt/software/openGauss

再次执行

# /opt/software/openGauss/script/gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/cluster_config.xml

设置用户omm的密码为jingya@2016

正式安装

#su  - omm$[omm@postgresql script]$ gs_install -X  /opt/software/openGauss/cluster_config.xml

默认是UTF8 字符集 也可以手动指定—encoding= UTF8

四、设置备机可读

检查相关参数

# cat /opt/openGauss/dn/postgresql.conf|grep -i wal_level

日志级别hot_standby

默认就是

# cat /opt/openGauss/dn/postgresql.conf|grep -i hot_standby

备库可读,默认已经开启

五、 验证数据同步

主上创建表

openGauss=# create table tb1 (id int,name text);CREATE TABLE
openGauss=#  insert into tb1 (id,name) values (10,'Jacky');

备库上进行查询


能够查询到数据

六、数据库状态检查

连接数据库

gsql -d postgres -p 15400

-- omm用户[omm@gaussdb01 ~]$ gs_om -t status --detail[   Cluster State   ]
cluster_state   : Normalredistributing  : Nocurrent_az      : AZ_ALL
[  Datanode State   ]
   node     node_ip         port      instance                  state--------------------------------------------------------------------------------------1  gaussdb01 10.10.80.236    15400      6001 /opt/openGauss/dn   P Primary Normal 2  gaussdb02 10.10.80.237    15400      6002 /opt/openGauss/dn   S Standby Normal

“cluster_state”显示“Normal”表示数据库可正常

更详细信息

$ gs_om -t status --all

C查询HA状态

$ gs_ctl query -D /opt/openGauss/dn

七、总结

通过对openGauss数据库集群的部署,使我感受最深的一点是集群部署的方便性、灵活性,与其他数据库要配置大量的参数相比,openGaussGauss数据库通过定义xml文件来实现一键部署,能够更加快速实现业务对数据库的需求。


本文分享自微信公众号 - openGauss(openGauss)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部