KingbaseES V8R3集群管理维护案例之---集群迁移单实例架构

案例说明:
在生产中,需要将KingbaseES V8R3集群转换为单实例架构,可以采用以下方式快速完成集群架构的迁移。

适用版本:
KingbaseES V8R3

当前数据库版本:

TEST=# select version();
                                                         VERSION
-------------------------------------------------------------------------------------------------------------------------
 Kingbase V008R003C002B0290 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 64-bit
(1 row)

集群状态信息:

TEST=# show pool_nodes;
 node_id |   hostname    | port  | status | lb_weight |  role   | select_cnt | load_balance_node | replication_delay
---------+---------------+-------+--------+-----------+---------+------------+-------------------+-------------------
 0       | 192.168.1.101 | 54321 | up     | 0.500000  | standby | 0          | false             | 0
 1       | 192.168.1.102 | 54321 | up     | 0.500000  | primary | 0          | true              | 0
(2 rows)

流复制状态信息:

TEST=# select * from sys_stat_replication;
  PID  | USESYSID | USENAME | APPLICATION_NAME |  CLIENT_ADDR  | CLIENT_HOSTNAME | CLIENT_PORT |         BACKEND_START         | BACKE
ND_XMIN |   STATE   | SENT_LOCATION | WRITE_LOCATION | FLUSH_LOCATION | REPLAY_LOCATION | SYNC_PRIORITY | SYNC_STATE
-------+----------+---------+------------------+---------------+-----------------+-------------+-------------------------------+------
--------+-----------+---------------+----------------+----------------+-----------------+---------------+------------
 18217 |       10 | SYSTEM  | node101          | 192.168.1.101 |                 |       45972 | 2022-07-29 16:14:33.202101+08 |
        | streaming | 0/2E0001B0    | 0/2E0001B0     | 0/2E0001B0     | 0/2E0001B0      |             1 | sync
(1 row)

一、在主库初始化新的实例

=注意:需要和原集群的配置环境一致,如大小写敏感性、字符集等。=

1、初始化新的实例

[kingbase@node102 bin]$ ./initdb -U system -W 123456  -E utf8 -D /data/kingbase/v8r3_290/data/
The files belonging to this database system will be owned by user "kingbase".
This user must also own the server process.
......
syncing data to disk ... ok
Success. You can now start the database server using:
    ./sys_ctl -D /data/kingbase/v8r3_290/data/ -l logfile start

2、启动新的实例

[kingbase@node102 bin]$ ./sys_ctl -D /data/kingbase/v8r3_290/data/ start
server starting

3、测试数据库连接

[kingbase@node102 bin]$ ./ksql -U system -W 123456 test -p 54325
ksql (V008R003C002B0290)
Type "help" for help.

test=# select version();
                                                         version
-------------------------------------------------------------------------------------------------------------------------
 Kingbase V008R003C002B0290 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 64-bit
(1 row)

4、关闭数据库服务

[kingbase@node102 bin]$ ./sys_ctl stop -D /data/kingbase/v8r3_290/data/
waiting for server to shut down.... done
server stopped

二、集群迁移单实例

1、停止集群服务

[kingbase@node101 bin]$ ./kingbase_monitor.sh stop
-----------------------------------------------------------------------
2022-07-29 16:31:57 KingbaseES automation beging...
2022-07-29 16:31:57 stop kingbasecluster [192.168.1.101] ...
......
2022-07-29 16:32:26 Done...
......................
all stop..

2、备份单实例data
[kingbase@node102 v8r3_290]$ mv data data.bk

3、拷贝集群data到单实例(适合数据量小环境)

[kingbase@node102 db]$ cp -r data /data/kingbase/v8r3_290/
[kingbase@node102 v8r3_290]$ chmod 700 data

4、启动单实例数据库

[kingbase@node102 bin]$ ./sys_ctl -D /data/kingbase/v8r3_290/data/ start
server starting
[kingbase@node102 bin]$ LOG:  redirecting log output to logging collector process
HINT:  Future log output will appear in directory "sys_log".

5、连接数据库访问

[kingbase@node102 bin]$ ./ksql -U SYSTEM -W 123456 TEST -p 54325
ksql (V008R003C002B0290)
Type "help" for help.

TEST=# select version();
                                                         VERSION
-------------------------------------------------------------------------------------------------------------------------
 Kingbase V008R003C002B0290 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 64-bit
(1 row)

TEST=# \l
                               List of databases
   Name    | Owner  | Encoding |   Collate   |    Ctype    | Access privileges
-----------+--------+----------+-------------+-------------+--------------------
 PROD      | SYSTEM | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 SAMPLES   | SYSTEM | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 SECURITY  | SYSTEM | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 TEMPLATE0 | SYSTEM | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/SYSTEM         +
           |        |          |             |             | SYSTEM=CTcb/SYSTEM
 TEMPLATE1 | SYSTEM | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/SYSTEM         +
           |        |          |             |             | SYSTEM=CTcb/SYSTEM
 TEMPLATE2 | SYSTEM | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/SYSTEM        +
           |        |          |             |             | SYSTEM=CTcb/SYSTEM
 TEST      | SYSTEM | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 TEST1     | SYSTEM | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
(8 rows)

6、修改单实例kingbase.conf的data_diretory参数(适合数据量大环境)

=注意:对于数据量小的环境,可以直接拷贝集群的data到单实例下;但是对于数据量大的环境,迁移时间窗口和磁盘空间有限的情况下,可以直接修改单实例数据库的kingbase.conf文件的data_dirctory参数,将data目录指向原集群的data目录即可,无需拷贝,节省迁移时间。=

[kingbase@node102 data]$ cat kingbase.conf |grep data_directory
#data_directory = 'ConfigDir'           # use data in another directory

三、总结
对于生产环境涉及到数据库服务的停止运行,所以要考虑申请停机窗口,对于数据量小的场景,可以直接拷贝集群data到单实例即可;对于大数据量的环境,cp数据会占用大量的时间,可以考虑直接修改单实例的kingbase.conf文件的data_directory参数,提高迁移的效率。

posted @ 2022-08-06 11:33  KINGBASE研究院  阅读(109)  评论(0编辑  收藏  举报