banner
RustyNail

RustyNail

coder. 【blog】https://rustynail.me 【nostr】wss://ts.relays.world/ wss://relays.world/nostr

Running Docker, starting MongoDB in Replicate Set mode.

There is currently a standalone MongoDB running in Docker, and now it needs to read its oplog, so it needs to enable the replSet mode.

1. Shutdown#

Copy the data directory for backup.

2. Modify the docker-compose file#

 mongodb:
    command: mongod --replSet rs -f /etc/mongod.conf
    volumes:
        - ./mongod.conf:/etc/mongod.conf
        - ./mongo.keyfile:/etc/mongo.keyfile
  • Add --replSet rs and -f parameters to specify the running mode as rs and the location of the configuration file.

  • Specify the locations of the configuration file and key file.

3. mongod.conf configuration file#

Specify the data location and keyfile location in the file.

storage:
  dbPath: /data/db
  journal:
    enabled: true
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

security:
  authorization: enabled
  keyFile: /etc/mongo.keyfile

4. mongo.keyfile#

Generate the content of the keyfile using the openssl tool.

openssl rand -base64 756 > mongo.keyfile

Set permissions:

chmod 400 mongo.keyfile

Set user:

chown 999:999 mongo.keyfile

Otherwise, permission errors such as permission too open will occur, and MongoDB will not start.

5. Start mongo#

Enter the client of the mongo container.

rs.initiate({ _id: "rs", members: [{_id:0,host:"ip:port"}]}

Initialize

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.