Metadb master-slave configuration
Configuration Instructions
- 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
- 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, where10.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. - Ensure that the slave server can log in without a password to the master server.
- 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
- Before initializing metaslave, ensure that the metadb service is in the startup state.
- 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
1
2
2
Startup Operation
shell
cd /opt/hengshi
bin/hengshi-sense-bin start metaslave
1
2
2
Stop Operation
shell
cd /opt/hengshi
bin/hengshi-sense-bin stop metaslave
1
2
2
Switch Slave Operation
- 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
2
2
- Enter Y to confirm this operation when prompted. The successful operation interface is as follows:
- 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- 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.
- 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.
- Restart the HENGSHI SENSE service to complete the master-slave switch operation.
shell
cd /opt/hengshi
bin/hengshi-sense-bin restart hengshi
1
2
2
Cluster Deployment Considerations
- 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
2
2
- 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
2
2
- 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
1
2
2
Seeing the "streaming" label indicates that the master-slave configuration is successful
Container Deployment
Preparation
- Deploy Metadb master-slave using a specific docker-compose.yaml file, please contact the after-sales personnel.
- 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)
- 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
- Before initializing metaslave, ensure that the metadb service is in the startup state.
- 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
1
2
2
Startup Operation
shell
cd single
docker-compose up -d
1
2
2
Stop Operation
shell
cd single
docker-compose down
1
2
2
Switch Slave Operation
- 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
2
2
- Enter Y to confirm this operation when prompted. The successful operation interface is as follows:
- Please modify the
metaslave/docker-compose.yaml
configuration file, changehengshi>environment>HS_PG_HOST:**hengshi-metadb**
to the IP of the standby server. - Restart the HENGSHI SENSE service to complete the master-slave switch operation.
shell
cd single
docker-compose down
docker-compose up
1
2
3
2
3
k8s Deployment
Preparation
- Please contact the after-sales staff to obtain the
metaslave.yaml
configuration file.
Startup Operation
Note
- Before performing the operation metaslave, ensure that the metadb service is in the startup state.
- The initialized slave database has read-only permissions and no write permissions, and cannot be directly connected for use as a database.
- 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
1
2
2
Switch Slave Operation
- 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:
- Modify the
configmap.yaml
file, changing the parameterHS_PG_HOST: **metadb-0.hengshi-hs**
tometaslave-0.hengshi-hs
. - Restart the HENGSHI SENSE service to complete the master-slave switch operation.
shell
kubectl -n hengshi apply -f hengshi.yaml
1