Introduction #
DBPlusEngine-Mate is a registry center designed for DBPlusEngine-Proxy. It helps users manage DBPlusEngine-Proxy in a more cloud-native way, making it easier to operate while also saving resources. It provides an operational experience that is suitable for SREs (Site Reliability Engineers) and DBAs (Database Administrators).
Features #
Currently, Mate supports the following features:
High Availability Support Mate currently uses a primary/secondary mode to support a high-availability architecture.
Event Subscription Support Mate uses a ZNode structure similar to ZooKeeper to store data. DBPlusEngine-Proxy interacts with Mate through bidirectional GRPC streams and subscribes to events related to specific paths. When events occur, Mate sends them to all subscribers.
Multiple Backend Data Persistence Support Mate supports data persistence using Kubernetes ConfigMap, object storage, MySQL, and PostgreSQL.
Support for Different Deployment Methods Mate supports deployment in both virtual machines and Kubernetes environments.
Architecture #
Mate Architecture #
- How It Works When Mate starts, it writes a value to a fixed location in the backend. Following the “first come, first served” principle, the Mate that successfully writes first becomes the primary node to provide services. Additionally, Mate periodically updates information.
Proxy Connecting to Mate Architecture Diagram #
- How It Works When DBPlusEngine-Proxy starts, it retrieves information about the current primary node through Mate’s interface. It accesses Mate’s service interface based on the obtained primary node information. If it cannot retrieve the information, it continues to periodically attempt to fetch the primary node information until successful.
Deployment #
Deployment in Virtual Machines #
Explanation:
DBPlusEngine-Proxy retrieves information about all Mate instances via the internal LB address. It then constructs the RPC address of the Mate Leader based on the returned information and establishes a connection with the RPC address.
The host IP address where DBPlusEngine-Proxy is located needs to have network connectivity with the host IP addresses of Mate instances.
If you cannot create an LB in a private environment, you can use the following solutions:
a. Deploy keepalived + VIP.
b. Change the server-lists
configuration in the DBPlusEngine-Proxy’s server.yaml
configuration file to “machine1 ip:9090, machine2 ip:9090,” as shown below.
...
mode:
type: Cluster
repository:
type: ZooKeeper
props:
namespace: governance_ds
server-lists: 192.168.0.1:9090,192.168.0.2:9090
...
Installation #
sudo rpm -ivh sphereex-mate*.rpm
Explanation: RPM Package Files
The RPM package will create the following files:
File | Description |
---|---|
/etc/sphereex-mate/mate.conf | This is Mate’s configuration file, primarily containing command-line parameters for startup |
/usr/lib/systemd/system/sphereex-mate.service | This is Mate’s service configuration file, managed by systems |
/usr/local/sphereex-mate/mate | This is the executable file for Mate |
/usr/local/sphereex-mate/mate-cli | This is a maintenance tool for Mate, mainly used for operations on the keys stored by the current Mate |
Preparatory Steps
Before using Mate, follow these steps:
After installing the Mate RPM package, execute the following command to make the Mate service effective:
systemctl daemon-reload #只需运行一次
- Before starting Mate, modify the /etc/sphereex-mate/mate.conf configuration file according to your actual requirements. For example, if you’re using MySQL as the leader election and data storage backend for Mate, the configuration might look like this:
ARGS="-db-leader \
-mysql-backend \
-db-host=127.0.0.1 \
-db-port=13306 \
-db-user=root \
-db-password=123456 \
Startup #
To start Mate, use the following command:
sudo systemctl start sphereex-mate
- Mate will by default start on the following ports:
|Port|Description| |21510| Mate GRPC service port, used for communication with DBPlusEngine-Proxy| |21511 |Mate GRPC-Web port, reserved for future use| |9090 |Mate metrics port, used by DBPlusEngine-Proxy to obtain Mate instance information|
- Check Status
sudo systemctl status sphereex-mate
- Shutdown
sudo systemctl stop sphereex-mate
- Uninstall
sudo rpm -e sphereex-mate
- Configure DBPlusEngine-Proxy
DBPlusEngine-Proxy 使用 Mate 需要做如下配置:
...
mode:
type: Cluster
repository:
type: SphereEx:MATE
props:
namespace: governance_ds
server-lists: ${LB IP}:9090
Replace ${LB IP}
with the actual IP address of your load balancer (LB).
- List of Parameters
Parameter | Type | Default | Value Description |
---|---|---|---|
-grpc-addr | string | :21510 | Address for the GRPC service listener |
-grpc-web-addr | string | :21511 | Address for the GRPC Web service listener (reserved for future use) |
-metrics-addr | string | :9090 | Address for the metrics service listener, used by DBPlusEngine-Proxy to obtain the current running Mate leader information |
-kube-leader | boolean | false | Whether to elect the leader through Kubernetes |
-obs-leader | boolean | false | Whether to elect the leader through object storage |
-db-leader | boolean | false | Whether to elect the leader through a database |
-kube-backend | boolean | false | Whether to use Kubernetes ConfigMap for data persistence |
-obs-backend | boolean | false | Whether to use object storage for data persistence |
-pg-backend | boolean | false | Whether to use PostgreSQL for data persistence |
-mysql-backend | boolean | false | Whether to use MySQL for data persistence |
-null-backend | boolean | false | Whether to retain data only in memory (primarily used for testing, has no practical purpose) |
-rate | integer | 0 | Rate limit |
-kube-backend-name | string | mate-backend | Name of the Kubernetes ConfigMap used for data persistence |
-obs-access-key | string | "" | Specify the access key for connecting to object storage |
-obs-secret-key | string | "" | Specify the secret key for connecting to object storage |
-obs-endpoint | string | "" | Specify the address of the object storage |
-obs-region | string | "" | Specify the region where the object storage bucket is located, can be left empty |
-obs-bucket | string | "" | Specify the bucket used in object storage |
-obs-ssl | boolean | false | Whether to enable SSL when connecting to object storage |
-db-host | string | "" | Specify the database address |
-db-port | string | "" | Specify the database port |
-db-user | string | "" | Specify the username for connecting to the database |
-db-password | string | "" | Specify the password for connecting to the database |
-db-dbname | string | "" | Specify the name of the connected database |
-zap-log-level | string | info | Log level, can be ‘debug’, ‘info’, or ’error’ |
Deployment in Kubernetes #
In Kubernetes deployment, DBPlusEngine-Proxy retrieves information about all Mate instances via a Service address and connects to the RPC address of the Mate Leader, as constructed from the received information. Here are some important notes:
- DBPlusEngine-Proxy obtains information about all Mate PODs through the Service and constructs the Mate Leader’s RPC address for connection.
- The POD IP of DBPlusEngine-Proxy needs to be able to communicate with the POD IP of Mate.
Installation #
Before installing Mate in a Kubernetes environment, you need to modify the values.yaml
file of the Helm Chart according to your actual requirements. Here’s an example configuration for electing a leader in Kubernetes with S3 as the Mate data persistence storage:
...
kubeLeader:
## @param kubeLeader.enabled Enable leader election in Kubernetes using Lease
enabled: true
nullBackend:
## @param nullBackend.enabled Set to use in-memory mode; this mode is for testing purposes only
enabled: false
kubeBackend:
## @param kubeBackend.enabled Enable kubeBackend for data persistence to Kubernetes ConfigMap
enabled: false
## @param kubeBackend.backendName Name of the ConfigMap for data persistence
backendName: "mate-backend"
obsBackend:
## @param obsBackend.enabled Enable obsBackend for data persistence to object storage
enabled: true
## @param obsBackend.accessKey Authentication access key for object storage
accessKey: "AKIAXRZPPZNGWHZDZX1Z"
## @param obsBackend.secretKey Authentication secret key for object storage
secretKey: "1Reu8cOyTLl57jccjLMSTh5qFOH3Rayx0R2UWCUd"
## @param obsBackend.endpoint Address of the object storage
endpoint: "s3.amazonaws.com"
## @param obsBackend.bucket Name of the bucket in object storage
bucket: "mate-test-chaos"
## @param obsBackend.region Region where the object storage bucket is located
region: ""
## @param obsBackend.useSSL Enable SSL when accessing object storage
useSSL: true
...
To install, run the following command:
helm install release-name dbplusengine-mate [-n namespace]
This will create the following resources:
deployment
: Mate’s deployment with a default replica count of 2.service
: Mate’s service exposing default ports 21510 and 9090.secret
: Created if imagePullAccount.enabled is set to true.
Configuring DBPlusEngine-Proxy To configure DBPlusEngine-Proxy to use Mate, modify your configuration as follows:
...
mode:
type: Cluster
repository:
type: SphereEx:MATE
props:
namespace: governance_ds
server-lists: ${Service Name}:9090
Replace ${Service Name}
with the actual ServiceName.
Uninstallation #
To uninstall, run the following command:
helm delete release-name
Parameter List #
Helm Chart List of Parameters
Parameter | Default Value | Description |
---|---|---|
replicas | 2 | Number of Mate Replicas |
image.repository | uhub.service.ucloud.cn/cloud-ops/mate | Mate image name |
image.tag | latest | Mate image tag |
image.pullPolicy | Always | image pull policy |
imagePullAccount.enabled | false | Automatically create a secret based on authentication information |
imagePullAccount.username | "" | Username for private repository authentication |
imagePullAccount.password | "" | Password for private repository authentication |
imagePullSecrets.enabled | true | Use existing private repository authentication secrets |
imagePullSecrets.secrets[0].name | "" | Specify the name of an existing private repository authentication secret |
resources | {} | Resources required by Mate |
podTemplateAnnotations | {} | Annotations for the Pod template |
grpcAddr | :21510 | gRPC server listening address |
grpcWebAddr | :21511 | gRPC web server listening address |
metricsAddr | :9090 | Metrics server listening address |
kubeLeader.enabled | true | Enable leader election in Kubernetes using Lease |
nullBackend.enabled | false | Set to use in-memory mode (for testing only) |
kubeBackend.enabled | true | Enable kubeBackend for data persistence to Kubernetes ConfigMap |
kubeBackend.backendName | mate-backend | Name of the ConfigMap for data persistence |
obsBackend.enabled | false | Enable obsBackend for data persistence to object storage |
obsBackend.accessKey | "" | Authentication access key for object storage |
obsBackend.secretKey | "" | Authentication secret key for object storage |
obsBackend.endpoint | "" | Object storage address |
obsBackend.bucket | "" | Name of the bucket in object storage |
obsBackend.region | "" | Region where the object storage bucket is located |
obsBackend.useSSL | false | Enable SSL when accessing object storage |
dbBackend.enabled | false | Enable dbBackend for data persistence to a database |
dbBackend.kind.mysql | true | Use MySQL database |
dbBackend.kind.pg | false | Use PostgreSQL database |
dbBackend.host | "" | Database address |
dbBackend.user | "" | Database authentication username |
dbBackend.password | "" | Database authentication password |
dbBackend.db | "" | Database name |
MateCli Usage Guide #
Introduction #
MateCli provides functionality similar to zkCli.sh in Zookeeper. It allows you to interactively query the data stored within Mate, enhancing Mate’s maintainability.
Interactive Commands #
Prerequisite: #
For deployment in a virtual machine, execute the following command to enter the interactive terminal, for example:
# /mate-cli -mate-addr 127.0.0.1:9090
Mate[/]>
For deployment in Kubernetes, you need to enter the container and execute the following command to access the interactive terminal, for example:
❯ kubectl exec -it -n ss mate-sphereex-dbplusengine-mate-d569b4b69-9zhbk sh
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
/ # ./mate-cli -mate-addr 127.0.0.1:9090
Mate[/]>
Note: Replace the -mate-addr parameter with the actual address.
ls
Execute the following command:
ls
Execute the following command to recursively display all keys:
ls -r
cd
Execute the following command to switch to a specific node:
cd /tm/nodes/compute_nodes/online/proxy/
put
Execute the following command to create a key:
put /ts/a c
get
Execute the following command to view a key:
get /ts/a
stat
Execute the following command to view the metadata of a key:
stat /ts/a
delete
Execute the following command to delete a key:
delete /ts/a
pwd
Execute the following command to view the current path:
pwd
help
Execute the following command to view the help information:
help
Execute the following command to view specific command help information:
put -h
- exit
To exit the terminal, simply use the exit command.
exit