This topic describes how to change a standard OCP cluster into a primary or standby cluster in multi-cluster mode.
Prerequisite
An OCP cluster of V3.1.1 or later versions have been installed.
Method 1: Run scripts to enable the OCP multi-cluster mode
Run the
docker exec -it ocp bashcommand to enter the OCP container.Run the
env | grep -i metadbcommand to check whether the following MetaDB environment variables are set.OCP_METADB_HOST OCP_METADB_PORT OCP_METADB_USER OCP_METADB_PASSWORD OCP_METADB_DBNAMEIf not, run the following command to set the MetaDB environment viarables:
# The following example variables are provided for your reference only. You need to change the values based on the actual situation. export OCP_METADB_HOST="xxx.xxx.xxx.xxx" export OCP_METADB_PORT="2881" export OCP_METADB_USER="ocp@ocp_meta" export OCP_METADB_PASSWORD="******" export OCP_METADB_DBNAME="meta_01"Run the
cd /home/admin/ocp-init/src/ocp-initcommand to go to the directory where the modify_mc_config.py script is stored.You can perform one of the following steps to restructure your OCP cluster as needed:
Run the following command in the target OCP cluster to change it into the leader OCP cluster.
python modify_mc_config.py --multicluster_mode_enabled=true --cluster_id=1 --cluster_name=xxx --cluster_role=LEADERRun the following command in the target OCP cluster to change it into a follower OCP cluster.
python modify_mc_config.py --multicluster_mode_enabled=true --cluster_id=2 --cluster_name=xxx --cluster_role=FOLLOWERAfter a failover, run the following command in the original leader OCP cluster to change it into an unregistered follower OCP cluster that can be registered with the new leader OCP cluster.
python modify_mc_config.py --cluster_role=FOLLOWER --register_status=UNREGISTERED
Note
The modify_mc_config.py script supports the following parameters:
- --multicluster_mode_enabled: specifies whether to enable multi-cluster mode. Valid values: true and false.
- --cluster_id: specifies the ID of the OCP cluster. The type of the cluster ID is integral.
Restart the OCP cluster.
Run the
docker restart ocpcommand on the OCP host.If two or more OCP instances are deployed in the OCP cluster, restart all OCP instances.
Method 2: Run SQL commands to enable the OCP multi-cluster mode
Change the target OCP cluster into the leader cluster
Run the following command to connect to the MetaDB of the target cluster.
### Run the obclient command on the OBClient to connect to the OBServer and enter the MetaDB. obclient -hxxx.xxx.xxx.xxx -P2881 -uocp@ocp_meta#ocp321 -paA******1j -Dmeta_01 ### The following configurations are provided for your reference only. You need to change the values based on the actual situation. ### # xxx.xxx.xxx.xxx is the IP address of the OBServer on which the MetaDB is located. # 2881 is the port number for accessing the OBServer on which the MetaDB is located. # ocp@ocp_meta is the username used to access the MetaDB. # ocp321 is the name of the OceanBase cluster of the tenant to which the MetaDB belongs. # meta_ 01 is the name of the MetaDB.Run the following command to modify the mc_ocp_cluster_config table.
# Enable multi-cluster mode for the current OCP cluster. update mc_ocp_cluster_config set current_value = 'true' where name = 'ocp.multi-cluster.enabled'; # Change the role of the current OCP cluster to LEADER. update mc_ocp_cluster_config set current_value = 'LEADER' where name = 'ocp.cluster.role';Restart the OCP cluster.
Run the
docker restart ocpcommand on the OCP host.If two or more OCP instances are deployed in the OCP cluster, restart all OCP instances.
Log on to the OCP cluster again to verify whether it has become the leader.
In the left-side navigation pane, choose System Management > OCP Multi-cluster Mode . In the OCP Parameters list, find the
ocp.cluster.roleparameter and check whether the value is LEADER.If yes, the target OCP cluster is already changed into the leader OCP cluster.
Change the target OCP cluster into a follower OCP cluster
Run the following command to connect to the MetaDB of the target cluster.
### Run the obclient command on the OBClient to connect to the OBServer and enter the MetaDB. obclient -hxxx.xxx.xxx.xxx -P2881 -uocp@ocp_meta#ocp321 -paA******1j -Dmeta_01Run the following command to modify the mc_ocp_cluster_config table.
# Enable multi-cluster mode for the current OCP cluster. update mc_ocp_cluster_config set current_value = 'true' where name = 'ocp.multi-cluster.enabled'; # Change the role of the current OCP cluster to FOLLOWER update mc_ocp_cluster_config set current_value = 'FOLLOWER' where name = 'ocp.cluster.role';Restart the OCP cluster.