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.

Nota

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

1

Con la autenticación keyfile, cada instanciasmongod del set de réplicas utiliza el contenido del keyfile como contraseña compartida para autenticar a otros miembros en la implementación. Solo mongod instancias con el archivo de clave correcto pueden unirse al set de réplicas.

Nota

Los archivos de claves para la autenticación interna de miembros utilizan el formato YAML para permitir múltiples claves en un archivo de claves. El formato YAML acepta:

  • Una string de clave única (igual que en versiones anteriores)

  • Una secuencia de cadenas clave

El formato YAML es compatible con los archivos de claves de una sola clave existentes que utilizan el formato de archivo de texto.

La longitud de una clave debe estar entre 6 y 1024 caracteres y solo puede contener caracteres del conjunto base64. Todos los miembros del set de réplicas deben compartir al menos una clave común.

Nota

En los sistemas UNIX, el archivo de claves no debe tener permisos de grupo ni de otros. En los sistemas Windows, no se verifican los permisos de los archivos de claves.

Se puede generar un archivo de claves utilizando cualquier método que se elija. Por ejemplo, la siguiente operación utiliza openssl para generar un string de caracteres complejo pseudoaleatorio de 1024 caracteres que se utilizará como contraseña compartida. Luego utiliza chmod para cambiar los permisos del archivo para proporcionar permisos de lectura solo al propietario del archivo:

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

Consultar Keyfiles para obtener más información y requisitos para el uso de los keyfiles.

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

Para crear el archivo de configuración, se debe guardar el siguiente código en mongod.conf o en la ubicación de preferencia.

# 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

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

7

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"
}
]
}
)

Para más información, consulte Crear un Rol Definido por el Usuario.

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

Volver

Conectarte a la búsqueda