kingbaseES V8R3 集群运维系列--数据库存储(data)路径修改案例
案例说明:
默认KingbaseES V8R3集群部署后,数据存储目录(data)在/home/kingbase下,部署时不能更改;对于生产环境,需要指定数据库存储路径时,可以在集群部署完成后,迁移data目录到其他指定的存储位置。
适用版本:
KingbaseES V8R3
集群节点信息:
test=# show pool_nodes;
node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay
---------+---------------+-------+--------+-----------+---------+------------+-------------------+-------------------
0 | 192.168.7.243 | 54321 | up | 0.500000 | standby | 0 | false | 0
1 | 192.168.7.248 | 54321 | up | 0.500000 | primary | 0 | true | 0
一、创建新的data路径(所有节点)
[kingbase@node1 ~]$ mkdir -p /data/kingbase/cluster/r3/data
[kingbase@node1 ~]$ chmod 700 /data/kingbase/cluster/r3/data
二、修改配置文件中data路径
1、修改HAmodule.conf参数(所有节点)
=== 以下两个目录中文件的都要修改===
[kingbase@node3 etc]$ pwd
/home/kingbase/cluster/kha/db/etc
[kingbase@node1 etc]$ pwd
/home/kingbase/cluster/kha/kingbasecluster/etc
****
修改前:
[kingbase@node3 etc]$ cat HAmodule.conf |grep -i data
#location of the db data directory.example:KB_DATA_PATH="./cluster/clusterName/db/data"
KB_DATA_PATH="/home/kingbase/cluster/kha/db/data"
修改后:
[kingbase@node3 etc]$ cat HAmodule.conf |grep -i kb_data
#location of the db data directory.example:KB_DATA_PATH="./cluster/clusterName/db/data"
#KB_DATA_PATH="/home/kingbase/cluster/kha/db/data"
KB_DATA_PATH="/data/kingbase/cluster/r3/data"
2、修改kingbase.conf 文件(所有节点)
=== 以下两个目录中文件的都要修改===
[kingbase@node3 etc]$ pwd
/home/kingbase/cluster/kha/db/etc
[kingbase@node3 data]$ pwd
/home/kingbase/cluster/kha/db/data
修改前:
[kingbase@node1 etc]$ cat kingbase.conf |grep -i data
# option or KBDATA environment variable, represented here as ConfigDir.
#data_directory = 'ConfigDir' # use data in another directory
......
log_directory='/home/kingbase/cluster/kha/db/data/sys_log/'
修改后:
[kingbase@node1 etc]$ cat kingbase.conf |grep -i data
# option or KBDATA environment variable, represented here as ConfigDir.
#data_directory = 'ConfigDir' # use data in another directory
......
#log_directory='/home/kingbase/cluster/kha/db/data/sys_log/'
log_directory='/data/kingbase/cluster/r3/data/sys_log/'
3、修改kingbasecluster.conf文件(所有节点)
[kingbase@node1 etc]$ pwd
/home/kingbase/cluster/kha/kingbasecluster/etc
修改前:
[kingbase@node3 etc]$ cat kingbasecluster.conf|grep -i data
backend_data_directory0='/home/kingbase/cluster/kha/db/data'
......
backend_data_directory1='/home/kingbase/cluster/kha/db/data'
修改后:
[kingbase@node3 etc]$ cat kingbasecluster.conf|grep -i data
#backend_data_directory0='/home/kingbase/cluster/kha/db/data'
backend_data_directory0='/data/kingbase/cluster/r3/data'
......
#backend_data_directory1='/home/kingbase/cluster/kha/db/data'
backend_data_directory1='/data/kingbase/cluster/r3/data'
三、拷贝本节点数据文件到新的data路径下:(所有节点)
=== 注意:拷贝前,保证主备库节点数据库都是正常关闭===
[kingbase@node3 db]$ du -sh data
621M data
[kingbase@node3 data]$ scp -r * /data/kingbase/cluster/r3/data/
[kingbase@node3 data]$ du -sh /data/kingbase/cluster/r3/data/
621M /data/kingbase/cluster/r3/data/
重新对data授权:
[kingbase@node3 bin]$ chmod 700 /data/kingbase/cluster/r3/data
四、主备流复制测试
1、主备流复制测试
启动主库数据库服务:
[kingbase@node1 bin]$ ./sys_ctl start -D /data/kingbase/cluster/r3/data
server starting
.......
[kingbase@node1 bin]$ ps -ef |grep kingbase
kingbase 5009 1 0 17:31 pts/0 00:00:00 /home/kingbase/cluster/kha/db/bin/kingbase -D /data/kingbase/cluster/r3/data
kingbase 5026 5009 0 17:31 ? 00:00:00 kingbase: logger process
kingbase 5028 5009 0 17:31 ? 00:00:00 kingbase: checkpointer process
kingbase 5029 5009 0 17:31 ? 00:00:00 kingbase: writer process
kingbase 5030 5009 0 17:31 ? 00:00:00 kingbase: wal writer process
kingbase 5031 5009 0 17:31 ? 00:00:00 kingbase: autovacuum launcher process
kingbase 5032 5009 0 17:31 ? 00:00:00 kingbase: archiver process
kingbase 5033 5009 0 17:31 ? 00:00:00 kingbase: stats collector process
kingbase 5034 5009 0 17:31 ? 00:00:00 kingbase: bgworker: syslogical supervisor
kingbase 5041 5009 0 17:31 ? 00:00:00 kingbase: wal sender process SYSTEM 192.168.7.243(60676) streaming 0/28000098
启动备库数据库服务:
[kingbase@node3 bin]$ ./sys_ctl start -D /data/kingbase/cluster/r3/data
server starting
......
[kingbase@node3 bin]$ ps -ef |grep kingbase
kingbase 11336 1 0 17:31 pts/0 00:00:00 /home/kingbase/cluster/kha/db/bin/kingbase -D /data/kingbase/cluster/r3/data
kingbase 11337 11336 0 17:31 ? 00:00:00 kingbase: logger process
kingbase 11338 11336 0 17:31 ? 00:00:00 kingbase: startup process recovering 000000020000000000000027
kingbase 11342 11336 0 17:31 ? 00:00:00 kingbase: checkpointer process
kingbase 11343 11336 0 17:31 ? 00:00:00 kingbase: writer process
kingbase 11344 11336 0 17:31 ? 00:00:00 kingbase: stats collector process
查看流复制状态:
test=# select * from sys_stat_replication;
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state | sent_location | write_location | flush_location | replay_location | sync_priority | sync_state
------+----------+---------+------------------+---------------+-----------------+-------------+-------------------------------+--------------+-----------+---------------+----------------+----------------+-----------------+---------------+------------
5041 | 10 | SYSTEM | node243 | 192.168.7.243 | | 60676 | 2021-03-01 17:31:19.905944+08 | | streaming | 0/280000D0 | 0/280000D0 | 0/280000D0 | 0/280000D0 | 0 | async
(1 row)
2、测试数据同步
主库DML操作:
test=# \c prod
You are now connected to database "prod" as user "system".
prod=# create table dept1 as select * from dept;
SELECT 2
prod=# select * from dept1;
deptno | dname | loc
--------+-------+----------
10 | CAIWU | BEIJING
20 | JISHU | SHANGHAI
(2 rows)
备库查询:
test=# \c prod
You are now connected to database "prod" as user "system".
prod=# select * from dept1;
deptno | dname | loc
--------+-------+----------
10 | CAIWU | BEIJING
20 | JISHU | SHANGHAI
(2 rows)
五、重启集群测试
1、启动集群
[kingbase@node1 bin]$ ./kingbase_monitor.sh restart
-----------------------------------------------------------------------
2021-03-01 17:35:32 KingbaseES automation beging...
......................
all started..
...
now we check again
=======================================================================
| ip | program| [status]
[ 192.168.7.243]| [kingbasecluster]| [active]
[ 192.168.7.248]| [kingbasecluster]| [active]
[ 192.168.7.243]| [kingbase]| [active]
[ 192.168.7.248]| [kingbase]| [active]
=======================================================================
2、查看流复制状态
test=# show pool_nodes;
node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay
---------+---------------+-------+--------+-----------+---------+------------+-------------------+-------------------
0 | 192.168.7.243 | 54321 | up | 0.500000 | standby | 0 | false | 0
1 | 192.168.7.248 | 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 | backend_xmin | state | sent_location | write_location | flush_location | replay_location | sync_priority | sync_state
------+----------+---------+------------------+---------------+-----------------+-------------+-------------------------------+--------------+-----------+---------------+----------------+----------------+-----------------+---------------+------------
8963 | 10 | SYSTEM | node243 | 192.168.7.243 | | 60749 | 2021-03-01 17:37:04.121560+08 | | streaming | 0/2901EDD8 | 0/2901EDD8 | 0/2901EDD8 | 0/2901EDD8 | 0 | async
(1 row)
=== 如上所示,集群数据库data路径修改成功!===
六、总结
kingbaseES V8R3集群修改data路径修改,操作比较繁琐,修改的配置文件较多,必须保证所有节点的对应配置文件都做了修改,才能保证集群正常启动和运行。
KINGBASE研究院