1. 程式人生 > 其它 >KingbaseES R6 叢集一鍵修改叢集和資料庫引數測試案例

KingbaseES R6 叢集一鍵修改叢集和資料庫引數測試案例

案例說明:
叢集環境修改叢集或資料庫引數,需要在每個node上都要修改,在每個節點而執行修改操作,容易出現漏改或節點上引數不一致等錯誤;在KingbaseES V8R6的叢集中增加了,一鍵修改引數的新功能,可以在一個節點配置後,同時修改叢集中所有節點的引數,這樣使用者在修改叢集中的引數時,避免以上錯誤的發生。

官方文件說明:
https://help.kingbase.com.cn/stage-api/profile/document/kes/v8r6/html/highly/highly-tools/cluster-use/cluster-use-6.html#id2
6. 一鍵修改叢集引數
6.1. 命令列命令
6.1.1. sys_monitor.sh set/set --restart


sys_monitor.sh set/set --restart —一鍵修改叢集配置和資料庫配置

6.1.1.1. 描述
sys_monitor.sh set 指令碼讀取配置檔案set_repmgr.conf和set_db.conf中的配置,分別修改叢集的配置檔案repmgr.conf和es_rep.conf
6.1.1.2. 使用
在$db_etc目錄下配置set_repmgr.conf,該配置檔案中設定引數,修改叢集repmgr.conf檔案
例:

圖 6.1.20 修改叢集repmgr.conf檔案
在$db_etc目錄下配置set_db.conf,該配置檔案中設定引數,修改叢集es_rep.conf檔案
例:

圖 6.1.21 修改叢集es_rep.conf檔案
6.1.1.3. 選項
以下是指令碼執行引數:

set
指令碼呼叫修改叢集和資料庫配置函式
set --restart
指令碼呼叫修改叢集和資料庫配置函式,並重啟叢集。如果修改的引數必須重啟資料庫才能生效時,使用該項

例:

圖 6.1.22 一鍵修改叢集配置和資料庫配置
例:

圖 6.1.23 一鍵修改叢集配置和資料庫配置
6.1.1.4. 注意事項

1.必須在叢集所有節點狀態正常的情況下才能執行修改引數操作
2.set_db.conf中
不可以配置port引數
不可以配置kingbase.conf中沒有的引數
不可以給引數配置錯誤的值
3.set_repmgr.conf中
不建議修改路徑相關和資料庫連線串等引數,以下是適合一鍵修改的引數 例如:
reconnect_attempts
reconnect_interval
recovery
trust_servers

測試案例:

測試資料庫版本:

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

叢集node資訊:

[kingbase@node102 bin]$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.1.101   node101     ###  Standby
192.168.1.102   node102     ###  Primary


 ID | Name    | Role    | Status    | Upstream | repmgrd | PID   | Paused? | Upstream last seen
----+---------+---------+-----------+----------+---------+-------+---------+--------------------
 1  | node101 | standby |   running | node102  | running | 15547 | no      | 1 second(s) ago
 2  | node102 | primary | * running |          | running | 16388 | no      | n/a

一、檢視叢集節點狀態

=注意:在修改引數前,必須保證叢集中所有節點是正常狀態。=

[kingbase@node101 bin]$ ./repmgr cluster show
 ID | Name    | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string                                     
----+---------+---------+-----------+----------+----------+----------+----------+----------------------------------------------------------------------------------------------------------------------------------------------------
 1  | node101 | standby |   running | node102  | default  | 100      | 2        | host=192.168.1.101 user=system dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
 2  | node102 | primary | * running |          | default  | 100      | 2        | host=192.168.1.102 user=system dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3

二、修改引數測試

=在主節點的etc目錄下,分別配置set_repmgr.conf和set_db.conf,將需要修改的repmgr和資料庫引數及value寫入到此配置檔案中。=

1、檢視需要修改的repmgr引數

[kingbase@node101 data]$ cat ../etc/repmgr.conf |grep -i recovery
#recovery='standby'
recovery='automatic'

[kingbase@node102 etc]$ cat repmgr.conf |grep recovery
#recovery='standby'
recovery='automatic'

2、配置repmgr引數檔案(將需要修改的引數寫入此配置檔案,注意檔名)

[kingbase@node102 etc]$ cat set_repmgr.conf
recovery=standby

3、檢視需要修改的資料庫引數

[kingbase@node101 data]$ cat kingbase.conf |grep work_mem
#work_mem = 4MB                         # min 64kB
#maintenance_work_mem = 64MB            # min 1MB
#autovacuum_work_mem = -1               # min 1MB, or -1 to use maintenance_work_mem

[kingbase@node102 bin]$ cat ../data/kingbase.conf |grep -i work_mem
#work_mem = 4MB                         # min 64kB
#maintenance_work_mem = 64MB            # min 1MB

4、配置資料庫引數檔案(將需要修改的引數寫入此配置檔案,注意檔名)

[kingbase@node102 etc]$ cat set_db.conf
work_mem = 16MB

