rs.conf()メソッドまたはreplSetGetConfigコマンドを使用して、レプリカセットの構成にアクセスできます。
レプリカセットの構成を変更するには、rs.reconfig() メソッドを使用して、構成ドキュメントをメソッドに渡します。
警告
MongoDB のバージョンによって検証ルールが異なる可能性があるため、異なるバージョンの MongoDB のノードを含むレプリカセットの再設定は避けてください。
レプリカセット構成ドキュメントの例
次のドキュメントは、レプリカセット構成ドキュメントの表現を示しています。お使いのレプリカセットの構成には、以下の設定の一部しか含まれていない場合があります。
{ _id: <string>, version: <int>, term: <int>, protocolVersion: <number>, writeConcernMajorityJournalDefault: <boolean>, configsvr: <boolean>, members: [ { _id: <int>, host: <string>, arbiterOnly: <boolean>, buildIndexes: <boolean>, hidden: <boolean>, priority: <number>, tags: <document>, secondaryDelaySecs: <int>, votes: <number> }, ... ], settings: { chainingAllowed : <boolean>, heartbeatIntervalMillis : <int>, heartbeatTimeoutSecs: <int>, electionTimeoutMillis : <int>, catchUpTimeoutMillis : <int>, getLastErrorModes : <document>, getLastErrorDefaults : <document>, replicaSetId: <ObjectId> } }
レプリカセット構成フィールド
_id型: string
レプリカセットの名前です。
_idは、replication.replSetNameまたはコマンドラインでmongodに指定された--replSetの値と同一である必要があります。Tip
レプリカセット名の設定については、
replSetNameまたは--replSetを参照してください。
versionタイプ: int
レプリカセット構成ドキュメントの改訂版を前の構成と区別するため、数字を 1 つずつ増やします。
Replica set members use
termandversionto achieve consensus on the "newest" replica configuration. When members compare replica configuration documents, the configuration document with a largertermis considered the "newest". Iftermis the same or absent, the configuration document with the largerversionis considered "newest".
termタイプ: int
機能の互換性バージョン(FCV)「4.4」以降でのみ使用可能です。
An incrementing number used to distinguish revisions of the replica set configuration document from previous iterations of the configuration. The
termof a configuration document matches the term of the replica set primary which performed the reconfiguration. The primary increments its term each time it steps up after winning an election. The primary ignores thetermfield if set explicitly in thereplSetReconfigoperation.Issuing a force reconfiguration removes the
termfield. When the primary next issuesreplSetReconfigwithout force, it sets thetermto its own term.Replica set members use
termandversionto achieve consensus on the "newest" replica configuration. When members compare replica configuration documents, the configuration document with a largertermis considered the "newest". Iftermis the same or absent, the configuration document with the largerversionis considered "newest".
configsvrタイプ: ブール値
デフォルト: false
レプリカセットがシャーディングされたクラスターのコンフィギュレーションサーバーに使用されるかどうかを示します。レプリカセットがシャーディングされたクラスターのコンフィギュレーションサーバー用である場合は、
trueに設定します。
protocolVersionタイプ: 数値
デフォルト: 1
MongoDB は
protocolVersion: 1のみをサポートし、protocolVersion: 0はサポートしなくなりました。
writeConcernMajorityJournalDefaultタイプ: ブール値
デフォルト: true
書込み保証 (write concern) でジャーナル オプション j が明示的に指定されていない場合の、
{ w: "majority" }書込み保証 (write concern) の動作を決定します。次の表に、
writeConcernMajorityJournalDefaultの値と、それに対応する{ w: "majority" }の動作を示します。値{ w: "majority" }動作true
MongoDB は、投票権を持つノードの過半数がディスク上のジャーナルに書込んだ後、書込み (write) 操作に確認応答を返します。
重要:
writeConcernMajorityJournalDefaultがtrueの場合、投票権を持つレプリカセットの全ノードはジャーナリングを実行する必要があります。If any voting member of a replica set uses the in-memory storage engine, you must set
writeConcernMajorityJournalDefaulttofalse.If any voting member of a replica set uses the in-memory storage engine and
writeConcernMajorityJournalDefaultistrue,"majority"write operations may fail. These include operations that inherently use"majority"write concern, such as thereplSetStepDowncommand, or variousmongoshmethods that by default use"majority"write concern, such as user management methods and role management methods.バージョン4.2 以降(および4.0.13 および3.6.14 )、レプリカセットのメンバーが、 インメモリストレージエンジンを使用しているものの(投票または非投票)、レプリカセットの が
writeConcernMajorityJournalDefaulttrue に設定されている場合、レプリカセットノードはスタートアップ警告をログに記録します。false
MongoDB は、投票権を持つノードの過半数がメモリ内で操作を適用した後で、書込み (write) 操作に確認応答を返します。
警告:If any voting member of a replica set uses the in-memory storage engine, you must set
writeConcernMajorityJournalDefaulttofalse.Starting in version 4.2 (and 4.0.13 and 3.6.14 ), if a replica set member uses the in-memory storage engine (voting or non-voting) but the replica set has
writeConcernMajorityJournalDefaultset to true, the replica set member logs a startup warning.You cannot run transactions on a sharded cluster that has a shard with
writeConcernMajorityJournalDefaultset tofalse(such as a shard with a voting member that uses the in-memory storage engine).
members
membersタイプ: 配列
An array of member configuration documents, one for each member of the replica set. The
membersarray is a zero-indexed array.各ノード固有の構成ドキュメントには、次のフィールドを含めることができます。
members[n]._idタイプ: 整数
レプリカセット内のノードの整数識別子です。すべてのノード間で一意です。
MongoDB 5.0 以降では、値は
0以上の任意の整数値にできます。以前は、この値は0から255までの整数に制限されていました。Each replica set member must have a unique
_id. Avoid re-using_idvalues even if nomembers[n]entry is using that_idin the current configuration.Once set, you cannot change the
_idof a member.注意
When updating the replica configuration object, access the replica set members in the
membersarray with the array index. The array index begins with0. Do not confuse this index value with the value of themembers[n]._idfield in each document in themembersarray.
members[n].host型: string
セットのノードのホスト名と、指定されている場合はポート番号。
ホスト名は、レプリカセット内のすべてのホストで解決可能である必要があります。
警告
members[n].hostcannot hold a value that resolves tolocalhostor the local interface unless all members of the set are on hosts that resolve tolocalhost.
members[n].arbiterOnly任意。
タイプ: ブール値
デフォルト: false
アービタを指定するブール値です。値
trueは、ノードがアービタであることを示します。When using the
rs.addArb()method to add an arbiter, the method automatically setsmembers[n].arbiterOnlytotruefor the added member.
members[n].buildIndexes任意。
タイプ: ブール値
デフォルト: true
A boolean that indicates whether the
mongodbuilds indexes on this member. You can only set this value when adding a member to a replica set. You cannot changemembers[n].buildIndexesfield after the member has been added to the set. To add a member, seers.add()andrs.reconfig().クライアントからクエリを受信する
mongodインスタンスの場合はfalseに設定しないでください。次の条件がすべて当てはまる場合は、
buildIndexesをfalseに設定すると便利な場合があります。you are only using this instance to perform backups using
mongodump, andこのノードはクエリを受け取らない。
インデックスの作成とメンテナンスが、ホスト システムに過度の負担をかける。
falseに設定しても、レプリケーションに必要な操作を容易にするために、セカンダリは_idフィールドにインデックスを構築します。警告
If you set
members[n].buildIndexestofalse, you must also setmembers[n].priorityto0. Ifmembers[n].priorityis not0, MongoDB will return an error when attempting to add a member withmembers[n].buildIndexesequal tofalse.ノードがクエリを受け取らないようにするには、インデックスを構築しないインスタンスをすべて隠ぺいする必要があります。
Other secondaries cannot replicate from a member where
members[n].buildIndexesis false.
members[n].hidden任意。
タイプ: ブール値
デフォルト: false
この値が
trueの場合、レプリカセットはこのインスタンスを隠ぺいし、db.hello()またはhelloの出力にノードを含めません。こうすることで、セカンダリの読み込み設定 (read preference) によって読み取り操作(つまり、クエリ)がこのホストするに到達することを防止できます。Hidden members can acknowledge write operations issued with Write Concern. For write operations issued with
"majority"write concern, the member must also be a voting member (that is,votesis greater than0).
members[n].priority任意。
型: プライマリ/セカンダリ ノードの場合は 0 から 1000 までの数値、アービタの場合は 0 または 1 の数値。
デフォルト: プライマリ/セカンダリのノードの場合は 1.0、アービタの場合は 0。
レプリカセットがプライマリになる相対的な可能性を示す数値。
ノードがプライマリになる可能性を高めるには、そのノードの
priority値を高く指定します。ノードがプライマリになる可能性を減らすには、そのノードの
priority値を低く指定します。
ノードの優先順位を変更すると、1 つ以上の選挙がトリガーされます。選挙アルゴリズムは、最も優先順位が高いノードをプライマリに選出するために最善を尽くします。しかし、優先順位の高いセカンダリが使用できる場合でも、優先順位の低いノードがプライマリになる場合があります。
優先順位の低いノードがプライマリになると、サーバーは最も優先順位の高いレプリカセットがプライマリになるまで、定期的に選挙を呼び出します。選挙が行われる頻度は、選出されたノードと最も優先順位の高いノードとの間の優先順位の違いによって決まります。
優先順位が
0のノードがプライマリになることはできません。Non-voting members (meaning members that have
votesset to0) must have a priority of0.Tip
members[n].tags任意。
型: ドキュメント
デフォルト: なし
tagsドキュメントには、レプリカセットのユーザー定義タグ フィールドと値のペアが含まれています。{ "<tag1>": "<string1>", "<tag2>": "<string2>",... } 読み取り操作では、読み込み設定 (read preference) でタグセットを指定して、指定したタグを持つレプリカセットに操作を指示できます。
For write operations, you can create a customize write concern using
settings.getLastErrorModesandsettings.getLastErrorDefaults.
詳しくは、「レプリカセットのタグセットの構成」を参照してください。
members[n].secondaryDelaySecs任意。
タイプ: 整数
デフォルト: 0
このレプリカセットがプライマリから "遅れる" 秒数。
遅延ノードを作成するにはこのオプションを使用します。遅延ノードは、過去のある時点におけるデータの状態を反映したデータのコピーを保持します。
Delayed members can contribute to acknowledging write operations issued with Write Concern. However, they return write acknowledgment no earlier than the configured delay value. For write operations issued with
"majority"write concern, the member must also be a voting member (that is,votesis greater than0).Tip
members[n].votes任意。
タイプ: 整数
デフォルト: 1
レプリカセット選挙においてサーバーが投じる投票数です。各ノードが持つ投票数は
1または0で、アービタ は常にちょうど1票を持ちます。が より大きいメンバーは、
priority00votesを持つことはできません。レプリカセットには最大50 7メンバーを含めることができますが、投票メンバーは メンバーのみです。7 1 つのレプリカセットに を超えるノードが必要な場合は、追加の投票権のないノードのために
members[n].votesから0を設定します。投票権のない(すなわち
votesが0の)メンバーは、priorityの0 を持っている必要があります。MongoDB 5.0 以降では、新しく追加されたセカンダリは投票権のあるノードとしてカウントされず、
SECONDARY状態に達するまで選出されません。投票権のないノードは、
"majority"書込み保証 (write concern) 付きで発行された書込み (write) 操作に確認応答できません。
settings
settings任意。
型: ドキュメント
レプリカセット全体に適用される構成オプションを含むドキュメントです。
The
settingsdocument contains the following fields:settings.chainingAllowed任意。
タイプ: ブール値
デフォルト: true
MongoDB5.0.1 以前で、 が次の場合。
settings.chainingAllowedMongoDB 5.0.2 以降
With an override enabled, replica set secondary members can replicate data from other secondary members even if
settings.chainingAllowedisfalse.To override
settings.chainingAllowedand allow replication from a secondary member, set theenableOverrideClusterChainingSettingserver parameter totrue.enableOverrideClusterChainingSettingのデフォルトはfalseです。
settings.getLastErrorDefaults任意。
型: ドキュメント
MongoDB 5.0 以降では使用できません。
重要
MongoDB5.0 以降では、デフォルトの 以外の でデフォルトの書込み保証 (write concern)を指定することはできません。代わりに、
settings.getLastErrorDefaults{ w: 1, wtimeout: 0 }setDefaultRWConcernコマンドを使用して、レプリカセットまたはシャーディングされたクラスターのデフォルトの読み取りまたは書込み保証 (write concern)を設定します。
settings.getLastErrorModes任意。
型: ドキュメント
A document used to define a custom write concern through the use of
members[n].tags. The custom write concern can provide data-center awareness.{ getLastErrorModes: { <name of write concern> : { <tag1>: <number>, .... }, ... } } The
<number>refers to the number of different tag values required to satisfy the write concern. For example, the followingsettings.getLastErrorModesdefines a write concern nameddatacenterthat requires the write to propagate to two members whosedctag values differ.{ getLastErrorModes: { datacenter: { "dc": 2 } } } カスタム書込み保証 (write concern) を使用するには、書込み保証名を書込み保証 (write concern) 内の
wオプションに渡します。例:{ w: "datacenter" } 詳細と例については、「レプリカセットのタグセットの構成」を参照してください。
settings.heartbeatTimeoutSecs任意。
タイプ: int
デフォルト: 10
レプリカセットがお互いのハートビートが成功するまで待つ秒数です。あるノードが時間内に応答しない場合、他のノードは期限を過ぎたそのノードをアクセス不可としてマークします。
settings.electionTimeoutMillis任意。
タイプ: int
デフォルト: 10000(10 秒)
The time limit in milliseconds for detecting when a replica set's primary is unreachable. This setting controls failover sensitivity when using
protocolVersion: 1. You can expect the failover timeout to not exceed the value ofelectionTimeoutMillis.値を選択する際には、次の点を考慮してください。
値が大きいほどフェイルオーバーは遅くなりますが、プライマリ ノードやネットワークの速度低下やむらの影響を受けにくくなります。
値が小さいほどフェイルオーバーは速くなりますが、プライマリ ノードやネットワークの速度低下やむらの影響を受けやすくなります。
The setting only applies when using
protocolVersion: 1.注意
forceフィールドをtrueに設定せずにrs.stepDown()またはreplSetStepDownを使用してプライマリを降格すると、降格したプライマリは、選挙を直ちに呼び出す資格のあるセカンダリを指名します。
settings.catchUpTimeoutMillis任意。
タイプ: int
デフォルト: -1、キャッチアップ時間は無限。
新たに選出されたプライマリが、より新しい書込み (write) を行った可能性のある他のレプリカセットと同期(キャッチアップ)するまでの時間制限(ミリ秒単位)です。時間制限が無限の場合や長い場合には、選挙後に他のノードがロールバックする必要のあるデータ量は減りますが、フェイルオーバー時間は長くなる可能性があります。
新たに選出されたプライマリは、セットの他のノードに完全に追いつくと、キャッチアップ期間を早く終了します。キャッチアップ期間中は、新しく選出されたプライマリはクライアントからの書込み (write) に対応できません。キャッチアップを中止してプライマリへの移行を完了するには、
replSetAbortPrimaryCatchUpを使用します。The setting only applies when using
protocolVersion: 1.
settings.catchUpTakeoverDelayMillis任意。
タイプ: int
デフォルト: 30000(30 秒)
ノードが現在のプライマリよりも進んでいると判断した後、キャッチアップ引き継ぎの開始を待つ時間(ミリ秒単位)です。キャッチアップ引き継ぎ中、現在のプライマリの進んだノードがレプリカセットの新しいプライマリになるための選挙を開始します。
引き継ぎを開始したノードが現在のプライマリよりも先行していると判断した後、指定されたミリ秒数待機してから、次のことを確認します。
まだ現在のプライマリよりも進んでいること
利用可能な全ノードの中で最新のノードであること
現在のプライマリが現在、そのノードをキャッチアップしていること
これらの条件をすべて満たしていると判断すると、引き継ぎを開始したノードは直ちに選挙に立候補します。
レプリカセット選挙の詳細については、「レプリカセット選挙」を参照してください。
注意
Setting
catchUpTakeoverDelayMillisto-1disables catchup takeover. SettingcatchUpTimeoutMillisto0disables primary catchup and consequently also catchup takeover.
settings.replicaSetId型: ObjectId
The ObjectId associated with the replica set and automatically created during
rs.initiate()orreplSetInitiate. You cannot change thereplicaSetId.