Sobre esta tarefa
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.
Observação
If you already have a replica set with keyfile authentication set up, you can skip this procedure.
Passos
Create your keyfile.
Com a autenticação do arquivo-chave, cada instância do mongod
no conjunto de réplicas utiliza o conteúdo do arquivo-chave como a senha compartilhada para autenticar outros membros no sistema. Somente instâncias mongod
com o arquivo-chave correto podem entrar no conjunto de réplicas.
Observação
Os arquivos de chaves para autenticação de associação interna usam o formato YAML para permitir várias chaves em um só arquivo. O formato YAML aceita:
Uma única string de chave (igual às versões anteriores)
Uma sequência de strings de chave
O formato YAML é compatível com os arquivos-chave de chave única existentes que usam o formato de arquivo de texto.
O comprimento de uma chave deve ter entre 6 e 1024 caracteres e só pode conter caracteres no conjunto base64. Todos os membros do conjunto de réplicas devem compartilhar pelo menos uma chave comum.
Observação
Em sistemas UNIX, o arquivo-chave não deve ter permissões de grupo ou mundiais. Em sistemas Windows, as permissões do arquivo-chave não são verificadas.
Você pode gerar um arquivo-chave usando qualquer método de sua escolha. Por exemplo, a operação a seguir usa openssl
para gerar uma cadeia complexa pseudo-aleatória de 1024 caracteres para ser usada como senha compartilhada. Em seguida, ele usa chmod
para alterar as permissões do arquivo e fornecer permissões de leitura somente para o proprietário do arquivo:
openssl rand -base64 756 > <path/to/keyfile> chmod 400 <path/to/keyfile>
Consulte Keyfiles para obter detalhes adicionais e requisitos para usar keyfiles.
Copy the keyfile.
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.
Create your mongod configuration file.
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
Create your admin user.
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.
Initiate your replica set.
Use the rs.initiate()
method to initiate your replica set. For details, see this example.
Update your config file to point to your keyfile.
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>
Restart mongod with keyfile authentication.
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