【openGauss学习】CentOS7.9系统安装主、备集群
1.资源地址
#CentOS官方下载地址
http://isoredirect.centos.org/centos/7.9.2009/isos/x86_64/
#openGauss官方下载地址
https://opengauss.org/zh/download.html
#openGauss代码托管地址
https://gitee.com/opengauss
2.环境工具
VMware Workstation 16 Xmanager Power Suite 7
3.资源规划
#CPU资源分配
2C
#MEM资源分配
4G
#DSK资源分配
vg00:20G
vgdata:40G
#NIC资源分配
Backend Network(host-only):bond0(ens32 & ens33)
Frontend Network(NAT):ens35
CentOS7.9 Minimal Install(勾选“Compatibility Libraries”、“Development Tools”和“System Administration Tools”)
4.环境准备
#关闭firewalld
systemctl disable firewalld
#关闭SELinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
#关闭SWAP
sed -ri 's/.*swap.*/#&/' /etc/fstab
#安装软件包
yum -y install python3 libaio-devel ncurses-devel glibc-devel redhat-lsb readline-devel net-tools sysstat
#修改系统版本显示
echo "CentOS Linux release 7.6.1810 (Core)">/etc/centos-release
#配置hosts解析
echo "192.168.10.81 ogdb1">>/etc/hosts
echo "192.168.10.82 ogdb2">>/etc/hosts
#创建用户组及用户
groupadd dbgrp && useradd omm -g dbgrp
#修改内核参数
cat << EOF >>/etc/sysctl.conf
net.ipv4.tcp_retries1 = 5
net.ipv4.tcp_syn_retries = 5
net.sctp.path_max_retrans = 10
net.sctp.max_init_retransmits = 10
EOF
#修改系统参数
cat << EOF >>/etc/systemd/system.conf
DefaultLimitNOFILE=1000000
DefaultLimitNPROC=unlimited
EOF
#配置数据存储空间
pvcreate /dev/sdb
vgcreate vgdata /dev/sdb
lvcreate -n lvdata -L 10G /dev/vgdata
lvcreate -n lvlog -L 5G /dev/vgdata
mkfs -t ext4 /dev/vgdata/lvdata
mkfs -t ext4 /dev/vgdata/lvlog
mkdir /gaussdb /gausslog
echo "/dev/vgdata/lvdata /gaussdb ext4 defaults 0 0">>/etc/fstab
echo "/dev/vgdata/lvlog /gausslog ext4 defaults 0 0">>/etc/fstab
mount -a
chown -R omm.dbgrp /gaussdb
chown -R omm.dbgrp /gausslog
5.配置时间同步
yum -y install chrony
#Server侧(ogdb1)配置
sed -i "s/server 0.centos.pool.ntp.org iburst/pool 0.cn.pool.ntp.org/g" /etc/chrony.conf
sed -i "s/server 1.centos.pool.ntp.org iburst/pool 1.cn.pool.ntp.org/g" /etc/chrony.conf
sed -i "s/server 2.centos.pool.ntp.org iburst/pool 2.cn.pool.ntp.org/g" /etc/chrony.conf
sed -i "s/server 3.centos.pool.ntp.org iburst/pool 3.cn.pool.ntp.org/g" /etc/chrony.conf
sed -i "27iallow 192.168.10.0/24" /etc/chrony.conf
sed -i "31ilocal stratum 10" /etc/chrony.conf
#Client侧(ogdb2)配置
sed -i "3,6 s/^/#/g" /etc/chrony.conf
sed -i "7iserver 192.168.10.81 iburst" /etc/chrony.conf
systemctl start chronyd && systemctl enable chronyd
6.绑定集群网络
在主、备节点(ogdb1、ogdb2)均配置集群双网卡绑定
#配置/etc/sysconfig/network-scripts/ifcfg-bond0
cat <<EOF>/etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
NAME=bond0
TYPE=Bond
BONDING_MASTER=yes
IPADDR=192.168.10.81
PREFIX=24
ONBOOT=yes
BOOTPROTO=none
BONDING_OPTS="mode=1 miimon=100"
NM_CONTROLLED="no"
EOF
#配置/etc/sysconfig/network-scripts/ifcfg-ens32
cat <<EOF> /etc/sysconfig/network-scripts/ifcfg-ens32
DEVICE=ens32
NAME=bond0-slave
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
NM_CONTROLLED="no"
EOF
#配置/etc/sysconfig/network-scripts/ifcfg-ens33
cat <<EOF> /etc/sysconfig/network-scripts/ifcfg-ens33
DEVICE=ens33
NAME=bond0-slave
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
NM_CONTROLLED="no"
EOF
systemctl restart network
7.准备集群配置文件(/tmp/cluster_config.xml)
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<!-- openGauss整体信息 -->
<CLUSTER>
<PARAM name="clusterName" value="Clus_ogdb" />
<PARAM name="nodeNames" value="ogdb1,ogdb2" />
<PARAM name="gaussdbAppPath" value="/gaussdb/app" />
<PARAM name="gaussdbLogPath" value="/gausslog" />
<PARAM name="tmpMppdbPath" value="/gaussdb/tmp"/>
<PARAM name="gaussdbToolPath" value="/gaussdb/om" />
<PARAM name="corePath" value="/gaussdb/corefile"/>
<PARAM name="backIp1s" value="192.168.10.81,192.168.10.82"/>
</CLUSTER>
<!-- 每台服务器上的节点部署信息 -->
<DEVICELIST>
<!-- node1上的节点部署信息 -->
<DEVICE sn="ogdb1">
<PARAM name="name" value="ogdb1"/>
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
<PARAM name="backIp1" value="192.168.10.81"/>
<PARAM name="sshIp1" value="192.168.10.81"/>
<!--dn-->
<PARAM name="dataNum" value="1"/>
<PARAM name="dataPortBase" value="15400"/>
<PARAM name="dataNode1" value="/gaussdb/data/dn,ogdb2,/gaussdb/data/dn"/>
<PARAM name="dataNode1_syncNum" value="0"/>
</DEVICE>
<!-- node2上的节点部署信息,其中“name”的值配置为主机名称 -->
<DEVICE sn="ogdb2">
<PARAM name="name" value="ogdb2"/>
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
<PARAM name="backIp1" value="192.168.10.82"/>
<PARAM name="sshIp1" value="192.168.10.82"/>
</DEVICE>
</DEVICELIST>
</ROOT>
8.准备集群
#上传安装文件到/tmp
tar -zxvf openGauss-2.0.1-CentOS-64bit-all.tar.gz
tar -zxvf openGauss-2.0.1-CentOS-64bit-om.tar.gz
#准备安装环境
/tmp/script/gs_preinstall -U omm -G dbgrp -X /tmp/cluster_config.xml
#重启系统,使配置生效
reboot
9.安装集群
su - omm gs_install -X /tmp/cluster_config.xml \ --gsinit-parameter="--encoding=UTF8" \ --dn-guc="max_connections=1000" \ --dn-guc="max_process_memory=2GB" \ --dn-guc="shared_buffers=128MB" \ --dn-guc="bulk_write_ring_size=128MB" \ --dn-guc="cstore_buffers=16MB"
10.查看集群运行状态
gs_om -t status ----------------------------------------------------------------------- cluster_name : Clus_ogdb cluster_state : Normal redistributing : No ----------------------------------------------------------------------- gs_om -t status --detail [ Cluster State ] cluster_state : Normal redistributing : No current_az : AZ_ALL [ Datanode State ] node node_ip instance state | node node_ip instance state ---------------------------------------------------------------------------------------------------------------------------------------- 1 ogdb1 192.168.10.81 6001 /gauss/data/dn P Primary Normal | 2 ogdb2 192.168.10.82 6002 /gauss/data/dn S Standby Normal
11.配置客户端参数
#创建Data Studio登录用户
gsql -d postgres -p 15400 -c "create user user1 with password 'P@ssw0rd';"
#设置Data Studio登录权限
gs_guc reload -N all -I all -h "host all all 192.168.10.0/24 sha256"
#openGauss Data Studio 2.0使用user1用户和密码,以非ssl方式可以登录postgres数据库
12.启停集群
gs_om -t start Starting cluster. ========================================= [SUCCESS] ogdb1 [SUCCESS] ogdb2 ========================================= Successfully started. gs_om -t stop Stopping cluster. ========================================= Successfully stopped cluster. ========================================= End stop cluster.
13.切换实例
登录备节点(ogdb2)
#进行实例切换
gs_ctl switchover -D /gaussdb/data/dn
[2021-06-10 11:11:40.582][9804][][gs_ctl]: gs_ctl switchover ,datadir is /gaussdb/data/dn
[2021-06-10 11:11:40.582][9804][][gs_ctl]: switchover term (1)
[2021-06-10 11:11:40.586][9804][][gs_ctl]: waiting for server to switchover................
[2021-06-10 11:11:53.646][9804][][gs_ctl]: done
[2021-06-10 11:11:53.646][9804][][gs_ctl]: switchover completed (/gaussdb/data/dn)
#进行信息记录
gs_om -t refreshconf
Generating dynamic configuration file for all nodes.
Successfully generated dynamic configuration file.
#查看集群运行状态
gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip instance state | node node_ip instance state
--------------------------------------------------------------------------------------------------------------------------------------------
1 ogdb1 192.168.10.81 6001 /gaussdb/data/dn P Standby Normal | 2 ogdb2 192.168.10.82 6002 /gaussdb/data/dn S Primary Normal
#转换时间服务同步方向(从ogdb2->ogdb1,到ogdb1->ogdb2)
14.查看集群信息
#分别在ogdb1和ogdb2执行
gs_ctl query -D /gaussdb/data/dn
15.打印集群配置信息
gs_om -t view
16.检查集群健康状态
gs_check -e inspect
17.集群相关日志
类型 | 位置 |
---|---|
系统日志 | /gausslog/omm/pg_log(数据库运行日志) /gausslog/omm/om(om操作日志) |
操作日志 | /gausslog/omm/bin |
审计日志 | /gausslog/omm/pg_audit |
WAL日志 | /gaussdb/data/dn/pg_xlog |
性能日志 | /gausslog/omm/omm/gs_profile |
18.增加集群节点
#准备扩容节点(ogdb2)环境(按照正常安装集群的环境准备)
#建立节点间root用户和omm用户的ssh信任关系(ogdb1和ogdb2均执行如下操作)
ssh-keygen -t dsa
ssh-copy-id ogdb1
ssh-copy-id ogdb2
#在节点(ogdb1和ogdb2)准备集群xml文件(/tmp/cluster_config.xml)
#在扩容节点(ogdb2)利用脚本初始化集群安装环境
/tmp/script/gs_preinstall -U omm -G dbgrp -X /tmp/cluster_config.xml -L
#在主节点(ogdb1)导入主数据库环境变量
source /home/omm/.bashrc
#在主节点(ogdb1)执行扩容操作
/tmp/script/gs_expansion -U omm -G dbgrp -X /tmp/cluster_config.xml -h 192.168.10.82
19.删除集群节点
#在主节点(ogdb1)执行
gs_dropnode -U omm -G dbgrp -h 192.168.10.82
#删除备节点(ogdb2)ssh信任关系
mv /root/.ssh /root/.ssh_bak && mv /home/omm/.ssh /home/omm/.ssh_bak
#卸载备节点(ogdb2)配置
gs_uninstall --delete-data -L
#清理备节点(ogdb2)安装环境
/tmp/script/gs_postuninstall -U omm -X /tmp/cluster_config.xml --delete-user --delete-group -L
#删除残留文件
cd /gaussdb && rm -rf *;cd /gausslog && rm -rf *
20.删除集群
#使用omm用户卸载集群
gs_uninstall --delete-data
#使用root用户清理安装环境
/tmp/script/gs_postuninstall -U omm -X /tmp/cluster_config.xml --delete-user --delete-group
最后修改时间:2021-06-10 17:51:35
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。