南大通用GBase 8a自动生成gcChangeInfo.xml同组互备策略的脚本

GBase 8a数据库集群,对数据节点的主副本备份方式,默认是循环制,2备份1,3备份2,4备份3,1备份最后1个节点。在某些情况下,可以人工指定备份方式,比如本文介绍的分成多个组,组内互备,也就是2备份1,1备份2,4备份3,3备份4。本文提供自动生成gcChangeInfo.xml同组互备策略的脚本。

互备的优势

比如1+1的情况,如果坏2台服务器,在循环备份情况下,100%会导致集群不可用。而互备,则有50%的可能是2台落在了2个互备组里,所以有50%的几率继续可用。

故障恢复除了标准的节点替换外,可以采用物理文件迁移的方式,特别是数据量不是极大(5T以内)时。因为2个节点互备,数据完全相同,直接复制过去就行。而循环备份则分布在前后2台服务器上。

互备的缺点

当1个节点故障,做故障恢复时,只有1个节点提供数据,而循环备份的可以有2个。

循环备份的样子

[gbase@localhost gcinstall]$ gcadmin showdistribution

              Distribution ID: 1 | State: new | Total segment num: 4

    Primary Segment Node IP         Segment ID         Duplicate Segment node IP
====================================================================================
|       192.168.174.151        |       1          |        192.168.174.152         |
------------------------------------------------------------------------------------
|       192.168.174.152        |       2          |        192.168.174.153         |
------------------------------------------------------------------------------------
|       192.168.174.153        |       3          |        192.168.174.154         |
------------------------------------------------------------------------------------
|       192.168.174.154        |       4          |        192.168.174.151         |
====================================================================================
[gbase@localhost gcinstall]$ 

同组互备的样子

[gbase@localhost gcinstall]$ gcadmin showdistribution

              Distribution ID: 1 | State: new | Total segment num: 4

    Primary Segment Node IP         Segment ID         Duplicate Segment node IP
====================================================================================
|       192.168.174.151        |       1          |        192.168.174.152         |
------------------------------------------------------------------------------------
|       192.168.174.152        |       2          |        192.168.174.151         |
------------------------------------------------------------------------------------
|       192.168.174.153        |       3          |        192.168.174.154         |
------------------------------------------------------------------------------------
|       192.168.174.154        |       4          |        192.168.174.153         |
====================================================================================
[gbase@localhost gcinstall]$ 

样例IP

每个IP占用一行,最后一个IP后不要多一个换行

[gbase@Gbase1521 test]$ cat iplist.txt 
192.168.168.1
192.168.168.2
192.168.168.3
192.168.168.4
192.168.168.5
192.168.168.6
192.168.168.7
192.168.168.8
192.168.168.9
192.168.168.10

生成1+1副本的代码

要求IP数量为偶数。使用方式为输出到一个文件里

sh genGcXML.sh > distribution.xml
[gbase@Gbase1521 test]$ cat genGcXML.sh 
echo "<?xml version='1.0' encoding="utf-8"?>"
echo "<distributions>"
echo " <distribution>"
echo "  <segments>"

cat iplist.txt|while read line;
do
  read line2
  echo "<segment>"
  echo "  <primarynode ip=\"$line\"/>"
  echo "  <duplicatenodes>"
  echo "    <duplicatenode ip=\"$line2\"/>"
  echo "  </duplicatenodes>"
  echo "</segment>"
  echo "<segment>"
  echo "  <primarynode ip=\"$line2\"/>"
  echo "  <duplicatenodes>"
  echo "    <duplicatenode ip=\"$line\"/>"
  echo "  </duplicatenodes>"
  echo "</segment>"
  echo
done

echo "  </segments>"
echo " </distribution>"
echo "</distributions>"

输出样例

<?xml version='1.0' encoding="utf-8"?>
<distributions>
 <distribution>
  <segments>
<segment>
  <primarynode ip="192.168.168.1"/>
  <duplicatenodes>
    <duplicatenode ip="192.168.168.2"/>
  </duplicatenodes>
</segment>
<segment>
  <primarynode ip="192.168.168.2"/>
  <duplicatenodes>
    <duplicatenode ip="192.168.168.1"/>
  </duplicatenodes>
</segment>

<segment>
  <primarynode ip="192.168.168.3"/>
  <duplicatenodes>
    <duplicatenode ip="192.168.168.4"/>
  </duplicatenodes>
</segment>
<segment>
  <primarynode ip="192.168.168.4"/>

............ 忽略

生成1+2副本的代码

要求IP是3的倍数

[gbase@Gbase1521 test]$ cat genGcXM_3L.sh 
echo "<?xml version='1.0' encoding="utf-8"?>"
echo "<distributions>"
echo " <distribution>"
echo "  <segments>"

cat iplist.txt|while read line;
do
  read line2
  read line3
  echo "<segment>"
  echo "  <primarynode ip=\"$line\"/>"
  echo "  <duplicatenodes>"
  echo "    <duplicatenode ip=\"$line2\"/>"
  echo "    <duplicatenode ip=\"$line3\"/>"
  echo "  </duplicatenodes>"
  echo "</segment>"
  echo "<segment>"
  echo "  <primarynode ip=\"$line2\"/>"
  echo "  <duplicatenodes>"
  echo "    <duplicatenode ip=\"$line\"/>"
  echo "    <duplicatenode ip=\"$line3\"/>"
  echo "  </duplicatenodes>"
  echo "</segment>"
  echo "<segment>"
  echo "  <primarynode ip=\"$line3\"/>"
  echo "  <duplicatenodes>"
  echo "    <duplicatenode ip=\"$line\"/>"
  echo "    <duplicatenode ip=\"$line2\"/>"
  echo "  </duplicatenodes>"
  echo "</segment>"
  echo
done

echo "  </segments>"
echo " </distribution>"
echo "</distributions>"

样例就不写了,和前面的一样,只是每组3个IP,1+2副本互备。

gcChangeInfo.xml格式

其中的cfgFile指向你生成的distribution.xml 名字随意,匹配上即可。

[gbase@localhost gcinstall_8.6.2.20R1]$ cat gcChangeInfo.xml 
<?xml version="1.0" encoding="utf-8"?>
<servers>
<cfgFile file="distribution.xml"/>
</servers>