GBase 8a支持ipv4和ipv6的ip地址,如果从ipv4更换到ipv6时,必须手工逐个节点的修改替换,或者自行编写个工具来执行。本文介绍一个新的GBase 提供的ip地址更换工具,可以自动将集群所有节点的ip从ipv4更改到ipv6。
本文测试时尚不是最终发布版本,如有变动会更新本文档。
本文测试的是8.6.2Build43,未包含95。
目录导航
注意
如果系统存在event或者故障节点,请先修复,集群必须处于完全正常状态。
如果有未完成的重分布,也请先完成,之后删掉无用的分布策略distribuition。
在替换IP前,停掉业务,包括外部定时任务,数据库内定时任务。
建议整个集群重启一次,操作步骤参考 GBase 8a从V8升级到V9的REDOLOG的刷新处理,虽然替换功能本身会刷REDOLOG。
环境
2节点ipv4集群,8.6.2Build43R35.5版本。两台服务器已经配置了ipv6地址并生效。
[root@rh6-1 gcreplaceip]# gcadmin
CLUSTER STATE: ACTIVE
CLUSTER MODE: NORMAL
=================================================================
| GBASE COORDINATOR CLUSTER INFORMATION |
=================================================================
| NodeName | IpAddress |gcware |gcluster |DataState |
-----------------------------------------------------------------
| coordinator1 | 10.0.2.201 | OPEN | OPEN | 0 |
-----------------------------------------------------------------
| coordinator2 | 10.0.2.202 | OPEN | OPEN | 0 |
-----------------------------------------------------------------
=============================================================
| GBASE DATA CLUSTER INFORMATION |
=============================================================
|NodeName | IpAddress |gnode |syncserver |DataState |
-------------------------------------------------------------
| node1 | 10.0.2.201 | OPEN | OPEN | 0 |
-------------------------------------------------------------
| node2 | 10.0.2.202 | OPEN | OPEN | 0 |
-------------------------------------------------------------
新的ipv6地址分别为2001::201和2001::202, 本文只是测试目的,请根据实际要求更换IPV6。
201节点
[gbase@rh6-1 gcreplaceip]$ ifconfig eth0
eth0 Link encap:Ethernet HWaddr 08:00:27:30:04:2F
inet addr:10.0.2.201 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: 2001::201/64 Scope:Global
inet6 addr: fe80::a00:27ff:fe30:42f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11982 errors:0 dropped:0 overruns:0 frame:0
TX packets:17348 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1445641 (1.3 MiB) TX bytes:2323338 (2.2 MiB)
202节点
[root@rh6-2 ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 08:00:27:C6:0F:AE
inet addr:10.0.2.202 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: 2001::202/64 Scope:Global
inet6 addr: fe80::a00:27ff:fec6:fae/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:15815 errors:0 dropped:0 overruns:0 frame:0
TX packets:10777 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2182245 (2.0 MiB) TX bytes:1309792 (1.2 MiB)
替换工具
[root@rh6-1 gcreplaceip]# ll
total 104
-rw-r--r-- 1 root root 44016 Aug 19 10:48 gcReplaceIp.py
-rw-r--r-- 1 root root 206 Aug 23 10:11 hostReplaceIp.json
-rw-r--r-- 1 root root 17 Aug 19 10:48 README.md
-rw-r--r-- 1 root root 28472 Aug 19 10:48 ReplaceIpFuns.py
-rw-r--r-- 1 root root 276 Aug 23 10:11 replaceip.options
-rw-r--r-- 1 root root 8648 Aug 19 10:48 rmt.py
-rw-r--r-- 1 root root 2596 Aug 19 10:48 SSHThread.py
-rw-r--r-- 1 root root 1812 Aug 19 10:48 使用说明.txt
替换程序
gcReplaceIp.py
[gbase@rh6-1 gcreplaceip]$ ./gcReplaceIp.py --help
Usage: gcReplaceIp.py [options]
Options:
-h, --help show this help message and exit
--silent=SILENTCONFIG
use the supplied properties file for a 'silent'
ipreplace
--passwordInputMode=PASSWORDINPUTMODE
get password method[file,pwdsame,pwddiff],
file: get from config file,default
pwdsame: nodes have the same user passwd
pwddiff: nodes have different user passwds
[gbase@rh6-1 gcreplaceip]
配置文件
replaceip.options
与安装配置文件格式相同,包括现有集群的IP和密码等信息,增加了IP替换的配置文件的参数
[root@rh6-1 gcreplaceip]# cat replaceip.options
installPrefix= /opt
coordinateHost = 10.0.2.201,10.0.2.202
dataHost = 10.0.2.201,10.0.2.202
#gcwareHost = 192.168.7.210
dbaUser = gbase
dbaGroup = gbase
dbaPwd = 'gbase1234'
rootPwd = '111111'
version = V862
#rootPwdFile = rootPwd.json
hostReplaceIpFile = hostReplaceIp.json
hostReplaceIp.json
IP替换规则
[root@rh6-1 gcreplaceip]# cat hostReplaceIp.json
{
"HOSTREPLACEIP":[
{
"OLDIP":"10.0.2.201",
"NEWIP":"2001::201"
},
{
"OLDIP":"10.0.2.202",
"NEWIP":"2001::202"
}
]
}
运行样例
要在dbaUser下运行。最终集群成功从ipv4替换到了ipv6地址。
[root@rh6-1 gcreplaceip]# chmod a+x *.py
[root@rh6-1 gcreplaceip]# chown -R gbase:gbase *
[root@rh6-1 gcreplaceip]# su gbase
[gbase@rh6-1 gcreplaceip]$ ./gcReplaceIp.py --silent=replaceip.options
*********************************************************************************
Welcome to use GBase products
*********************************************************************************
modify gcware file on 10.0.2.201 successfully.
modify gcware file on 10.0.2.202 successfully.
Starting all gcluster nodes...
sys.exit
[gbase@rh6-1 gcreplaceip]$ gcadmin
CLUSTER STATE: ACTIVE
CLUSTER MODE: NORMAL
=========================================================
| GBASE COORDINATOR CLUSTER INFORMATION |
=========================================================
| NodeName | IpAddress |gcware |gcluster |DataState |
---------------------------------------------------------
| coordinator1 | 2001::201 | OPEN | OPEN | 0 |
---------------------------------------------------------
| coordinator2 | 2001::202 | OPEN | OPEN | 0 |
---------------------------------------------------------
=====================================================
| GBASE DATA CLUSTER INFORMATION |
=====================================================
|NodeName | IpAddress |gnode |syncserver |DataState |
-----------------------------------------------------
| node1 | 2001::201 | OPEN | OPEN | 0 |
-----------------------------------------------------
| node2 | 2001::202 | OPEN | OPEN | 0 |
-----------------------------------------------------
[gbase@rh6-1 gcreplaceip]$
执行日志
[root@rh6-1 gcreplaceip]# cat gcReplaceIp.log
2022-08-23 10:12:36,004-DEBUG chmod 766 /home/gbase/gcreplaceip/gcReplaceIp.log
2022-08-23 10:12:54,044-DEBUG chmod 766 /home/gbase/gcreplaceip/gcReplaceIp.log
2022-08-23 10:12:57,069-INFO coordinateHost ?: ['10.0.2.201', '10.0.2.202']
2022-08-23 10:12:57,069-INFO dataHost ?: ['10.0.2.201', '10.0.2.202']
2022-08-23 10:12:57,069-DEBUG stop all gcluster nodes...
2022-08-23 10:13:06,829-INFO 10.0.2.201: stop service successfully.
2022-08-23 10:13:07,480-INFO 10.0.2.202: stop service successfully.
2022-08-23 10:13:08,411-INFO bakeup file on v862 version...
2022-08-23 10:13:14,433-DEBUG modify corosync file...
2022-08-23 10:13:19,820-INFO modify gcware file on 10.0.2.201 successfully.
2022-08-23 10:13:20,271-INFO modify gcware file on 10.0.2.202 successfully.
2022-08-23 10:13:20,813-DEBUG Starting all gcluster nodes...
2022-08-23 10:13:39,273-INFO start service successfull on host 10.0.2.201.
2022-08-23 10:13:39,837-INFO start service successfull on host 10.0.2.202.
2022-08-23 10:35:37,482-DEBUG chmod 766 /home/gbase/gcreplaceip/gcReplaceIp.log
[root@rh6-1 gcreplaceip]#
回退
更换前,所有重要的文件都备份在/home/gbase目录下,一般类似如下的样子、
/home/gbase/gcluster_backup_20220823093037.tar.bz2
里面就是所有文件,
[root@rh6-1 ip]# ll
total 20
drwxr-xr-x 6 root root 4096 Aug 24 15:37 etc
drwxr-xr-x 3 root root 4096 Aug 24 15:37 home
drwxr-xr-x 4 root root 4096 Aug 24 15:37 opt
drwxr-xr-x 7 root root 4096 Aug 24 15:37 usr
drwxr-xr-x 4 root root 4096 Aug 24 15:37 var
可以直接解压,然后覆盖即可。 也可以直接解压到根目录,直接覆盖。
注意每个节点都要做。用安装程序的restore.py也可以。