mongosync ユーティリティは、 MongoDBクラスター間の接続を作成します。mongosync は次のいずれかのクラスターに接続できます。
MongoDB Atlas のホストされたクラスター
自己管理型クラスターと Atlas ホスト型クラスター
このページでは、 MongoDB Mongosync を使用して自己管理型クラスターを接続する手順を説明します。
注意
最高のパフォーマンスを得るには、移行の前に、ソースクラスターと宛先クラスターを最新のMongoDB Serverパッチ リリースにアップグレードしてください。詳細については、MongoDBの最新の自己管理型パッチ リリースへのアップグレード を参照してください。
接続文字列
mongosync は、 MongoDB URI 接続文字列を使用してクラスターを接続します。
SRV 接続スキームの形式は次のとおりです。
mongodb+srv://[username:password@][host.domain.TLD][:port][/defaultauthdb][?options] 標準の URI 接続スキームの形式は次のとおりです。
mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]
Specify the hostnames of the mongod instances the same way that they are listed in your replica set configuration.
シャーディングされたクラスターの場合は、 インスタンスではなく、mongos mongodインスタンスのホスト名を指定します。
注意
mongosync does not require the replicaSet option.
mongosync では、ソースクラスターと宛先クラスターに接続するには、 読み込み設定 (readprimary preference)が必要です。詳しくは、「 読み込み設定(read preference)オプション 」を参照してください。
認証
ソースクラスターまたは宛先クラスターのいずれかに認証が必要な場合は、 mongosyncを呼び出すときに正しい認証情報を指定する必要があります。
ロール
mongosync接続文字列で指定されたユーザーには、ソースクラスターと宛先クラスターで必要な権限が必要です。権限は、環境と逆同期を使用するかどうかによって異なります。
自己管理型権限は次のとおりです。
同期タイプ | 必要なソース権限 | 必要な宛先権限 |
|---|---|---|
default | ||
元に戻す | ||
複数の反転 |
サーバーロールの詳細については、「自己管理型配置でのロールベースのアクセス制御」を参照してください。
ユーザー権限を更新するには、grantRolesToUser を参照してください。
動作
ホスティング
The mongosync utility can be hosted on its own hardware close to either the source or destination cluster. It does not have to be hosted on the same server as one of the mongod or mongos instances in the cluster. This flexibility allows you to push, or pull, data to the destination cluster with minimal impact on the mongod or mongos instances running there.
初期状態
mongosyncが接続すると、 IDLE状態になります。 同期を開始するには、 startコマンドを発行する必要があります。
例
接続情報の収集
ソースクラスターcluster0は、次のサーバーとポートでホストされています。
clusterOne01.fancyCorp.com:20020
clusterOne02.fancyCorp.com:20020
clusterOne03.fancyCorp.com:20020
宛先クラスターcluster1は、次のサーバーとポートでホストされています。
clusterTwo01.fancyCorp.com:20020
clusterTwo02.fancyCorp.com:20020
clusterTwo03.fancyCorp.com:20020
各クラスターには管理ユーザーclusterAdminが設定されており、パスワードsuperSecretが使用されます。
を使用したソースクラスターと宛先クラスターの接続 mongosync
一般的な接続文字列の形式は次のとおりです。
mongodb://<user>:<password>@<ip-address>:<port>,<ip-address>:<port>,<ip-address>:<port>
収集した接続情報を使用して、 cluster0とcluster1の接続文字列を作成します。
cluster0: mongodb://clusterAdmin:superSecret@clusterOne01.fancyCorp.com:20020,clusterOne02.fancyCorp.com:20020,clusterOne03.fancyCorp.com:20020 cluster1: mongodb://clusterAdmin:superSecret@clusterTwo01.fancyCorp.com:20020,clusterTwo02.fancyCorp.com:20020,clusterTwo03.fancyCorp.com:20020
以下のmongosyncコマンドのレイアウトは表示用に変更されています。 mongosyncを使用してcluster0をcluster1に接続するには、次のコマンドを 1 行で入力します。
mongosync \ --cluster0 "mongodb://clusterAdmin:superSecret@clusterOne01.fancyCorp.com:20020,clusterOne02.fancyCorp.com:20020,clusterOne03.fancyCorp.com:20020" \ --cluster1 "mongodb://clusterAdmin:superSecret@clusterTwo01.fancyCorp.com:20020,clusterTwo02.fancyCorp.com:20020,clusterTwo03.fancyCorp.com:20020"
mongodb+srvmongosyncでは 接続文字列を使用することもできます。tls=true オプションをmongodb+srv 接続文字列に追加する必要はありません。 (例: )。
mongosync \ --cluster0 "mongodb+srv://clusterAdmin:superSecret@clusterOne01.fancyCorp.com/" \ --cluster1 "mongodb+srv://clusterAdmin:superSecret@clusterTwo01.fancyCorp.com/"
mongodb+srv接続文字列の詳細については、 SRV 接続形式 を参照してください。