Docs Menu
Docs Home
/
データベース マニュアル
/ / /

Deploy a Replica Set with Keyfile Authentication for mongot

This procedure guides you through setting up a mongod locally in order to complete the Install MongoDB Search and MongoDB Vector Search Tarball installation tutorial.

注意

If you already have a replica set with keyfile authentication set up, you can skip this procedure.

1

キーファイル認証では、レプリカセット内の各 mongod インスタンスは、配置内の他のノードを認証するための共有パスワードとしてキーファイルの内容を使用します。正しいキーファイルを持つ mongod のインスタンスのみがレプリカセットに参加できます。

注意

内部メンバーシップ認証用のキーファイルでは、キーファイル内に複数のキーを含めるために YAML 形式が使用されます。YAML 形式は次のいずれかを受け入れます。

  • 1 つのキー文字列(以前のバージョンと同じ)

  • キー文字列のシーケンス

YAML 形式は、テキストファイル形式を使用する既存の単一のキー キーファイルと互換性があります。

キーの長さは 6 文字から 1024 文字の間で、base64 セット内の文字のみを含めることができます。レプリカセットのすべてのノードは、少なくとも 1 つの共通キーを共有する必要があります。

注意

UNIX システムでは、キーファイルにグループ権限またはワールド権限があってはなりません。Windows システムでは、キーファイルの権限はチェックされません。

キーファイルは、選択した任意の方法で生成できます。たとえば、次の操作では、openssl を使用して、共有パスワードとして使用する疑似ランダムの複雑な 1024 文字の文字列を生成します。次に、chmod を使用してファイル権限を変更し、ファイル所有者のみに読み取り権限を付与します。

openssl rand -base64 756 > <path/to/keyfile>
chmod 400 <path/to/keyfile>

キーファイルの使用に関する詳細と要件については、「キーファイル」を参照してください。

2

Copy the keyfile to each server hosting the replica set members. Ensure that the user running the mongod instances is the owner of the file and can access the keyfile.

Avoid storing the keyfile on storage mediums that can be easily disconnected from the hardware that hosts the mongod instances, such as a USB drive or a network attached storage device.

3

To create your configuration file, save the following code to mongod.conf or your preferred location.

# MongoDB Configuration File
# Network configuration
net:
port: 27017
bindIpAll: true # Equivalent to --bind_ip_all
# Replica set configuration
replication:
replSetName: rs0
# Security configuration
#security:
# authorization: enabled # Equivalent to --auth
# keyFile: </path/to/keyfile>
# Search configuration parameters
setParameter:
mongotHost: localhost:27027
searchIndexManagementHostAndPort: localhost:27027
# Process management configuration
processManagement:
fork: true
# Logging configuration
systemLog:
destination: file
path: /var/log/mongodb/mongod.log
logAppend: true
4

To start the mongod, run the following command, specifying the configuration file you created above:

./mongod --config mongod.conf
5

Use mongosh to connect to the primary node with this command:

mongosh --port 27017
6

To create an admin user on your mongod, run the following commands, replacing <password> with the desired password for the myAdmin user:

use admin
db.createUser(
{
user: "myAdmin",
pwd: "<password>",
roles: [
{
role: "root",
db: "admin"
}
]
}
)

For details, see Create a User-Defined Role.

7

Use the rs.initiate() method to initiate your replica set. For details, see this example.

8

To exit mongosh, run:

exit
9

Uncomment the following lines in the mongod.conf file you created in Create your mongod configuration file. Replace </path/to/keyfile> with the path to the keyfile you created in Create your keyfile.

security:
authorization: enabled # Equivalent to --auth
keyFile: </path/to/keyfile>
10

To start mongod with keyfile authentication, specify the config file that you created in Create your mongod configuration file and updated throughout the procedure.

./mongod --config mongod.conf

戻る

Connect to Search