一. 實驗環境
本次實驗環境是通過mac電腦上的vmware軟件部署的兩套centos 8(arm)操作系統,具體信息如下:
| 角色 | IP | 主機名 | 操作系統信息 | PTK版本 |
|---|---|---|---|---|
| 主 | 172.16.117.128 | mogdbA | Linux mogdbA 5.11.12-300.el8.aarch64 #1 SMP Fri Jul 30 12:03:15 CST 2021 aarch64 aarch64 aarch64 GNU/Linux | v0.3.8 |
| 備 | 172.16.117.129 | mogdbB | Linux mogdbA1 5.11.12-300.el8.aarch64 #1 SMP Fri Jul 30 12:03:15 CST 2021 aarch64 aarch64 aarch64 GNU/Linux | v0.3.8 |
- PTK工具下載鏈接:https://docs.mogdb.io/zh/ptk/v0.2/release
- PTK工具支持在線安裝,安裝指令如下
curl --proto '=https' --tlsv1.2 -sSf https://cdn-mogdb.enmotech.com/ptk/install.sh | sh
二. 操作系統安裝前準備
在安裝部署mogdb前,需要對兩套操作系統進行配置
2.1 關閉操作系統防火墻
- 修改/etc/selinux/config文件中的“SELINUX”值為“disabled”。
vim /etc/selinux/config
修改“SELINUX”的值“disabled”,執行:wq保存并退出修改。
SELINUX=disabled
- 使用systemctl命令停止防火墻并禁止開機自啟
#查看firewalld狀態
[root@mogdbA ~]# systemctl status firewalld
#停止firewalld服務
[root@mogdbA ~]# systemctl stop firewalld
#關閉firewalld服務開機自啟
[root@mogdbA ~]# systemctl disable firewalld
若防火墻狀態顯示為active (running),則表示防火墻未關閉.
若防火墻狀態顯示為inactive (dead), 則表示防火墻已關閉
2.2 各個節點設置為相同字符集
查看各節點的字符集:
[root@mogdbA ~]# echo $LANG
zh_CN.UTF-8
[root@mogdbA1 ~]# echo $LANG
zh_CN.UTF-8
2.3 設置時區和時間
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
2.4 關閉swap交換內存
swapoff -a
2.5 設置各節點網卡MTU值相同
- 使用
ifconfig命令查看網卡信息。 - 修改網卡MTU
ifconfig 網卡編號 mtu value
三. PTK工具
3.1 PTK工具介紹
PTK (Provisioning Toolkit)是一款針對 MogDB 數據庫開發的軟件安裝和運維工具,旨在幫助用戶更便捷地安裝部署MogDB數據庫。
3.2 在線安裝PTK
[root@mogdbA hugepages]# curl --proto '=https' --tlsv1.2 -sSf https://cdn-mogdb.enmotech.com/ptk/install.sh | sh
Downloading ptk package...
Detected shell: bash
Shell profile: /root/.bash_profile
ptk has been added to PATH in /root/.bash_profile
open a new terminal or source /root/.bash_profile to active it
Installed path: /root/.ptk/bin/ptk
安裝好后,執行一下命令使環境變量生效
source /root/.bash_profile
3.3 查看當前版本
[root@mogdbA hugepages]# ptk -v
PTK Version: v0.3.8
Go Version: go1.17.1
Build Date: 2022-08-31T14:12:21Z
Git Hash: b3fa51b
3.4 PTK CANDIDATE
該命令有兩個子命令:
- ptk candidate db - 列出支持安裝的 MogDB 數據庫版本列表
[root@mogdbA hugepages]# ptk candidate db
software | version
-----------+----------
MogDB | 3.0.1
| 3.0.0
| 2.1.1
| 2.0.3
| 2.0.1
| 2.0.0
本次安裝選擇3.0.1版本
- ptk candidate os - 列出支持安裝 MogDB 的操作系統
[root@mogdbA hugepages]# ptk candidate os
id | os | tested version(s)
-----+-------------------------------------+----------------------------
1 | CentOS 7 (x86_64) | 7.6.1810 (Core)
2 | openEuler 20 (x86_64) | 20.03 LTS
3 | openEuler 20 (arm64) | 20.03 LTS
4 | openEuler 22 (x86_64) | 22.03 LTS
5 | openEuler 22 (arm64) | 22.03 LTS
6 | Kylin V10 (x86_64) | V10 (Tercel)
7 | Kylin V10 (arm64) | V10 (Tercel)
8 | UOS 20 A (x86_64) | 1002a/1020a/1050a
9 | UOS 20 A (arm64) | 1050a (kongzi)
10 | Ubuntu 20 (x86_64) | 20.04.3 LTS (Focal Fossa)
11 | CentOS 8 (arm64) | 8.0.1905 (Core)
12 | CentOS 8 (x86_64) | 8.0.1905 (Core)
13 | Red Hat Enterprise Linux 7 (x86_64) | 7.5 (Maipo)
14 | Red Hat Enterprise Linux 8 (x86_64) | 8.5 (Ootpa)
15 | EulerOS 2 (x86_64) | 2.0 (SP3)
16 | EulerOS 2 (arm64) | 2.0 (SP3)
18 | SLES 12SP5 (x86_64) | 12SP5
19 | Oracle Linux 7 (x86_64) | 7.9 (Maipo)
20 | Oracle Linux 8 (x86_64) | 8.6 (Ootpa)
21 | Rocky Linux 8 (x86_64) | 8.5 (Green Obsidian)
22 | NeoKylin V7 (x86_64) | V7Update6
23 | UOS 20 D/E (x86_64) | 1040d (fou)
24 | UOS 20 D/E (arm64) | 1040d (fou)
25 | Ubuntu 22 (x86_64) | 22.04 (Jammy Jellyfish)
第11行CentOS 8 (arm64)是支持安裝的。
四. 安裝數據庫
4.1 準備拓補配置文件
PTK安裝需要提供配置文件config.yaml,PTK支持單節點安裝以及多節點安裝。此次實驗以一主一備節點安裝為例。
[root@mogdbA ~]# vi config.yaml
在文件中添加一下信息
# config.yaml
global:
cluster_name: mogdb_cluster1
user: omm
group: omm
base_dir: /opt/mogdb
db_servers:
- host: 172.16.117.128
db_port: 26000
role: primary
ssh_option:
port: 22
user: root
password:Enmo@123
- host: 172.16.117.129
db_port: 26000
role: standby
ssh_option:
port: 22
user: root
password:Enmo@123
4.2 檢查本機系統
ptk checkos -f config.yaml
確保輸出的檢查結果均為 OK 或者 Warning ,如果有 Abnormal 或 ExecuteError出現,需用戶根據日志提示先修正系統參數.
- 出現報錯
[root@mogdbA ~]# ptk checkos -f config.yaml
[PTK-4036] password field [172.16.117.128.ssh_optino.password] must be encrypted with ptk, raw password in config is not allowed
Please type "ptk encrypt -h" for more help
解決方法:使用ptk encrypt Enmo@123加密密碼,將獲得的文本替換config.yaml中的password
[root@mogdbA ~]# ptk encrypt Enmo@123
Enmo@123: pTk6MGZlYjk4OWQ8RTxDPj4/QXBDSDFsT0VCRDBWUEhtSVNtTlQyRFVUd3ZMNDRRTkZ4aVV0cXgzUmNRSlk=
- 再次執行checkos,輸出列表:
# Check Results
Item | Level
------------------------------------+---------------
A1.Check_OS_Version | OK
A2.Check_Kernel_Version | OK
A3.Check_Unicode | OK
A4.Check_TimeZone | OK
A5.Check_Swap_Memory_Configure | OK
A6.Check_SysCtl_Parameter | Warning
A7.Check_FileSystem_Configure | OK
A8.Check_Disk_Configure | OK
A9.Check_BlockDev_Configure | Warning
A9.Check_Logical_Block | OK
A10.Check_IO_Configure | Warning
A10.Check_IO_Request | Warning
A10.Check_Asynchronous_IO_Request | OK
A11.Check_Network_Configure | OK
A12.Check_Time_Consistency | OK
A13.Check_Firewall_Service | OK
A14.Check_THP_Service | ExecuteError
A15.Check_Dependent_Package | Abnormal
A16.Check_CPU_Instruction_Set | Abnormal
A17.Check_Port | OK
Total count 20, abnormal count 3, warning count 4
A14的問題是無法找到透明大頁的文件,可以忽略
A15的問題是依賴包問題,使用yum install可以下載缺少的依賴包即可
A6的問題是找不到bmi2指令集,不影響測試,可以忽略
4.2 執行安裝
[root@mogdbA ~]# ptk install -f config.yaml --skip-check-os
INFO[2022-09-07T22:58:01.756] 未指定安裝包路徑,默認使用在線包: https://cdn-mogdb.enmotech.com/mogdb-media/3.0.1/MogDB-3.0.1-openEuler-arm64.tar.gz
INFO[2022-09-07T22:58:01.756] skip check operating system
=============================
global:
cluster_name: mogdb_cluster1
user: omm
group: omm
app_dir: /opt/mogdb/app
data_dir: /opt/mogdb/data
log_dir: /opt/mogdb/log
tool_dir: /opt/mogdb/tool
tmp_dir: /opt/mogdb/tmp
db_servers:
- host: 172.16.117.128
db_port: 26000
role: primary
az_name: AZ1
az_priority: 1
- host: 172.16.117.129
db_port: 26000
role: standby
az_name: AZ1
az_priority: 1
=============================
請確認集群拓撲配置是否正確?[Y|Yes](default=N) y
INFO[2022-09-07T22:58:18.625] 正在下載安裝包...
> download MogDB-3.0.1-openEu...: 71.60 MiB / 128.22 MiB [----------------------------------------->________________________________] 55.84% 7.15 MiB p/s ETA 7s
–skip-check-os參數是指跳過檢查系統環境,因為之前忽略了兩個報錯,所以要跳過這一步檢查
-沒有指定安裝包,ptk會自己選擇合適的安裝包進行下載
4.3 安裝回顯
INFO[2022-09-07T22:58:37.762] 安裝包下載成功
INFO[2022-09-07T22:58:38.733] validation: installation package is safe
INFO[2022-09-07T22:58:38.733] parse version.cfg from MogDB-3.0.1-openEuler-64bit.tar.gz
INFO[2022-09-07T22:58:40.507] detected db version: MogDB-3.0.1, number: 92.605, commit_id: 1a363ea9
INFO[2022-09-07T22:58:40.510] [stage=precheck]: start host=172.16.117.129
INFO[2022-09-07T22:58:40.510] check user 'omm' host=172.16.117.129
INFO[2022-09-07T22:58:40.510] [stage=precheck]: start host=172.16.117.128
INFO[2022-09-07T22:58:40.510] check user 'omm' host=172.16.117.128
INFO[2022-09-07T22:58:40.516] [stage=precheck]: successful host=172.16.117.128
INFO[2022-09-07T22:58:40.533] [stage=precheck]: successful host=172.16.117.129
請輸入數據庫初始密碼(需8到16位)
請再次輸入數據庫初始密碼:
INFO[2022-09-07T22:59:55.847] scp file from /root/.ptk/cache/MogDB-3.0.1-openEuler-arm64.tar.gz to 172.16.117.129:/tmp/MogDB-3.0.1-openEuler-arm64.tar.gz host=172.16.117.129
INFO[2022-09-07T22:59:55.848] scp file from /root/.ptk/cache/MogDB-3.0.1-openEuler-arm64.tar.gz to 172.16.117.128:/tmp/MogDB-3.0.1-openEuler-arm64.tar.gz host=172.16.117.128
> upload MogDB-3.0.1-openEule...: 128.22 MiB / 128.22 MiB [-------------------------------------------------------------------------] 100.00% 13.55 MiB p/s 9.7s
INFO[2022-09-07T23:00:05.571] [stage=initial]: start host=172.16.117.129
INFO[2022-09-07T23:00:05.571] [stage=initial]: start host=172.16.117.128
INFO[2022-09-07T23:00:05.577] total memory(3GB) is less then 4GB, use default guc config host=172.16.117.128
INFO[2022-09-07T23:00:05.577] create os user omm, group omm host=172.16.117.128
INFO[2022-09-07T23:00:05.603] total memory(3GB) is less then 4GB, use default guc config host=172.16.117.129
INFO[2022-09-07T23:00:05.603] create os user omm, group omm host=172.16.117.129
INFO[2022-09-07T23:00:06.047] set ulimits host=172.16.117.128
INFO[2022-09-07T23:00:06.049] set user omm profiles host=172.16.117.128
INFO[2022-09-07T23:00:06.085] add c library /usr/local/lib to /etc/ld.so.conf.d/libc.conf host=172.16.117.128
INFO[2022-09-07T23:00:06.088] mkdir /opt/mogdb/tool host=172.16.117.128
INFO[2022-09-07T23:00:06.104] set ulimits host=172.16.117.129
INFO[2022-09-07T23:00:06.129] set user omm profiles host=172.16.117.129
INFO[2022-09-07T23:00:06.131] decompress MogDB-3.0.1-openEuler-arm64.tar.gz to dir /opt/mogdb/tool host=172.16.117.128
INFO[2022-09-07T23:00:06.204] add c library /usr/local/lib to /etc/ld.so.conf.d/libc.conf host=172.16.117.129
INFO[2022-09-07T23:00:06.226] mkdir /opt/mogdb/tool host=172.16.117.129
INFO[2022-09-07T23:00:06.319] decompress MogDB-3.0.1-openEuler-arm64.tar.gz to dir /opt/mogdb/tool host=172.16.117.129
INFO[2022-09-07T23:00:07.016] remove files /tmp/MogDB-3.0.1-openEuler-arm64.tar.gz host=172.16.117.128
INFO[2022-09-07T23:00:07.024] decompress *-om.tar.gz to dir /opt/mogdb/tool host=172.16.117.128
INFO[2022-09-07T23:00:07.171] remove files /tmp/MogDB-3.0.1-openEuler-arm64.tar.gz host=172.16.117.129
INFO[2022-09-07T23:00:07.198] decompress *-om.tar.gz to dir /opt/mogdb/tool host=172.16.117.129
INFO[2022-09-07T23:00:07.326] fix psutil lib host=172.16.117.128
INFO[2022-09-07T23:00:07.336] change /opt/mogdb/tool owner to omm host=172.16.117.128
INFO[2022-09-07T23:00:07.340] mkdir /opt/mogdb/app host=172.16.117.128
INFO[2022-09-07T23:00:07.396] decompress MogDB-3.0.1-openEuler-64bit.tar.gz to dir /opt/mogdb/app host=172.16.117.128
INFO[2022-09-07T23:00:07.519] fix psutil lib host=172.16.117.129
INFO[2022-09-07T23:00:07.594] change /opt/mogdb/tool owner to omm host=172.16.117.129
INFO[2022-09-07T23:00:07.617] mkdir /opt/mogdb/app host=172.16.117.129
INFO[2022-09-07T23:00:07.724] decompress MogDB-3.0.1-openEuler-64bit.tar.gz to dir /opt/mogdb/app host=172.16.117.129
INFO[2022-09-07T23:00:09.473] fix dynamic library for gs_initdb host=172.16.117.128
INFO[2022-09-07T23:00:09.511] fix dynamic library for mogdb host=172.16.117.128
INFO[2022-09-07T23:00:09.547] change /opt/mogdb/app owner to omm host=172.16.117.128
INFO[2022-09-07T23:00:09.553] mkdir /opt/mogdb/log/gs_profile,/opt/mogdb/log/pg_log,/opt/mogdb/log/pg_audit,/opt/mogdb/log/bin,/opt/mogdb/log/pg_log/dn_6001,/opt/mogdb/log/pg_audit/dn_6001,/opt/mogdb/log/pg_log/dn_6002,/opt/mogdb/log/pg_audit/dn_6002 host=172.16.117.128
INFO[2022-09-07T23:00:09.887] fix dynamic library for gs_initdb host=172.16.117.129
INFO[2022-09-07T23:00:09.961] fix dynamic library for mogdb host=172.16.117.129
INFO[2022-09-07T23:00:10.034] change /opt/mogdb/app owner to omm host=172.16.117.129
INFO[2022-09-07T23:00:10.056] mkdir /opt/mogdb/log/gs_profile,/opt/mogdb/log/pg_log,/opt/mogdb/log/pg_audit,/opt/mogdb/log/bin,/opt/mogdb/log/pg_log/dn_6001,/opt/mogdb/log/pg_audit/dn_6001,/opt/mogdb/log/pg_log/dn_6002,/opt/mogdb/log/pg_audit/dn_6002 host=172.16.117.129
INFO[2022-09-07T23:00:10.311] mkdir /opt/mogdb/tmp host=172.16.117.128
INFO[2022-09-07T23:00:10.366] save version to /opt/mogdb/app/bin/upgrade_version host=172.16.117.128
INFO[2022-09-07T23:00:10.396] create cluster_manual_start file host=172.16.117.128
INFO[2022-09-07T23:00:10.424] generate static config to /opt/mogdb/app/bin/cluster_static_config host=172.16.117.128
INFO[2022-09-07T23:00:10.429] change /opt/mogdb/app/bin/cluster_static_config owner to omm host=172.16.117.128
INFO[2022-09-07T23:00:10.431] mkdir /opt/mogdb/data host=172.16.117.128
INFO[2022-09-07T23:00:10.488] change /opt/mogdb/data owner to omm host=172.16.117.128
INFO[2022-09-07T23:00:10.490] initial database host=172.16.117.128
INFO[2022-09-07T23:00:11.496] mkdir /opt/mogdb/tmp host=172.16.117.129
INFO[2022-09-07T23:00:11.611] save version to /opt/mogdb/app/bin/upgrade_version host=172.16.117.129
INFO[2022-09-07T23:00:11.720] create cluster_manual_start file host=172.16.117.129
INFO[2022-09-07T23:00:11.765] generate static config to /opt/mogdb/app/bin/cluster_static_config host=172.16.117.129
INFO[2022-09-07T23:00:11.865] change /opt/mogdb/app/bin/cluster_static_config owner to omm host=172.16.117.129
INFO[2022-09-07T23:00:11.885] mkdir /opt/mogdb/data host=172.16.117.129
INFO[2022-09-07T23:00:12.047] change /opt/mogdb/data owner to omm host=172.16.117.129
INFO[2022-09-07T23:00:12.066] initial database host=172.16.117.129
INFO[2022-09-07T23:00:15.719] set 172.16.117.128 postgresql.conf host=172.16.117.128
INFO[2022-09-07T23:00:15.754] set 172.16.117.128 hba config host=172.16.117.128
INFO[2022-09-07T23:00:15.785] create CA files host=172.16.117.128
INFO[2022-09-07T23:00:15.975] move CA files to server host=172.16.117.128
INFO[2022-09-07T23:00:15.980] download ca files from host 172.16.117.128 host=172.16.117.128
INFO[2022-09-07T23:00:16.012] [stage=initial]: successful host=172.16.117.128
INFO[2022-09-07T23:00:17.149] set 172.16.117.129 postgresql.conf host=172.16.117.129
INFO[2022-09-07T23:00:17.203] set 172.16.117.129 hba config host=172.16.117.129
INFO[2022-09-07T23:00:17.251] waitting for generate CA files... host=172.16.117.129
INFO[2022-09-07T23:00:17.251] upload CA files host=172.16.117.129
INFO[2022-09-07T23:00:17.573] move CA files to server host=172.16.117.129
INFO[2022-09-07T23:00:17.594] [stage=initial]: successful host=172.16.117.129
INFO[2022-09-07T23:00:17.594] start make ssh mutual trust for omm
INFO[2022-09-07T23:00:17.791] make ssh mutual trust successfully
INFO[2022-09-07T23:00:17.791] [stage=launch]: start host=172.16.117.129
INFO[2022-09-07T23:00:17.791] start 172.16.117.129 database by gs_ctl host=172.16.117.129
? executing...INFO[2022-09-07T23:00:17.791] [stage=launch]: start host=172.16.117.128
INFO[2022-09-07T23:00:17.791] start 172.16.117.128 database by gs_ctl host=172.16.117.128
INFO[2022-09-07T23:00:18.858] alter initial user password host=172.16.117.128
INFO[2022-09-07T23:00:18.874] waitting for primary startup... host=172.16.117.129
INFO[2022-09-07T23:00:18.957] [stage=launch]: successful host=172.16.117.128
INFO[2022-09-07T23:00:18.957] primary startuped, start build current db host=172.16.117.129
INFO[2022-09-07T23:00:18.957] build 172.16.117.129 database by gs_ctl host=172.16.117.129
INFO[2022-09-07T23:00:26.595] [stage=launch]: successful host=172.16.117.129
INFO[2022-09-07T23:00:26.595] Time elapsed: 2m25s
cluste_name | host | user | port | stage | status | message
-----------------+----------------+------+-------+--------+---------------+----------
mogdb_cluster1 | 172.16.117.128 | omm | 26000 | launch | start_success | success
| 172.16.117.129 | omm | 26000 | launch | start_success | success
[root@mogdbA ~]#
4.4 集群/實例狀態管理
- ptk ls
列出當前用戶已經安裝的所有數據庫列表,PTK以使用用戶作為區分,所以不同用戶之間僅能看到自己安裝的列表
[root@mogdbA ~]# ptk ls
cluster_name | instances | user | data_dir | db_version | create_time | comment
-----------------+----------------------+------+-----------------+------------------------------+---------------------+----------
mogdb_cluster1 | 172.16.117.128:26000 | omm | /opt/mogdb/data | MogDB 3.0.1 (build 1a363ea9) | 2022-09-07 23:00:05 |
| 172.16.117.129:26000 | | | | |
- ptk cluster
ptk cluster status: 查詢集群或實例狀態
ptk cluster start: 啟動數據庫集群或實例
ptk cluster stop: 停止數據庫集群或實例
ptk cluster restart: 重啟數據庫集群或實例
- 查看數據庫實例狀態
[root@mogdbA ~]# ptk cluster status -n mogdb_cluster1
[ Cluster State ]
database_version : MogDB-3.0.1
cluster_name : mogdb_cluster1
cluster_state : Normal
current_az : AZ_ALL
[ Datanode State ]
id | ip | port | user | instance | db_role | state
-------+----------------+-------+------+----------+---------+---------
6001 | 172.16.117.128 | 26000 | omm | dn_6001 | primary | Normal
6002 | 172.16.117.129 | 26000 | omm | dn_6002 | standby | Normal
一主一備正常運行




