You can add and remove cluster hosts, resync the hosts, and manage {{ MG }} settings for individual clusters. To move cluster hosts to a different availability zone, read this guide.
{% list tabs group=instructions %}
-
Management console {#console}
- Go to the [folder page]({{ link-console-main }}) and select {{ ui-key.yacloud.iam.folder.dashboard.label_managed-mongodb }}.
- Click the name of the {{ mmg-name }} cluster.
- Select the {{ ui-key.yacloud.mdb.cluster.switch_hosts }} tab.
-
CLI {#cli}
{% include cli-install %}
{% include default-catalogue %}
To get a list of {{ mmg-name }} cluster hosts, run this command:
{{ yc-mdb-mg }} host list \ --cluster-name <cluster_name>
Result:
+----------------------------+----------------------+--------+------------+--------------+----------+---------------+-----------+ | NAME | CLUSTER ID | TYPE | SHARD NAME | ROLE | HEALTH | ZONE ID | PUBLIC IP | +----------------------------+----------------------+--------+------------+--------------+----------+---------------+-----------+ | rc1b...{{ dns-zone }} | c9qp71dk1q1w******** | MONGOD | rs01 | PRIMARY | ALIVE | {{ region-id }}-b | false | | rc1a...{{ dns-zone }} | c9qp71dk1q1w******** | MONGOD | rs01 | SECONDARY | ALIVE | {{ region-id }}-a | false | +----------------------------+----------------------+--------+------------+--------------+----------+---------------+-----------+
You can request the {{ mmg-name }} cluster name with a list of clusters in the folder.
-
API {#api}
To get a list of {{ mmg-name }} cluster hosts, use the listHosts REST API method for the Cluster resource or the ClusterService/ListHosts gRPC API call and provide the cluster ID in the
clusterId
request parameter.You can get the cluster ID with a list of clusters in the folder.
{% endlist %}
The number of hosts in {{ mmg-name }} clusters is limited by the CPU and RAM quotas available to DB clusters in your cloud. To check the resources in use, open the [Quotas]({{ link-console-quotas }}) page and find {{ mmg-name }}.
You can add different types of hosts to a {{ mmg-name }} cluster. Their number depends on the sharding type:
{#hosts-table}
Sharding type | MONGOD | MONGOINFRA | MONGOS | MONGOCFG |
---|---|---|---|---|
No sharding | ⩾ 1 | — | — | — |
Standard | ⩾ 1 | ⩾ 3 | — | — |
Advanced | ⩾ 1 | — | ⩾ 2 | ⩾ 3 |
{% list tabs group=instructions %}
-
Management console {#console}
To add a host to your {{ mmg-name }} cluster:
- Go to the [folder page]({{ link-console-main }}) and select {{ ui-key.yacloud.iam.folder.dashboard.label_managed-mongodb }}.
- Click the name of the {{ mmg-name }} cluster you need and go to the {{ ui-key.yacloud.mdb.cluster.switch_hosts }} tab.
- Click {{ ui-key.yacloud.mdb.cluster.hosts.button_add-host }}.
- Specify the host parameters:
- Availability zone.
- Subnet (if the required subnet is not on the list, create it).
- Select {{ ui-key.yacloud.mdb.hosts.dialog.field_public_ip }} if the host must be accessible from outside {{ yandex-cloud }}. You cannot change this setting after you create a host.
- Host type and shard name, if sharding is enabled for the {{ mmg-name }} cluster.
- Click {{ ui-key.yacloud.mdb.hosts.dialog.button_choose }}.
-
CLI {#cli}
{% include cli-install %}
{% include default-catalogue %}
To add a host to your {{ mmg-name }} cluster:
-
Request a list of {{ mmg-name }} cluster subnets to select a subnet for the new host:
yc vpc subnet list
Result:
+----------------------+-----------+-----------------------+---------------+------------------+ | ID | NAME | NETWORK ID | ZONE | RANGE | +----------------------+-----------+-----------------------+---------------+------------------+ | b0cl69a2b4c6******** | default-d | enp6rq72rndgr******** | {{ region-id }}-d | [172.16.0.0/20] | | e2lkj9qwe762******** | default-b | enp6rq72rndgr******** | {{ region-id }}-b | [10.10.0.0/16] | | e9b0ph42bn96******** | a-2 | enp6rq72rndgr******** | {{ region-id }}-a | [172.16.32.0/20] | | e9b9v22r88io******** | default-a | enp6rq72rndgr******** | {{ region-id }}-a | [172.16.16.0/20] | +----------------------+-----------+-----------------------+---------------+------------------+
If the required subnet is not on the list, create it.
-
View a description of the CLI command for adding a host:
{{ yc-mdb-mg }} host add --help
-
Run the add host command:
{{ yc-mdb-mg }} host add \ --cluster-name <cluster_name> \ --host zone-id=<availability_zone>,` `subnet-id=<subnet_ID>,` `assign-public-ip=<public_access>
Where
assign-public-ip
is public access to the host,true
orfalse
.{{ mmg-name }} will run the add host operation.
The subnet ID should be specified if the availability zone contains multiple subnets; otherwise, {{ mmg-name }} automatically selects the sole subnet. You can request the {{ mmg-name }} cluster name with a list of clusters in the folder.
-
-
{{ TF }} {#tf}
To add a host to your {{ mmg-name }} cluster:
-
Open the current {{ TF }} configuration file with an infrastructure plan.
For more information about how to create this file, see Creating clusters.
-
Add the following to the {{ mmg-name }} cluster description:
- Resources corresponding to the sharding type, if you are adding a host to a sharded cluster:
resources_mongoinfra
: For standard sharding.resources_mongos
andresources_mongocfg
: For advanced sharding.
- The
host
section.
resource "yandex_mdb_mongodb_cluster" "<cluster_name>" { ... resources_mongod { resource_preset_id = "<host_class>" disk_type_id = "<disk_type>" disk_size = <storage_size_GB> } resources_mongoinfra { # Add this for standard sharding. resource_preset_id = "<host_class>" disk_type_id = "<disk_type>" disk_size = <storage_size_GB> } resources_mongos { # Add this for advanced sharding. resource_preset_id = "<host_class>" disk_type_id = "<disk_type>" disk_size = <storage_size_GB> } resources_mongocfg { # Add this for advanced sharding. resource_preset_id = "<host_class>" disk_type_id = "<disk_type>" disk_size = <storage_size_GB> } host { role = "<replica_type>" zone_id = "<availability_zone>" subnet_id = "<subnet_ID>" assign_public_ip = <public_access> shard_name = "<shard_name>" type = "<host_type>" ... } }
Where:
host
: Host parameters:role
: Replica type,PRIMARY
orSECONDARY
.zone_id
: Availability zone.subnet_id
: ID of a subnet in the selected availability zone.assign_public_ip
: Public access to the host,true
orfalse
.shard_name
: Name of the shard in a sharded cluster.type
: Type of the host in a sharded cluster:MONGOD
,MONGOINFRA
,MONGOS
, orMONGOCFG
.
- Resources corresponding to the sharding type, if you are adding a host to a sharded cluster:
-
Make sure the settings are correct.
{% include terraform-validate %}
-
Confirm updating the resources.
{% include terraform-apply %}
For more information, see the [{{ TF }} provider documentation]({{ tf-provider-resources-link }}/mdb_mongodb_cluster).
{% include Terraform timeouts %}
-
-
API {#api}
To add a host to a cluster, use the addHosts REST API method for the Cluster resource or the ClusterService/AddHosts gRPC API call and provide the following in the request:
- Cluster ID in the
clusterId
parameter. To find out the cluster ID, get a list of clusters in the folder. - New host settings in one or more
hostSpecs
parameters.
- Cluster ID in the
{% endlist %}
Security groups are at the Preview stage. If they are not available on your network, all incoming and outgoing traffic for the resources will be allowed. No additional setup is required.
To enable security groups, [request access to this feature from technical support]({{ link-console-support }}).
{% note warning %}
If you cannot connect to the added host, make sure that the {{ mmg-name }} cluster security group is configured correctly for the subnet where you placed the host.
{% endnote %}
You can remove a MONGOD
host from a {{ mmg-name }} cluster if it is not the only host in it. To replace a single host, first create a new host and then remove the old one.
If the host is a primary one at the time of removal, {{ mmg-name }} automatically selects a new primary replica.
From a sharded {{ mmg-name }} cluster, you may remove the MONGOS
, MONGOCFG
, or MONGOINFRA
hosts that exceed the minimum number needed for sharding.
{% list tabs group=instructions %}
-
Management console {#console}
To remove a host from a {{ mmg-name }} cluster:
- Go to the [folder page]({{ link-console-main }}) and select {{ ui-key.yacloud.iam.folder.dashboard.label_managed-mongodb }}.
- Click the name of the {{ mmg-name }} cluster you need and select the {{ ui-key.yacloud.mdb.cluster.switch_hosts }} tab.
- Click the icon in the line of the necessary host and select {{ ui-key.yacloud.common.delete }}.
- In the window that opens, check Delete host and click {{ ui-key.yacloud.mdb.cluster.hosts.popup-confirm_button }}.
-
CLI {#cli}
{% include cli-install %}
{% include default-catalogue %}
To remove a host from the {{ mmg-name }} cluster, run:
{{ yc-mdb-mg }} host delete <host_name> --cluster-name <cluster_name>
You can request the host name with a list of {{ mmg-name }} cluster hosts and the cluster name with a list of clusters in the folder.
-
{{ TF }} {#tf}
To remove a host from a {{ mmg-name }} cluster:
-
Open the current {{ TF }} configuration file with an infrastructure plan.
For more information about how to create this file, see Creating clusters.
-
Delete the corresponding
host
block from the {{ mmg-name }} cluster description. -
Make sure the settings are correct.
{% include terraform-validate %}
-
Type
yes
and press Enter.{% include terraform-apply %}
For more information, see the [{{ TF }} provider documentation]({{ tf-provider-resources-link }}/mdb_mongodb_cluster).
{% include Terraform timeouts %}
-
-
API {#api}
To delete a host, use the deleteHosts REST API method for the Cluster resource or the ClusterService/DeleteHosts gRPC API call and provide the following in the request:
- Cluster ID in the
clusterId
parameter. To find out the cluster ID, get a list of clusters in the folder. - Name(s) of the host(s) to delete in the
hostNames
parameter.
- Cluster ID in the
{% endlist %}
To resync a host with other replicas in the {{ mmg-name }} cluster or shard, run forced resync. The operation can be applied to only one MONGOD
host at a time and only for {{ mmg-name }} clusters with more than two replicas, regardless of the host class and type. Resync also lets you remove the collections and documents that were marked as deleted from the host's storage.
During this operation:
-
The host stops accepting write requests. If the host was a
PRIMARY
replica, {{ mmg-name }} will try to make it aSECONDARY
replica. If the operation fails, it is aborted. -
The {{ MG }} instance on the host stops, and all data is deleted.
-
The {{ MG }} instance restarts and downloads data from replica hosts again.
-
Once the host has synced with other replicas in the {{ mmg-name }} cluster, it becomes a secondary replica.
{% note info %}
- During syncing, the host can't fully respond to any request, because it has only part of the {{ mmg-name }} cluster data.
- Estimated sync rate: 300 GB per day or more.
{% endnote %}
{% list tabs group=instructions %}
-
Management console {#console}
To forcibly resync a host:
- Go to the [folder page]({{ link-console-main }}) and select {{ ui-key.yacloud.iam.folder.dashboard.label_managed-mongodb }}.
- Click the name of the {{ mmg-name }} cluster you need and select the {{ ui-key.yacloud.mdb.cluster.switch_hosts }} tab.
- Click the icon in the required host row and select {{ ui-key.yacloud.mongodb.hosts.action_resetup-host }}.
-
CLI {#cli}
{% include cli-install %}
{% include default-catalogue %}
To forcibly resync a host, run the following command:
{{ yc-mdb-mg }} hosts resetup <host_name> --cluster-name <cluster_name>
You can get the host name with a list of hosts in the folder. You can request the {{ mmg-name }} cluster name with a list of clusters in the folder.
-
API {#api}
To resync a host, use the resetupHosts REST API method for the Cluster resource or the ClusterService/ResetupHosts gRPC API call and provide the following in the request:
- Cluster ID in the
clusterId
parameter. To find out the cluster ID, get a list of clusters in the folder. - Host name, in the
hostNames
parameter. To find out the name, get a list of hosts in the cluster.
- Cluster ID in the
{% endlist %}
You can manually restart {{ mmg-name }} cluster hosts.
Restarting a host may make a {{ mmg-name }} cluster or shard temporarily unavailable:
- If there is a single host in the cluster.
- If the host is the primary replica.
When the primary replica is restarted, there is no automatic switch-over. To make sure the {{ mmg-name }} cluster remains available, switch the cluster's primary replica before it is restarted.
{% note info %}
You can only restart one host at a time.
{% endnote %}
{% list tabs group=instructions %}
-
CLI {#cli}
{% include cli-install %}
{% include default-catalogue %}
To restart a host, run the command:
{{ yc-mdb-mg }} hosts restart <host_name> \ --cluster-name <cluster_name>
-
API {#api}
To restart a host, use the restartHosts REST API method for the Cluster resource or the ClusterService/RestartHosts gRPC API call and provide the following in the request:
- {{ mmg-name }} cluster ID in the
clusterId
parameter. To find out the cluster ID, get a list of clusters in the folder. - Host name, in the
hostNames
parameter. To find out the name, get a list of hosts in the cluster.
- {{ mmg-name }} cluster ID in the
{% endlist %}