Skip to content

Metadb master-slave configuration

Configuration Instructions

  1. Master-slave configuration for Metadb, applicable to environments where the Metadb database version is higher than 13.5. For Metadb services with versions lower than this, please refer to Database Service Upgrade first.

Standalone/Cluster Deployment

Preparation

  1. Configure the export PG_METASLAVE_HOST=(10.10.10.xx 10.10.10.xx) parameter in the /opt/hengshi/conf/hengshi-sense-env.sh file, where 10.10.10.xx represents the IP address of the slave node. Support for multi-slave configuration, you can choose one slave or multiple slaves, and support horizontal scaling of the number of slaves.
  2. Ensure that the slave server can log in without a password to the master server.
  3. Before performing the slave initialization operation, ensure that the master's metadb service is in the startup state. Note The slave port is not configurable and uses the HS_PG_PORT value configured on the master. Please ensure that this port is available on the slave.

Initialization Operation

Note

  1. Before initializing metaslave, ensure that the metadb service is in the startup state.
  2. The initialized slave database has read-only permissions and no write permissions, and cannot be directly connected for use as a database.
shell
cd /opt/hengshi
bin/hengshi-sense-bin init metaslave

Startup Operation

shell
cd /opt/hengshi
bin/hengshi-sense-bin start metaslave

Stop Operation

shell
cd /opt/hengshi
bin/hengshi-sense-bin stop metaslave

Switch Slave Operation

  1. Elevate write permissions for the replica. This operation needs to be performed on the server where the original replica address configured in HS_PG_HOST is located.
shell
cd /opt/hengshi
bin/hengshi-sense-bin promote metadb
  1. Enter Y to confirm this operation when prompted. The successful operation interface is as follows:
  2. Modify the HS_PG_HOST parameter in the /opt/hengshi/conf/hengshi-sense-env.sh file to the address of the standby database you want to switch to the primary database. Note
    1. If the HS_ENGINE_HOST parameter is not configured, please configure it. Using the default parameter will reference the HS_PG_HOST parameter information, leading to an incorrect engine address.
    2. After switching to the standby database, please reconfigure the PG_METASLAVE_HOST parameter. The previous master-slave relationship will become invalid and you need to perform the initialization operation again.
  3. Restart the HENGSHI SENSE service to complete the master-slave switch operation.
shell
cd /opt/hengshi
bin/hengshi-sense-bin restart hengshi

Cluster Deployment Considerations

  1. Uncomment the following content in /opt/hengshi/ansible/hosts on the cluster operation node (default Node-A)
shell
[metaslave] #metadb database slave (optional) can be used as a standby database when the master is down
Node-B
  1. Specify the parameter export PG_METASLAVE_HOST=(Node-B) in the /opt/hengshi/conf/hengshi-sense-env.sh file on the machine node where the metadb slave is located (default Node-B) as Node-B, with multiple hosts separated by spaces.

You can also directly modify the /opt/hengshi/conf/hengshi-sense-env.sh of Node-A, and then use the following command to synchronize the configuration file to other nodes.

shell
# Skip backup and gpdb files can add -s t -g false parameters
./hs_install -m config -c ../cluster-conf/
  1. Perform initialization and startup operations on the cluster operation node (default Node-A)
shell
/opt/hengshi/bin/hengshi-sense-bin init metaslave
/opt/hengshi/bin/hengshi-sense-bin start metaslave

Seeing the "streaming" label indicates that the master-slave configuration is successful

Container Deployment

Preparation

  1. Deploy Metadb master-slave using a specific docker-compose.yaml file, please contact the after-sales personnel.
  2. Configure the hsenv file:
    • HS_MASTER_PG_HOST: Deployment service node, server IP information (not docker container internal IP information)
    • HS_SLAVE_PG_HOST: Deployment slave node, server IP information (not docker container internal IP information)
  3. Please ensure that the HS_MASTER_PG_HOST and HS_SLAVE_PG_HOST servers can communicate normally and that the HS_PG_EXPOSE_PORT ports are open to each other.

Initialization Operation

Note

  1. Before initializing metaslave, ensure that the metadb service is in the startup state.
  2. The initialized slave database has read-only permissions and no write permissions, and cannot be directly connected for use as a database.
shell
cd single
docker-compose run --rm metadb init metaslave

Startup Operation

shell
cd single
docker-compose up -d

Stop Operation

shell
cd single
docker-compose down

Switch Slave Operation

  1. Elevate read and write permissions from the replica. This operation needs to be performed on the server of the original replica address configured in HS_SLAVE_PG_HOST.
shell
cd single
docker-compose run --rm metadb promote metadb
  1. Enter Y to confirm this operation when prompted. The successful operation interface is as follows:
  2. Please modify the metaslave/docker-compose.yaml configuration file, change hengshi>environment>HS_PG_HOST:**hengshi-metadb** to the IP of the standby server.
  3. Restart the HENGSHI SENSE service to complete the master-slave switch operation.
shell
cd single
docker-compose down
docker-compose up

k8s Deployment

Preparation

  1. Please contact the after-sales staff to obtain the metaslave.yaml configuration file.

Startup Operation

Note

  1. Before performing the operation metaslave, ensure that the metadb service is in the startup state.
  2. The initialized slave database has read-only permissions and no write permissions, and cannot be directly connected for use as a database.
  3. Please confirm that the LOCAL_HOST_NAME parameter configuration exists in the configmap.yaml file.
shell
kubectl -n hengshi apply -f configmap.yaml
kubectl -n hengshi apply -f metaslave.yaml

Switch Slave Operation

  1. Elevate Read and Write Permissions from the Library
shell
kubectl -n hengshi exec -it metaslave-0 -- /docker-entrypoint.sh promote metadb single
  1. Enter Y to confirm this operation when prompted. The successful operation interface is as follows:
  2. Modify the configmap.yaml file, changing the parameter HS_PG_HOST: **metadb-0.hengshi-hs** to metaslave-0.hengshi-hs.
  3. Restart the HENGSHI SENSE service to complete the master-slave switch operation.
shell
kubectl -n hengshi apply -f hengshi.yaml

HENGSHI SENSE Platform User Manual