【我和openGauss的故事】openGauss5.0企业版集群一主一备安装V1.0
  lYE0sTgD5uUi 2023年11月02日 68 0

王zz [openGauss](javascript:void(0);) 2023-07-29 17:58 发表于四川

收录于合集#第六届openGauss技术文章征集初审合格文章62个

一、基本环境

文档说明:

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

安装方式:利用 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<<EOF
net.ipv4.tcp_fin_timeout=60
net.ipv4.tcp_retries1=5
net.ipv4.tcp_syn_retries=5
#net.sctp.path_max_retrans=10
#net.sctp.max_init_retransmits=10
vm.min_free_kbytes=408677
net.ipv4.ip_local_port_range=26000 65535
net.ipv4.tcp_max_tw_buckets=10000
net.ipv4.tcp_tw_reuse=0
net.ipv4.tcp_tw_recycle=0
net.ipv4.tcp_keepalive_time=30
net.ipv4.tcp_keepalive_intvl=30
net.ipv4.tcp_retries2=12
net.ipv4.tcp_rmem=8192 250000 16777216
net.ipv4.tcp_wmem=8192 250000 16777216
net.core.wmem_max=21299200
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_tw_recycle=1
net.core.netdev_max_backlog=65535
net.ipv4.tcp_max_syn_backlog=65535
net.core.somaxconn=65535
EOF

检查

cat /etc/sysctl.conf

使其生效

sysctl -p

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

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

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

cat >> /etc/rc.d/rc.local<<EOF
if test -f /sys/kernel/mm/transparent_hugepage/enabled;
then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag;
then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
ifconfig ens32 mtu 8192
EOF

chmod 755 /etc/rc.d/rc.local
systemctl enable rc-local
systemctl start rc-local

-- 查看是否关闭:

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

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

echo "* soft nofile 1000000" >>/etc/security/limits.conf
echo "* 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<<EOF
export LANG=en_US.UTF-8
EOF
source /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

主要分为两部分和

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

部分参数解释

参数

参数值

作用

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

四、设置备机可读

检查相关参数

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

日志级别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   : Normal
redistributing  : No
current_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”表示数据库可正常

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

更详细信息

$ gs_om -t status --all

C查询HA状态

$ gs_ctl query -D /opt/openGauss/dn

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

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

七、总结

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

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  X5zJxoD00Cah   2023年12月11日   27   0   0 知乎Python迭代器
  X5zJxoD00Cah   2023年12月12日   34   0   0 Python.net
lYE0sTgD5uUi