案例说明:
KingbaseES V8R6集群,通过‘cluster’模式执行远程异地的外部备份,在备份初始化时,故障显示,远程节点连接数据库失败,异常终止。原因是,数据库节点不支持本地数据库访问导致。
适用版本:
KingbaseES V8R6
集群架构:
一、问题现象
如下所示,在执行sys_backup.sh init后,提示远程备份服务器无法访问数据库节点:
二、问题分析
1、在备份服务器ksql连接测试
如下所示,远程备份服务器可以远程访问数据集群节点数据库服务:
2、执行以下语句测试到数据库的连接
/home/kingbase/cluster/v9/kingbase/bin/sys_securecmd -q -o ConnectTimeout=10 -o StrictHostKeyChecking=no -p 8890 -o ServerAliveInterval=2 -o ServerAliveCountMax=3 kingbase@主库ip 'ksql -U system test -c "select version();"'
经测试,当通过securecmdd远程连接到数据库服务器本机时,执行ksql本地连接失败,只能通过远程“-h”网络远程连接数据库:
三、测试模拟分析
1、如下所示备份配置
2、通过sys_hba.conf禁止数据库本地访问
如下所示,禁止数据库本地连接访问:
# TYPE DATABASE USER ADDRESS METHOD# "local" 只能用于UNIX域套接字
# local all all scram-sha-256
3、测试数据库连接
如下所示,远程节点通过在通过securecmdd远程连接到数据库节点后,不支持ksql本地访问:
# ksql -h远程访问
[kingbase@node202 bin]$ ./sys_securecmd kingbase@192.168.1.208 "/home/kingbase/cluster/v9/kingbase/bin/ksql -U system test -p 54325 -h 192.168.1.208 -c 'select version();'"version
----------------------------------------------------------------------------------------------------------------------KingbaseES V009R001C002B0014 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28), 64-bit
(1 row)# ksql本地访问
[kingbase@node202 bin]$ ./sys_securecmd kingbase@192.168.1.208 "/home/kingbase/cluster/v9/kingbase/bin/ksql -U system test -p 54325 -c 'select version();'"
ksql: error: could not connect to server: FATAL: no sys_hba.conf entry for host "[local]", user "system", database "test", SSL off
4、测试备份初始化
如下所示,执行备份初始化异常:
[kingbase@node202 bin]$ ./sys_backup.sh init
# pre-condition: check the non-archived WAL files
# Check 192.168.1.208 archive-mode == always
# Check 192.168.1.209 archive-mode == always
# generate local sys_rman.conf...DONE
# update all node: sys_rman.conf and archive_command with sys_rman.archive-push...
# update all node: sys_rman.conf and archive_command with sys_rman.archive-push...DONE
# create stanza and check...(maybe 60+ seconds)
ERROR: create stanza failed, check log file /home/kingbase/cluster/v9/kingbase/log/sys_rman_stanza-create.log
[kingbase@node202 bin]$ cat /home/kingbase/cluster/v9/kingbase/log/sys_rman_stanza-create.log
2024-11-18 18:57:16.448 P00 INFO: stanza-create command begin 2.27: --band-width=0 --cmd-ssh=/home/kingbase/cluster/v9/kingbase/bin/sys_securecmd --config=/home/kingbase/kbbr_repo/sys_rman.conf --exec-id=10743-bd491a36 --kb1-host=192.168.1.208 --kb1-host-user=kingbase --kb1-path=/home/kingbase/cluster/v9/kingbase/data --kb1-port=54325 --kb1-user=system --log-level-console=info --log-level-file=info --log-path=/home/kingbase/cluster/v9/kingbase/log --log-subprocess --process-max=4 --repo1-path=/home/kingbase/kbbr_repo --stanza=kingbase
WARN: set process-max 4 is too large, auto set to CPU core count 1
2024-11-18 18:57:17.037 P00 INFO: stanza-create for stanza 'kingbase' on repo1
2024-11-18 18:57:17.397 P00 INFO: stanza-create command end: completed successfully (953ms)
2024-11-25 14:31:47.789 P00 INFO: stanza-create command begin 2.27: --backup-from=cluster --band-width=0 --cmd-ssh=/home/kingbase/cluster/v9/kingbase/bin/sys_securecmd --config=/home/kingbase/kbbr_repo/sys_rman.conf --exec-id=9257-11e09c11 --kb1-host=192.168.1.208 --kb2-host=192.168.1.209 --kb1-host-user=kingbase --kb2-host-user=kingbase --kb1-path=/home/kingbase/cluster/v9/kingbase/data --kb2-path=/home/kingbase/cluster/v9/kingbase/data --kb1-port=54325 --kb2-port=54325 --kb1-user=esrep --kb2-user=esrep --log-level-console=info --log-level-file=info --log-path=/home/kingbase/cluster/v9/kingbase/log --log-subprocess --process-max=4 --repo1-path=/home/kingbase/kbbr_repo --stanza=kingbase
WARN: set process-max 4 is too large, auto set to CPU core count 1
WARN: unable to check kb-1: [db_connect_err] raised from remote-0 ssh protocol on '192.168.1.208': unable to connect to 'application_name=internal_rman dbname='kingbase' port=54325 user='esrep'': FATAL: no sys_hba.conf entry for host "[local]", user "esrep", database "kingbase", SSL off
WARN: unable to check kb-2: [db_connect_err] raised from remote-0 ssh protocol on '192.168.1.209': unable to connect to 'application_name=internal_rman dbname='kingbase' port=54325 user='esrep'': FATAL: no sys_hba.conf entry for host "[local]", user "esrep", database "kingbase", SSL off
ERROR: [056]: unable to find primary cluster - cannot proceed
2024-11-25 14:31:48.906 P00 INFO: stanza-create command end: aborted with exception [056]
如下所示,备份服务器securecmdd远程连接主库后,sys_rman无法访问数据库服务:
四、问题解决
在解决数据库可以本地访问后,远程服务器备份正常。
五、总结
在远程外地备份模式中,远程服务器通过ssh或securecmdd连接到数据库服务器后,sys_rman需要在 数据库节点本地可以访问数据库服务,如果不支持,sys_rman备份将异常。