若要升級 InnoDB ReplicaSet 中的執行個體,請完成下列步驟
檢查已安裝二進位檔案的版本
mysqlrouter --version:檢查已安裝的 MySQL Router 版本。
mysqlsh --version:檢查已安裝的 MySQL Shell 版本。
mysqld --version:檢查已安裝的 MySQL 伺服器版本。
若要升級 MySQL Router,請完成下列步驟
-
停止 MySQL Router。
在 Unix 系統上,如果您使用選用的
--directory
引導選項,則會建立一個獨立安裝,所有產生的目錄和檔案都位於您在 引導路由器時選取的位置。這些檔案包含stop.sh
。導覽至此目錄並發出此命令./stop.sh
在 Microsoft Windows 上,如果您使用選用的
--directory
引導選項,則會建立一個獨立安裝,所有產生的目錄和檔案都位於您在 引導路由器時選取的位置。這些檔案包含stop.ps1
。導覽至此目錄並發出此命令.\stop.ps1
或者,在使用
systemd
的 Linux 系統上,發出以下命令停止 MySQL Router 服務systemctl stop mysqlrouter.service
否則,請終止相關的 mysqlrouter 程序的 程序 ID (PID)。
取得並安裝最新版本的 MySQL Router。
-
啟動 MySQL Router。
在 Unix 系統上,如果您使用選用的 -
-directory
引導選項,則會建立一個獨立安裝,所有產生的目錄和檔案都位於您選取的位置。這些檔案包含start.sh
。導覽至該目錄並發出此命令./start.sh
如果新路由器的路徑已變更,您必須更新
start.sh
Shell 腳本以反映路徑。#!/bin/bash basedir=/tmp/myrouter ROUTER_PID=$basedir/mysqlrouter.pid /usr/bin/mysqlrouter -c $basedir/mysqlrouter.conf & disown %-
如果您手動升級 MySQL Router,而不是使用套件管理,您可以更新
basedir=
。再次引導路由器也會重新產生start.sh
Shell 腳本。或者,在使用
systemd
的 Linux 系統上,發出以下命令啟動 MySQL Router 服務systemctl start mysqlrouter.service
在 Microsoft Windows 上,如果您使用選用的 -
-directory
引導選項,則會建立一個獨立安裝,所有產生的目錄和檔案都位於您選取的位置。這些檔案包含start.ps1
。導覽至該目錄並發出此命令.\start.ps1
使用新的路由器二進位檔案啟動 MySQL Router 時,路由器的版本會升級
mysqlrouter --version
藉由安裝新的二進位檔案,以及停止並啟動 MySQL Shell 來升級 MySQL Shell
取得並安裝最新版本的 MySQL Shell。
-
發出以下命令來停止並結束 MySQL Shell
\q
-
從命令列發出以下命令以重新啟動 MySQL Shell
mysqlsh
-
-
若要升級 InnoDB ReplicaSet,請將 MySQL Shell 的全域工作階段連線至您的 ReplicaSet,並使用
dba.upgradeMetadata()
操作將 ReplicaSet 的中繼資料升級至新的中繼資料。dba.upgradeMetadata()
函式會比較已安裝中繼資料結構描述的版本與此 Shell 支援的中繼資料結構描述版本。如果已安裝的中繼資料版本較低,則會啟動升級程序。
中繼資料升級如果 ReplicaSet 已使用最新版本,則中繼資料升級可能不會執行任何動作。
-
藉由在升級主要執行個體之前升級所有次要執行個體來升級 MySQL 伺服器。
升級 MySQL 伺服器是可選的。伺服器升級的影響可能大於升級 MySQL Shell 和 MySQL Router。此外,即使伺服器不是,您也應始終將 MySQL Shell 和 MySQL Router 維持在最新版本;這對 InnoDB Cluster 和 ReplicaSet 皆為如此。
-
發出下列其中一個命令來停止 MySQL 伺服器
-
如果 MySQL 伺服器使用 systemd,請發出
systemctl stop mysqld
-
如果 MySQL 伺服器使用 init.d,請發出
/etc/init.d/mysql stop
-
如果 MySQL 伺服器使用 service,請發出
service mysql stop
-
如果您在 Microsoft Windows 上部署 MySQL 伺服器,請發出
mysqladmin -u root -p shutdown
-
取得並安裝最新版本的 MySQL 伺服器。
-
發出下列其中一個命令來啟動 MySQL 伺服器
-
如果 MySQL 伺服器使用 systemd,請發出
systemctl start mysqld
-
如果 MySQL 伺服器使用 init.d,請發出
/etc/init.d/mysql start
-
如果 MySQL 伺服器使用 service,請發出
service mysql start
-
如果您在 Microsoft Windows 上部署 MySQL 伺服器,請發出
mysqld
-
-
當您升級所有次要執行個體時,請升級主要執行個體以完成升級程序。
InnoDB ReplicaSet 中沒有自動主要切換。您需要將主要執行個體設定為您已升級的成員,然後再升級主要執行個體。
將升級的次要執行個體設定為主要執行個體
<ReplicaSet>.setPrimaryInstance('<host>:<port>')
使用
<ReplicaSet>.setPrimaryInstance()
操作,以安全地將 ReplicaSet 的主要項目變更為另一個執行個體。目前的主要執行個體會降級為次要執行個體並設為唯讀,而升級的執行個體則會成為新的主要執行個體並設為讀寫。所有其他次要執行個體都會更新以從新的主要執行個體進行複寫。您已針對 ReplicaSet 引導的 MySQL Router 執行個體會自動開始將讀寫用戶端重新導向至新的主要執行個體。升級
舊
的主要執行個體。升級後,您可以使用<ReplicaSet>.setPrimaryInstance()
將此升級的執行個體還原為主要執行個體。如需詳細資訊,請參閱第 9.7 節,「變更主要執行個體」。
升級 MySQL Router、MySQL Shell 和 MySQL 伺服器後
-
藉由發出
<ReplicaSet>.status()
來檢查 ReplicaSet 的狀態。在以下範例中,<ReplicaSet>.status()
會傳回instanceErrors
mysqlsh> <ReplicaSet>.status(); { "replicaSet": { "name": "myReplicaSet", "primary": "example-el7-1644251369:30014", "status": "AVAILABLE", "statusText": "All instances available.", "topology": { "example-el7-1644251369:30011": { "address": "example-el7-1644251369:30011", "instanceErrors": [ "NOTE: The required parallel-appliers settings are not enabled on the instance. Use dba.configureReplicaSetInstance() to fix it." ], "instanceRole": "SECONDARY", "mode": "R/O", "replication": { "applierStatus": "APPLIED_ALL", "applierThreadState": "Waiting for an event from Coordinator", "applierWorkerThreads": 4, "receiverStatus": "ON", "receiverThreadState": "Waiting for source to send event", "replicationLag": null }, "status": "ONLINE" }, "example-el7-1644251369:30014": { "address": "example-el7-1644251369:30014", "instanceErrors": [ "NOTE: The required parallel-appliers settings are not enabled on the instance. Use dba.configureReplicaSetInstance() to fix it." ], "instanceRole": "PRIMARY", "mode": "R/W", "status": "ONLINE" }, "example-el7-1644251369:30017": { "address": "example-el7-1644251369:30017", "instanceErrors": [ "NOTE: The required parallel-appliers settings are not enabled on the instance. Use dba.configureReplicaSetInstance() to fix it." ], "instanceRole": "SECONDARY", "mode": "R/O", "replication": { "applierStatus": "APPLIED_ALL", "applierThreadState": "Waiting for an event from Coordinator", "applierWorkerThreads": 4, "receiverStatus": "ON", "receiverThreadState": "Waiting for source to send event", "replicationLag": null }, "status": "ONLINE" }, "example-el7-1644251369:30021": { "address": "example-el7-1644251369:30021", "instanceErrors": [ "NOTE: The required parallel-appliers settings are not enabled on the instance. Use dba.configureReplicaSetInstance() to fix it." ], "instanceRole": "SECONDARY", "mode": "R/O", "replication": { "applierStatus": "APPLIED_ALL", "applierThreadState": "Waiting for an event from Coordinator", "applierWorkerThreads": 4, "receiverStatus": "ON", "receiverThreadState": "Waiting for source to send event", "replicationLag": null }, "status": "ONLINE" } }, "type": "ASYNC" } }
instanceError
會告知我們發出dba.configureReplicaSetInstance()
來修正錯誤。dba.configureReplicaSetInstance(
會設定您想要在 ReplicaSet 中使用的每個執行個體。MySQL Shell 可以連線到執行個體,然後設定它,或者您可以傳入執行個體
)執行個體
名稱來設定特定的遠端執行個體。如需詳細資訊,請參閱第 6.2.3 節,「持續設定」。以下範例顯示
<ReplicaSet>.status()
的輸出,如果PRIMARY
成員將read_only
或super_read_only
設定為ON
mysqlsh > <ReplicaSet>.status(); replicaset.status(); { "replicaSet": { "name": "myReplicaSet", "primary": "example-el7-1644251369:30014", "status": "UNAVAILABLE", "statusText": "PRIMARY instance is not available, but there is at least one SECONDARY that could be force-promoted.", "topology": { "example-el7-1644251369:30011": { "address": "example-el7-1644251369:30011", "instanceErrors": [ "NOTE: The required parallel-appliers settings are not enabled on the instance. Use dba.configureReplicaSetInstance() to fix it." ], "instanceRole": "SECONDARY", "mode": "R/O", "replication": { "applierStatus": "APPLIED_ALL", "applierThreadState": "Waiting for an event from Coordinator", "applierWorkerThreads": 4, "receiverStatus": "ON", "receiverThreadState": "Waiting for source to send event", "replicationLag": null }, "status": "ONLINE" }, "example-el7-1644251369:30014": { "address": "example-el7-1644251369:30014", "fenced": true, "instanceErrors": [ "ERROR: Instance is a PRIMARY but is READ-ONLY: read_only=ON, super_read_only=ON", "NOTE: The required parallel-appliers settings are not enabled on the instance. Use dba.configureReplicaSetInstance() to fix it." ], "instanceRole": "PRIMARY", "mode": "R/O", "status": "ERROR" }, "example-el7-1644251369:30017": { "address": "example-el7-1644251369:30017", "instanceErrors": [ "NOTE: The required parallel-appliers settings are not enabled on the instance. Use dba.configureReplicaSetInstance() to fix it." ], "instanceRole": "SECONDARY", "mode": "R/O", "replication": { "applierStatus": "APPLIED_ALL", "applierThreadState": "Waiting for an event from Coordinator", "applierWorkerThreads": 4, "receiverStatus": "ON", "receiverThreadState": "Waiting for source to send event", "replicationLag": null }, "status": "ONLINE" }, "example-el7-1644251369:30021": { "address": "example-el7-1644251369:30021", "instanceErrors": [ "NOTE: The required parallel-appliers settings are not enabled on the instance. Use dba.configureReplicaSetInstance() to fix it." ], "instanceRole": "SECONDARY", "mode": "R/O", "replication": { "applierStatus": "APPLIED_ALL", "applierThreadState": "Waiting for an event from Coordinator", "applierWorkerThreads": 4, "receiverStatus": "ON", "receiverThreadState": "Waiting for source to send event", "replicationLag": null }, "status": "ONLINE" } }, "type": "ASYNC" } }
如需詳細資訊,請參閱第 9.10 節,「檢查 InnoDB ReplicaSet 的狀態」。 .