HAC叢集中,計劃重新初始化資料庫使用原叢集配置的操作方法

瀚高PG實驗室發表於2022-04-08

瀚高資料庫
目錄
環境
文件用途
詳細資訊

環境
系統平臺:N/A
版本:4.5
文件用途
HAC叢集環境中,因某種特殊原因需要刪除當前data目錄並重建資料庫,能夠快速搭建叢集;避免重新安裝。

詳細資訊
1、所有節點停止hghac服務,刪除原data目錄,重新在主節點initdb(原配置的HAC叢集檔案不變)

[root@db data]# systemctl stop hghac-vip[root@db data]# initdb -e sm4 -c "echo *******" -D  /db/hgdbdata/data

2、啟動節點1的HAC服務,此時叢集資訊顯示異常

[root@db data]# /opt/HighGo/tools/hghac/hghactl -c /opt/HighGo/tools/hghac/hghac.yaml list+ Cluster: ha (7072987311974756506) +-----------+| Member | Host | Role | State | TL | Lag in MB |+--------+------+------+-------+----+-----------++--------+------+------+-------+----+-----------+[root@db data]# systemctl status hghac-vip

● hghac-vip.service - hghac

  Loaded: loaded (/etc/systemd/system/hghac-vip.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2022-03-18 12:16:07 CST; 3min 7s ago
  Process: 44961 ExecStart=/opt/HighGo/tools/hghac/hghac /opt/HighGo/tools/hghac/hghac.yaml (code=exited, status=1/FAILURE)
 Main PID: 44961 (code=exited, status=1/FAILURE)Mar 18 12:16:05 db systemd[1]: Started hghac.Mar 18 12:16:07 db systemd[1]: hghac-vip.service: main process exited, code=exited, status=1/FAILURE
Mar 18 12:16:07 db systemd[1]: Unit hghac-vip.service entered failed state.Mar 18 12:16:07 db systemd[1]: hghac-vip.service failed.[root@db data]# systemctl start hghac-vip[root@db data]# systemctl status hghac-vip

● hghac-vip.service - hghac

 Loaded: loaded (/etc/systemd/system/hghac-vip.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2022-03-18 12:19:26 CST; 2min 13s ago
  Process: 45581 ExecStart=/opt/HighGo/tools/hghac/hghac /opt/HighGo/tools/hghac/hghac.yaml (code=exited, status=1/FAILURE)
 Main PID: 45581 (code=exited, status=1/FAILURE)Mar 18 12:19:24 db systemd[1]: Started hghac.Mar 18 12:19:26 db systemd[1]: hghac-vip.service: main process exited, code=exited, status=1/FAILURE
Mar 18 12:19:26 db systemd[1]: Unit hghac-vip.service entered failed state.Mar 18 12:19:26 db systemd[1]: hghac-vip.service failed.

3、HAC叢集日誌中會報錯叢集的identifier與原來不一致(因為重新建庫了):

[root@db hghalog]# pwd/db/hgdbdata/hghalog[root@db hghalog]# tail -f patroni.log 
2022-03-18 12:16:06,807 INFO: Selected new etcd server http://192.168.80.111:23792022-03-18 12:16:06,828 INFO: No PostgreSQL configuration items changed, nothing to reload.2022-03-18 12:16:06,890 CRITICAL: system ID mismatch, node hghaca belongs to a different cluster: 7072987311974756506 != 70762866990207605662022-03-18 12:19:25,967 INFO: Selected new etcd server http://192.168.80.113:23792022-03-18 12:19:25,992 INFO: No PostgreSQL configuration items changed, nothing to reload.2022-03-18 12:19:26,063 CRITICAL: system ID mismatch, node hghaca belongs to a different cluster: 7072987311974756506 != 7076286699020760566

4、各節點重啟etcd和hghac服務後,還是報錯如上。

[root@db ~]# /opt/HighGo/tools/hghac/etcd/amd64/etcdctl endpoint status --write-out=table+----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+|          ENDPOINT          |        ID        | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |+----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+| http://192.168.80.111:2379 | ddbfd190d03ca278 |  3.4.15 |   20 kB |     false |      false |       218 |    1686066 |            1686066 |        || http://192.168.80.112:2379 | 1c703f0b65f7bddb |  3.4.15 |   20 kB |     false |      false |       218 |    1686066 |            1686066 |        || http://192.168.80.113:2379 | 92255e8f5c9ebfcd |  3.4.15 |   20 kB |      true |      false |       218 |    1686066 |            1686066 |        |+----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+[root@db ~]# systemctl start hghac-vip[root@db ~]# /opt/HighGo/tools/hghac/hghactl -c /opt/HighGo/tools/hghac/hghac.yaml list+ Cluster: ha (7072987311974756506) +-----------+| Member | Host | Role | State | TL | Lag in MB |+--------+------+------+-------+----+-----------++--------+------+------+-------+----+-----------+

5、原因分析:因為etcd的庫檔案中記錄了此資訊,需重新生成etcd的相關資訊

[root@db etcd]# pwd/opt/HighGo/tools/etcd[root@db etcd]# ls
hgdw1.etcd[root@db etcd]# pwd/opt/HighGo/tools/etcd[root@db etcd]# ls
hgdw1.etcd[root@db etcd]# mv hgdw1.etcd hgdw1.etcd.bak  <--所有節點都改名此目錄或刪除此目錄[root@db etcd]# systemctl stop etcd[root@db etcd]# systemctl start etcd[root@db etcd]# pwd/opt/HighGo/tools/etcd[root@db etcd]# ll
total 0drwx------  3 root root 20 Mar 18 12:34 hgdw1.etcd
drwx------. 3 root root 20 Mar 18 12:27 hgdw1.etcd.bak  <--重啟etcd會重新生成該目錄及其下的所有檔案,[root@db etcd]# /opt/HighGo/tools/hghac/etcd/amd64/etcdctl endpoint status --write-out=table+----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+|          ENDPOINT          |        ID        | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |+----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+| http://192.168.80.111:2379 | ddbfd190d03ca278 |  3.4.15 |   20 kB |      true |      false |         2 |          8 |                  8 |        || http://192.168.80.112:2379 | 1c703f0b65f7bddb |  3.4.15 |   20 kB |     false |      false |         2 |          8 |                  8 |        || http://192.168.80.113:2379 | 92255e8f5c9ebfcd |  3.4.15 |   20 kB |     false |      false |         2 |          8 |                  8 |        |+----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+[root@db etcd]# 
[root@db etcd]# systemctl start hghac-vip   <--此時啟動HAC,叢集資訊顯示正常[root@db etcd]# /opt/HighGo/tools/hghac/hghactl -c /opt/HighGo/tools/hghac/hghac.yaml list+ Cluster: ha (7076286699020760566) ----+---------+----+-----------+-----------------+| Member | Host                | Role   | State   | TL | Lag in MB | Pending restart |+--------+---------------------+--------+---------+----+-----------+-----------------+| hghaca | 192.168.80.111:5866 | Leader | running |  2 |           | *               |+--------+---------------------+--------+---------+----+-----------+-----------------+[root@db etcd]#

啟動其他節點的HAC,結果如下:

[root@db etcd]# /opt/HighGo/tools/hghac/hghactl -c /opt/HighGo/tools/hghac/hghac.yaml list+ Cluster: ha (7076286699020760566) -----+---------+----+-----------+-----------------+| Member | Host                | Role    | State   | TL | Lag in MB | Pending restart |+--------+---------------------+---------+---------+----+-----------+-----------------+| hghaca | 192.168.80.111:5866 | Leader  | running |  2 |           | *               || hghacb | 192.168.80.112:5866 | Replica | running |  2 |         0 | *               || hghacc | 192.168.80.113:5866 | Replica | running |  2 |         0 | *               |+--------+---------------------+---------+---------+----+-----------+-----------------+


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69994931/viewspace-2886234/,如需轉載,請註明出處,否則將追究法律責任。

相關文章