5、一鍵修改引數
=注意:如果修改的引數不需要重啟就生效,可以用set引數;如果引數修改需要重啟叢集或資料庫才能生效,需要用set --restart引數。=

[kingbase@node102 bin]$ ./sys_monitor.sh set
2022-04-06 11:58:29 Begin to set the es_rep.conf for database ...
2022-04-06 11:58:30 End to set the es_rep.conf for database ... OK
2022-04-06 11:58:30 Begin to set the repmgr.conf for repmgrd ...
2022-04-06 11:58:31 End to set the repmgr.conf for repmgrd ... OK
2022-04-06 11:58:31 Sending signal to reload the database on "192.168.1.102"
server signaled
2022-04-06 11:58:31 Sending signal to reload the database on "192.168.1.101"
server signaled
2022-04-06 11:58:32 Sending signal(SIGKILL) to stop the kbha on "192.168.1.102"
2022-04-06 11:58:34 Sending signal(SIGKILL) to stop the repmgrd on "192.168.1.102"
2022-04-06 11:58:34 begin to stop repmgrd on "[192.168.1.102]".
2022-04-06 11:58:35 repmgrd on "[192.168.1.102]" stop success.
2022-04-06 11:58:36 Start the repmgrd on "192.168.1.102"
2022-04-06 11:58:36 begin to start repmgrd on "[192.168.1.102]".
[2022-04-06 11:58:36] [NOTICE] using provided configuration file "/home/kingbase/cluster/R6HA/kha/kingbase/bin/../etc/repmgr.conf"
[2022-04-06 11:58:36] [NOTICE] redirecting logging output to "/home/kingbase/cluster/R6HA/kha/kingbase/log/hamgr.log"

2022-04-06 11:58:38 repmgrd on "[192.168.1.102]" start success.
2022-04-06 11:58:38 Start the kbha on "192.168.1.102"
[2022-04-06 11:58:41] [NOTICE] redirecting logging output to "/home/kingbase/cluster/R6HA/kha/kingbase/log/kbha.log"

2022-04-06 11:58:42 Sending signal(SIGKILL) to stop the kbha on "192.168.1.101"
2022-04-06 11:58:45 Sending signal(SIGKILL) to stop the repmgrd on "192.168.1.101"
2022-04-06 11:58:45 begin to stop repmgrd on "[192.168.1.101]".
2022-04-06 11:58:46 repmgrd on "[192.168.1.101]" stop success.
2022-04-06 11:58:46 Start the repmgrd on "192.168.1.101"
2022-04-06 11:58:46 begin to start repmgrd on "[192.168.1.101]".
[2022-04-06 11:58:47] [NOTICE] using provided configuration file "/home/kingbase/cluster/R6HA/kha/kingbase/bin/../etc/repmgr.conf"
[2022-04-06 11:58:47] [NOTICE] redirecting logging output to "/home/kingbase/cluster/R6HA/kha/kingbase/log/hamgr.log"

2022-04-06 11:58:48 repmgrd on "[192.168.1.101]" start success.
2022-04-06 11:58:48 Start the kbha on "192.168.1.101"
[2022-04-06 11:58:51] [NOTICE] redirecting logging output to "/home/kingbase/cluster/R6HA/kha/kingbase/log/kbha.log"

Some changes may not take effect by RELOAD, you can execute "./sys_monitor.sh restart" to restart the cluster

三、驗證引數的修改

1、檢視修改後的repmgr引數

如下所示:被修改的repmgr引數將追加到repmgr.conf檔案的之後

[kingbase@node102 bin]$ cat ../etc/repmgr.conf |grep -i recovery
#recovery='standby'
recovery='automatic'
auto_cluster_recovery_level=1
recovery=standby          ### 修改引數

2、檢視資料庫引數的修改

如下所示:被修改的資料庫引數將追加到es_rep.conf檔案的之後

[kingbase@node102 bin]$ cat ../data/es_rep.conf |grep -i work_mem
work_mem = 16MB
You have new mail in /var/spool/mail/kingbase

#資料庫環境檢視:
[kingbase@node102 bin]$ ./ksql -U system test
ksql (V8.0)
Type "help" for help.

test=# show work_mem;
 work_mem
----------
 16MB
(1 row)

四、驗證重啟叢集引數的修改

=注意:在叢集或資料庫中有些引數的修改,需要重啟叢集或資料庫服務才能生效,建議此類引數的修改,在業務低峰期間執行,防止生產環境中,業務訪問受到影響。=

