Are you an LLM? You can read better optimized documentation at /v6.0/en-us/metadb-slave-config.md for this page in Markdown format
Metadb Master-Slave Configuration
Configuration Instructions
- Metadb master-slave configuration, applicable to Metadb database versions higher than 13.5. For Metadb services below this version, refer to Database Service Upgrade.
Standalone/Cluster Deployment
Preparation Work
- 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.
Multiple slave configurations are supported, allowing you to choose one or multiple slave nodes, and horizontal scaling of the number of slave nodes is supported. - Ensure that the slave server can log in to the master server without a password.
- Before executing the initialization operation for the slave node, ensure that the master node's
metadb
service is in a running state.
Note: The slave node port cannot be configured; it uses theHS_PG_PORT
value configured on the master node. Please ensure that this port is available on the slave node.
Initialization Operations
Note
- Before initializing metaslave, ensure that the metadb service is running.
- The initialized slave database has read-only permissions without 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 Operations
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
Switching Slave Database Operations
- Promote write permissions for the slave database. This operation needs to be executed on the server with the original slave database address configured in
HS_PG_HOST
.
shell
cd /opt/hengshi
bin/hengshi-sense-bin promote metadb
1
2
2
- When the following prompt appears, enter
Y
to confirm the operation. The successful operation interface is shown below: - Modify the
HS_PG_HOST
parameter in the/opt/hengshi/conf/hengshi-sense-env.sh
file to the slave database address you want to switch to as the master database. Note- If the
HS_ENGINE_HOST
parameter is not configured, please configure it. Using the default parameter will reference theHS_PG_HOST
parameter information, which may lead to an incorrect engine address. - After switching to the slave database, please reconfigure the
PG_METASLAVE_HOST
parameter. The previously configured master-slave relationship will become invalid, and you will need to perform initialization operations again.
- If the
- Restart the HENGSHI service to complete the master-slave switching operation.
shell
cd /opt/hengshi
bin/hengshi-sense-bin restart hengshi
1
2
2
Cluster Deployment Notes
- 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 backup when the master database is down
Node-B
1
2
2
- Specify the
export PG_METASLAVE_HOST=(Node-B)
parameter in/opt/hengshi/conf/hengshi-sense-env.sh
on the machine node where the metadb slave resides (default Node-B) as Node-B. Use spaces to separate multiple hosts.
Alternatively, you can directly modify /opt/hengshi/conf/hengshi-sense-env.sh
on Node-A, and then use the following command to synchronize the configuration file to other nodes:
shell
./hs_install -m config -c ../cluster-conf/
1
- Execute 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
You will see the word "streaming," indicating that the master-slave configuration is successful.
Container Deployment
Preparation Work
- Deploy Metadb master-slave using a specific docker-compose.yaml file. Please contact support personnel.
- Configure the hsenv file:
- HS_MASTER_PG_HOST: Deployment service node, server IP information (not the internal IP of the docker container).
- HS_SLAVE_PG_HOST: Deployment slave node, server IP information (not the internal IP of the docker container).
- Ensure that the HS_MASTER_PG_HOST and HS_SLAVE_PG_HOST servers can communicate normally and that the HS_PG_EXPOSE_PORT is mutually open.
Initialization Operations
Note
- Before initializing metaslave, ensure that the metadb service is running.
- The initialized slave database has read-only permissions and no write permissions. It cannot be directly connected for use as a database.
shell
cd single
docker-compose run --rm metadb init metaslave
1
2
2
Start Operation
shell
cd single
docker-compose up -d
1
2
2
Stop Operation
shell
cd single
docker-compose down
1
2
2
Switching Slave Operations
- Promote the read-write permissions of the slave. This operation needs to be executed on the server with the original slave address configured in
HS_SLAVE_PG_HOST
.
shell
cd single
docker-compose run --rm metadb promote metadb
1
2
2
- When the following prompt appears, enter
Y
to confirm the operation. The successful operation interface is shown below: - Modify the
hengshi docker-compose/.env
configuration file, changingHS_PG_HOST:xxx
to the IP of the slave server. - Restart the HENGSHI service to complete the master-slave switching operation.
shell
cd single
docker-compose down
docker-compose up
1
2
3
2
3
k8s Deployment
Preparation Work
- Please contact the after-sales personnel to obtain the
metaslave.yaml
configuration file.
Startup Operations
Note
- Before executing the
metaslave
operation, ensure that themetadb
service is in a running state. - The initialized slave database has read-only permissions and no write permissions; it cannot be directly connected for use as a database.
- Please confirm that the
LOCAL_HOST_NAME
parameter is configured in theconfigmap.yaml
file.
shell
kubectl -n hengshi apply -f configmap.yaml
kubectl -n hengshi apply -f metaslave.yaml
1
2
2
Switching Slave Database Operations
- Promote slave database read-write permissions
shell
kubectl -n hengshi exec -it metaslave-0 -- /docker-entrypoint.sh promote metadb single
1
- When the following prompt appears, enter Y to confirm the operation. The successful operation interface is shown below:
- Modify the
configmap.yaml
file, change the parameterHS_PG_HOST: **metadb-0.hengshi-hs**
tometaslave-0.hengshi-hs
. - Restart the HENGSHI service to complete the master-slave switching operation:
shell
kubectl -n hengshi apply -f hengshi.yaml
1