mongosync ユーティリティは、 MongoDBクラスター間の接続を作成します。mongosync は次のいずれかのクラスターに接続できます。
MongoDB Atlas のホストされたクラスター
自己管理型クラスターと Atlas ホスト型クラスター
このページでは、 MongoDB Mongosync を使用して、自己管理型クラスターを Atlas クラスターに接続する手順を説明します。
Atlas クラスターへの接続の詳細については、「データベース配置への接続」を参照してください。
注意
最高のパフォーマンスを得るには、移行の前に、 自己管理型クラスター上の を最新の MongoDB Server パッチ リリースにアップグレードしてください。 詳細については、「 MongoDB の最新の自己管理型パッチ リリースへのアップグレード 」を参照してください。
接続文字列
mongosync は、 MongoDB URI接続文字列を使用して、自己管理型クラスターに接続します。
SRV 接続スキームの形式は次のとおりです。
mongodb+srv://[username:password@][host.domain.TLD][/defaultauthdb][?options] 標準の URI 接続スキームの形式は次のとおりです。
mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]
mongodレプリカセット構成にリストされているのと同じ方法で インスタンスのホスト名を指定します。
シャーディングされたクラスターの場合は、 インスタンスではなく、mongos mongodインスタンスのホスト名を指定します。
注意
mongosync にはreplicaSet オプションは必要ありません。
mongosync は、 MongoDB URI接続文字列を使用して Atlas クラスターに接続します。
SRV 接続スキームの形式は次のとおりです。
mongodb+srv://[username:password]@[clusterName].[host].mongodb.net/ Atlas で SRV接続文字列を見つける方法の詳細については、「 クラスターへの接続 」を参照してください。
標準の URI 接続スキームの形式は次のとおりです。
mongodb://[username:password]@[clusterName].[host].mongodb.net/
mongosync では、ソースクラスターと宛先クラスターに接続するには 読み込み設定 (readprimary preference)が必要です。詳しくは、「 読み込み設定(read preference)オプション 」を参照してください。
認証
MongoDB Atlasクラスターに接続するための有効な認証を提供します。 Atlasデータベースユーザー がまだない場合は、ユーザーを作成する必要があります。
ソースクラスターまたは宛先クラスターのいずれかに認証が必要な場合は、 mongosyncを呼び出すときに正しい認証情報を指定する必要があります。
ロール
mongosync接続文字列で指定されたユーザーには、ソースクラスターと宛先クラスターで必要な権限が必要です。権限は、環境と逆同期を使用するかどうかによって異なります。
ソースクラスターの自己管理型権限は次のとおりです。
同期タイプ | 必要なソース権限 |
|---|---|
default | |
二重書込みブロック | |
元に戻す | |
複数の反転 |
サーバーロールの詳細については、「 自己管理型配置でのロールベースのアクセス制御 」を参照してください。
ユーザー権限を更新するには、grantRolesToUser を参照してください。
宛先クラスターの Atlas 権限は次のとおりです。
同期タイプ | 必要な宛先権限 |
|---|---|
default |
|
二重書込みブロック、元対応、または複数元の逆 |
|
Atlas ロールの詳細については、「 Atlas ユーザーロール 」を参照してください。
Atlas ユーザー権限を更新するには、「 プロジェクトへのアクセス権の管理 」を参照してください。
During synchronization, mongosync uses the setUserWriteBlockMode command to block writes on the destination cluster. The database user that mongosync uses to connect to the destination cluster must have both of the following actions at the same time:
setUserWriteBlockMode, which allowsmongosyncto run the command that blocks writes.bypassWriteBlockingMode, which allowsmongosyncto keep writing to the destination while writes are blocked.
If either action is missing, mongosync stops and reports the missing privileges.
atlasAdmin is a built-in role, and these two actions are privilege actions, not roles. To grant them, create a custom role that includes both actions and assign the custom role to the database user.
To create the custom role and assign it to the database user:
カスタムロールを作成します。
[Custom Roles] タブをクリックします。
Add New Custom Role をクリックします。
For Custom Role Name, enter a name such as
mongosyncWriteBlocking.In the Action or Role dropdown menu, select the
setUserWriteBlockModeaction. Click Add an action or role and select thebypassWriteBlockingModeaction.[Add Custom Role] をクリックします。
To create the custom role, run the following command:
atlas customDbRoles create mongosyncWriteBlocking \ --privilege SET_USER_WRITE_BLOCK,BYPASS_USER_WRITE_BLOCK
To assign the custom role to the database user, run the following command. The --role option replaces the user's existing roles, so list the roles that the user already has along with the custom role. For example, to keep the atlasAdmin role:
atlas dbusers update <username> \ --role atlasAdmin,mongosyncWriteBlocking
動作
ホスティング
mongosyncユーティリティは、ソースクラスターまたは宛先クラスターのいずれかに近いハードウェアでホストできます。クラスター内のmongod またはmongos インスタンスのいずれかと同じサーバーでホストされている必要はありません。この柔軟性により、宛先クラスターにデータをプッシュまたはプルして、ここで実行中mongod またはmongos インスタンスへの影響を最小限に抑えることができます。
初期状態
mongosyncが接続すると、 IDLE状態になります。 同期を開始するには、 startコマンドを発行する必要があります。
制限
mongosyncM10+Atlas クラスターでRequire Indexes for All Queries notablescanの実行を試みる前に、false オプションを無効にして、ソースクラスターと宛先クラスターの両方で を に設定します。
例
接続情報の収集
ソースクラスターcluster0は、次のサーバーとポートでホストされています。
clusterOne01.fancyCorp.com:20020clusterOne02.fancyCorp.com:20020clusterOne03.fancyCorp.com:20020
宛先 Atlas クラスターであるcluster1は、次のサーバーとポートでホストされています。
cluster2Name-01.abc123.com:27017cluster2Name-02.abc123.com:27017cluster2Name-03.abc123.com:27017
各クラスターには管理ユーザーclusterAdminが設定されており、パスワードsuperSecretが使用されます。
を使用したソースクラスターと宛先クラスターの接続 mongosync
自己管理型クラスターの一般的な接続文字列形式は次のとおりです。
mongodb://<user>:<password>@<ip-address>:<port>,<ip-address>:<port>,<ip-address>:<port>
クラスターの一般的な接続文字列 Atlas 形式は次のとおりです。
mongodb://<user>:<password>@<clusterName>.<hostname>.mongodb.net/
自己管理型クラスター用に収集した接続情報を使用して、 cluster0の接続文字列を作成します。
cluster0: mongodb://clusterAdmin:superSecret@clusterOne01.fancyCorp.com:20020,clusterOne02.fancyCorp.com:20020,clusterOne03.fancyCorp.com:20020
MongoDB Atlas クラスターの接続文字列は、 Atlas UIから取得できます。詳細については、「 データベース配置への接続 」を参照してください。
以下の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@cluster2Name.abc123.mongodb.net"
Atlas クラスターには TLS 接続が必要です。mongosync Atlas クラスターで を使用するには、tls=true オプションを追加します。例admin cluster0を、 と のcluster1 データベースに接続するには、次のようにします。
mongosync \ --cluster0 "mongodb://clusterAdmin:superSecret@clusterOne01.fancyCorp.com:20020,clusterOne02.fancyCorp.com:20020,clusterOne03.fancyCorp.com:20020/admin?tls=true" \ --cluster1 "mongodb://clusterAdmin:superSecret@cluster2Name.abc123.mongodb.net/admin?tls=true"
mongodb+srvmongosyncでは 接続文字列を使用することもできます。tls=true mongodb+srv接続文字列に オプションを追加する必要はありません。 (例: )。
mongosync \ --cluster0 "mongodb+srv://clusterAdmin:superSecret@clusterOne01.fancyCorp.com/" \ --cluster1 "mongodb+srv://clusterAdmin:superSecret@cluster2Name.abc123.mongodb.net/"
mongodb+srv接続文字列の詳細については、 SRV 接続形式 を参照してください。