[kingbase@node102 bin]$ ./sys_monitor.sh set --restart
2022-04-06 12:00:23 Begin to set the es_rep.conf for database ...
2022-04-06 12:00:24 End to set the es_rep.conf for database ... OK
2022-04-06 12:00:24 Begin to set the repmgr.conf for repmgrd ...
2022-04-06 12:00:25 End to set the repmgr.conf for repmgrd ... OK
2022-04-06 12:00:25 Ready to stop all DB ...
Service process "node_export" was killed at process 8009
Service process "postgres_ex" was killed at process 8010
Service process "node_export" was killed at process 8135
Service process "postgres_ex" was killed at process 8136
2022-04-06 12:00:32 begin to stop repmgrd on "[192.168.1.102]".
2022-04-06 12:00:33 repmgrd on "[192.168.1.102]" stop success.
2022-04-06 12:00:33 begin to stop repmgrd on "[192.168.1.101]".
2022-04-06 12:00:34 repmgrd on "[192.168.1.101]" stop success.
2022-04-06 12:00:34 begin to stop DB on "[192.168.1.101]".
waiting for server to shut down.... done
server stopped
2022-04-06 12:00:34 DB on "[192.168.1.101]" stop success.
2022-04-06 12:00:34 begin to stop DB on "[192.168.1.102]".
waiting for server to shut down.... done
server stopped
2022-04-06 12:00:35 DB on "[192.168.1.102]" stop success.
2022-04-06 12:00:35 Done.
2022-04-06 12:00:35 Ready to start all DB ...
2022-04-06 12:00:35 begin to start DB on "[192.168.1.102]".
waiting for server to start.... done
server started
2022-04-06 12:00:36 execute to start DB on "[192.168.1.102]" success, connect to check it.
2022-04-06 12:00:37 DB on "[192.168.1.102]" start success.
2022-04-06 12:00:37 Try to ping trusted_servers on host 192.168.1.102 ...
2022-04-06 12:00:40 Try to ping trusted_servers on host 192.168.1.101 ...
2022-04-06 12:00:42 begin to start DB on "[192.168.1.101]".
waiting for server to start.... done
server started
2022-04-06 12:00:43 execute to start DB on "[192.168.1.101]" success, connect to check it.
2022-04-06 12:00:44 DB on "[192.168.1.101]" start success.
 ID | Name    | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string                                     
----+---------+---------+-----------+----------+----------+----------+----------+----------------------------------------------------------------------------------------------------------------------------------------------------
 1  | node101 | standby |   running | node102  | default  | 100      | 2        | host=192.168.1.101 user=system dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
 2  | node102 | primary | * running |          | default  | 100      | 2        | host=192.168.1.102 user=system dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
2022-04-06 12:00:44 The primary DB is started.
2022-04-06 12:00:44 begin to start repmgrd on "[192.168.1.102]".
[2022-04-06 12:00:45] [NOTICE] using provided configuration file "/home/kingbase/cluster/R6HA/kha/kingbase/bin/../etc/repmgr.conf"
[2022-04-06 12:00:45] [NOTICE] redirecting logging output to "/home/kingbase/cluster/R6HA/kha/kingbase/log/hamgr.log"

2022-04-06 12:00:47 repmgrd on "[192.168.1.102]" start success.
2022-04-06 12:00:47 begin to start repmgrd on "[192.168.1.101]".
[2022-04-06 12:00:49] [NOTICE] using provided configuration file "/home/kingbase/cluster/R6HA/kha/kingbase/bin/../etc/repmgr.conf"
[2022-04-06 12:00:49] [NOTICE] redirecting logging output to "/home/kingbase/cluster/R6HA/kha/kingbase/log/hamgr.log"

2022-04-06 12:00:50 repmgrd on "[192.168.1.101]" start success.
 ID | Name    | Role    | Status    | Upstream | repmgrd | PID   | Paused? | Upstream last seen
----+---------+---------+-----------+----------+---------+-------+---------+--------------------
 1  | node101 | standby |   running | node102  | running | 15547 | no      | 1 second(s) ago
 2  | node102 | primary | * running |          | running | 16388 | no      | n/a
[2022-04-06 12:00:53] [NOTICE] redirecting logging output to "/home/kingbase/cluster/R6HA/kha/kingbase/log/kbha.log"

[2022-04-06 12:00:57] [NOTICE] redirecting logging output to "/home/kingbase/cluster/R6HA/kha/kingbase/log/kbha.log"

2022-04-06 12:00:58 Done.

五、引數修改故障案例

=在修改引數時,如果只是配置了set_repmgr.conf檔案,缺少set_db.conf檔案,則執行一鍵修改時出現以下錯誤,需要同時建立以上兩個檔案。=

[kingbase@node102 bin]$ ./sys_monitor.sh set
2022-04-06 11:51:18 WRNING: there is no file "/home/kingbase/cluster/R6HA/kha/kingbase/bin/../etc//set_db.conf", don't change the es_rep.conf for database
2022-04-06 11:51:18 WRNING: there is no file "/home/kingbase/cluster/R6HA/kha/kingbase/bin/../etc//set_repmgr.conf", don't change the repmgr.conf for repmgrd
2022-04-06 11:51:18 ERROR: the file "/home/kingbase/cluster/R6HA/kha/kingbase/bin/../etc//set_db.conf" and "/home/kingbase/cluster/R6HA/kha/kingbase/bin/../etc//set_repmgr.conf" do not exist, exit

六、總結
對於KingbaseES V8R6叢集一鍵修改引數的功能,方便了叢集的維護和管理,但注意,並不是所有引數都能修改,具體可以參考官方文件說明。