Skip to content

Is my Mongodb installation correct?

Solved General
27 2 7.8k 1
  • @ahmed before you can enable authorization, a valid admin user needs to exist in the database. Try disabling the authorization for the time being, restart MongoDB and then see if you can login.

    I expect this will work, but once you are able to login, put the authorization back, restart MongoDB and then try it again.

    For more information, see

    https://www.mongodb.com/docs/manual/tutorial/configure-scram-client-authentication/#create-the-user-administrator

    @phenomlab

    root@localhost:~# sudo systemctl status mongod
    × mongod.service - MongoDB Database Server
         Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
         Active: failed (Result: exit-code) since Sat 2024-03-23 21:55:25 +03; 58s ago
           Docs: https://docs.mongodb.org/manual
        Process: 62746 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=14)
       Main PID: 62746 (code=exited, status=14)
            CPU: 60ms
    
    Mar 23 21:55:25 localhost systemd[1]: Started MongoDB Database Server.
    Mar 23 21:55:25 localhost mongod[62746]: {"t":{"$date":"2024-03-23T18:55:25.275Z"},"s":"I",  "c":"CONTROL",  "id":7484500, "ctx":"main","msg":"Environment variable MON>
    Mar 23 21:55:25 localhost systemd[1]: mongod.service: Main process exited, code=exited, status=14/n/a
    Mar 23 21:55:25 localhost systemd[1]: mongod.service: Failed with result 'exit-code'.
    
    
  • @phenomlab

    root@localhost:~# sudo systemctl status mongod
    × mongod.service - MongoDB Database Server
         Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
         Active: failed (Result: exit-code) since Sat 2024-03-23 21:55:25 +03; 58s ago
           Docs: https://docs.mongodb.org/manual
        Process: 62746 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=14)
       Main PID: 62746 (code=exited, status=14)
            CPU: 60ms
    
    Mar 23 21:55:25 localhost systemd[1]: Started MongoDB Database Server.
    Mar 23 21:55:25 localhost mongod[62746]: {"t":{"$date":"2024-03-23T18:55:25.275Z"},"s":"I",  "c":"CONTROL",  "id":7484500, "ctx":"main","msg":"Environment variable MON>
    Mar 23 21:55:25 localhost systemd[1]: mongod.service: Main process exited, code=exited, status=14/n/a
    Mar 23 21:55:25 localhost systemd[1]: mongod.service: Failed with result 'exit-code'.
    
    

    @ahmed can you post the content of /etc/mongod.conf

  • @ahmed can you post the content of /etc/mongod.conf

    @phenomlab said in Is my Mongodb installation correct?:

    /etc/mongod.conf

    # mongod.conf
    
    # for documentation of all options, see:
    #   http://docs.mongodb.org/manual/reference/configuration-options/
    
    # Where and how to store data.
    storage:
      dbPath: /var/lib/mongodb
    #  engine:
    #  wiredTiger:
    
    # where to write logging data.
    systemLog:
      destination: file
      logAppend: true
      path: /var/log/mongodb/mongod.log
    
    # network interfaces
    net:
      port: 27017
      bindIp: 127.0.0.1
    
    
    # how the process runs
    processManagement:
      timeZoneInfo: /usr/share/zoneinfo
    
    security:
      authorization: enabled
    
    #operationProfiling:
    
    #replication:
    
    #sharding:
    
    ## Enterprise-Only Options:
    
    #auditLog:
    
    
  • @phenomlab said in Is my Mongodb installation correct?:

    /etc/mongod.conf

    # mongod.conf
    
    # for documentation of all options, see:
    #   http://docs.mongodb.org/manual/reference/configuration-options/
    
    # Where and how to store data.
    storage:
      dbPath: /var/lib/mongodb
    #  engine:
    #  wiredTiger:
    
    # where to write logging data.
    systemLog:
      destination: file
      logAppend: true
      path: /var/log/mongodb/mongod.log
    
    # network interfaces
    net:
      port: 27017
      bindIp: 127.0.0.1
    
    
    # how the process runs
    processManagement:
      timeZoneInfo: /usr/share/zoneinfo
    
    security:
      authorization: enabled
    
    #operationProfiling:
    
    #replication:
    
    #sharding:
    
    ## Enterprise-Only Options:
    
    #auditLog:
    
    

    @ahmed does the database service start if you remove the below

    security:
      authorization: enabled
    
  • @ahmed does the database service start if you remove the below

    security:
      authorization: enabled
    

    @phenomlab said in Is my Mongodb installation correct?:

    does the database service start if you remove the below

    × mongod.service - MongoDB Database Server
         Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
         Active: failed (Result: exit-code) since Sun 2024-03-24 04:52:10 +03; 12s ago
           Docs: https://docs.mongodb.org/manual
        Process: 64261 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=14)
       Main PID: 64261 (code=exited, status=14)
            CPU: 50ms
    
    Mar 24 04:52:10 localhost systemd[1]: Started MongoDB Database Server.
    Mar 24 04:52:10 localhost mongod[64261]: {"t":{"$date":"2024-03-24T01:52:10.940Z"},"s":"I",  "c":"CONTROL",  "id":7484500, "ctx":"main","msg":"Environment variable MON>
    Mar 24 04:52:10 localhost systemd[1]: mongod.service: Main process exited, code=exited, status=14/n/a
    Mar 24 04:52:10 localhost systemd[1]: mongod.service: Failed with result 'exit-code'.
    
    
  • root@localhost:~# sudo chown -R mongodb:mongodb /var/lib/mongodb
    root@localhost:~# sudo chown mongodb:mongodb /tmp/mongodb-27017.sock
    root@localhost:~# sudo service mongod restart
    
    
    root@localhost:~# sudo systemctl status mongod
    ● mongod.service - MongoDB Database Server
         Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
         Active: active (running) since Sun 2024-03-24 05:27:54 +03; 12s ago
           Docs: https://docs.mongodb.org/manual
       Main PID: 64421 (mongod)
         Memory: 170.8M
            CPU: 1.279s
         CGroup: /system.slice/mongod.service
                 └─64421 /usr/bin/mongod --config /etc/mongod.conf
    
    Mar 24 05:27:54 localhost systemd[1]: Started MongoDB Database Server.
    Mar 24 05:27:54 localhost mongod[64421]: {"t":{"$date":"2024-03-24T02:27:54.700Z"},"s":"I",  "c":"CONTROL",  "id":7484500, "ctx":"main","msg":"Environment variable MON
    

    502 Bad Gateway
    nginx/1.18.0 (Ubuntu) happy ending when I log in to my website 😄

  • root@localhost:~# sudo chown -R mongodb:mongodb /var/lib/mongodb
    root@localhost:~# sudo chown mongodb:mongodb /tmp/mongodb-27017.sock
    root@localhost:~# sudo service mongod restart
    
    
    root@localhost:~# sudo systemctl status mongod
    ● mongod.service - MongoDB Database Server
         Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
         Active: active (running) since Sun 2024-03-24 05:27:54 +03; 12s ago
           Docs: https://docs.mongodb.org/manual
       Main PID: 64421 (mongod)
         Memory: 170.8M
            CPU: 1.279s
         CGroup: /system.slice/mongod.service
                 └─64421 /usr/bin/mongod --config /etc/mongod.conf
    
    Mar 24 05:27:54 localhost systemd[1]: Started MongoDB Database Server.
    Mar 24 05:27:54 localhost mongod[64421]: {"t":{"$date":"2024-03-24T02:27:54.700Z"},"s":"I",  "c":"CONTROL",  "id":7484500, "ctx":"main","msg":"Environment variable MON
    

    502 Bad Gateway
    nginx/1.18.0 (Ubuntu) happy ending when I log in to my website 😄

    @ahmed that would have been my next suggestion in relation to permissions. Glad you got it working

  • phenomlabundefined phenomlab marked this topic as a question on
  • phenomlabundefined phenomlab has marked this topic as solved on
  • @ahmed that would have been my next suggestion in relation to permissions. Glad you got it working

  • @ahmed that’s normal if you haven’t started your nodebb instance, or competed the installation yet.

  • @ahmed that’s normal if you haven’t started your nodebb instance, or competed the installation yet.

    @phenomlab
    I reset my server and set it up again.
    save as video
    Can you check if it is installed properly?
    especially the mongodb part

  • @phenomlab
    I reset my server and set it up again.
    save as video
    Can you check if it is installed properly?
    especially the mongodb part

    @ahmed can you provide me with a url I can reach the installation on? If you’d rather not place this here, you can use the PM to do so.

  • @phenomlab
    I reset my server and set it up again.
    save as video
    Can you check if it is installed properly?
    especially the mongodb part

    @ahmed thanks for the url. I’ll check this later.

  • @ahmed thanks for the url. I’ll check this later.

    @phenomlab
    Thank you for taking the time to answer my questions.

  • @phenomlab
    Thank you for taking the time to answer my questions.

    @ahmed anytime

  • @phenomlab

    What could be the reason why mongodb gives this error when trying to take a backup?

    root@localhost:~# sudo systemctl stop mongod
    root@localhost:~# sudo systemctl status mongod
    ○ mongod.service - MongoDB Database Server
         Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
         Active: inactive (dead) since Sun 2024-03-24 18:48:04 +03; 21s ago
           Docs: https://docs.mongodb.org/manual
        Process: 61116 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=0/SUCCESS)
       Main PID: 61116 (code=exited, status=0/SUCCESS)
            CPU: 2.034s
    
    Mar 24 18:47:01 localhost systemd[1]: Started MongoDB Database Server.
    Mar 24 18:47:01 localhost mongod[61116]: {"t":{"$date":"2024-03-24T15:47:01.540Z"},"s":"I",  "c":"CONTROL",  "id":7484500, "ctx":"main","msg":"Environment variable MON>
    Mar 24 18:48:04 localhost systemd[1]: Stopping MongoDB Database Server...
    Mar 24 18:48:04 localhost systemd[1]: mongod.service: Deactivated successfully.
    Mar 24 18:48:04 localhost systemd[1]: Stopped MongoDB Database Server.
    Mar 24 18:48:04 localhost systemd[1]: mongod.service: Consumed 2.034s CPU time.
    lines 1-14/14 (END)
    [6]+  Stopped                 sudo systemctl status mongod
    root@localhost:~# mongodump
    2024-03-24T18:49:15.964+0300    Failed: can't create session: failed to connect to mongodb://localhost/: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: localhost:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp 127.0.0.1:27017: connect: connection refused }, ] }
    root@localhost:~#
    root@localhost:~#
    root@localhost:~# mongodump --port 27017 -u "nodebb" -p "Em26452645" --db=nodebb --out=backup/ahmed
    2024-03-24T18:50:25.654+0300    Failed: can't create session: failed to connect to mongodb://localhost:27017/: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: localhost:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp 127.0.0.1:27017: connect: connection refused }, ] }
    root@localhost:~#
    
    
  • @phenomlab

    What could be the reason why mongodb gives this error when trying to take a backup?

    root@localhost:~# sudo systemctl stop mongod
    root@localhost:~# sudo systemctl status mongod
    ○ mongod.service - MongoDB Database Server
         Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
         Active: inactive (dead) since Sun 2024-03-24 18:48:04 +03; 21s ago
           Docs: https://docs.mongodb.org/manual
        Process: 61116 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=0/SUCCESS)
       Main PID: 61116 (code=exited, status=0/SUCCESS)
            CPU: 2.034s
    
    Mar 24 18:47:01 localhost systemd[1]: Started MongoDB Database Server.
    Mar 24 18:47:01 localhost mongod[61116]: {"t":{"$date":"2024-03-24T15:47:01.540Z"},"s":"I",  "c":"CONTROL",  "id":7484500, "ctx":"main","msg":"Environment variable MON>
    Mar 24 18:48:04 localhost systemd[1]: Stopping MongoDB Database Server...
    Mar 24 18:48:04 localhost systemd[1]: mongod.service: Deactivated successfully.
    Mar 24 18:48:04 localhost systemd[1]: Stopped MongoDB Database Server.
    Mar 24 18:48:04 localhost systemd[1]: mongod.service: Consumed 2.034s CPU time.
    lines 1-14/14 (END)
    [6]+  Stopped                 sudo systemctl status mongod
    root@localhost:~# mongodump
    2024-03-24T18:49:15.964+0300    Failed: can't create session: failed to connect to mongodb://localhost/: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: localhost:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp 127.0.0.1:27017: connect: connection refused }, ] }
    root@localhost:~#
    root@localhost:~#
    root@localhost:~# mongodump --port 27017 -u "nodebb" -p "Em26452645" --db=nodebb --out=backup/ahmed
    2024-03-24T18:50:25.654+0300    Failed: can't create session: failed to connect to mongodb://localhost:27017/: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: localhost:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp 127.0.0.1:27017: connect: connection refused }, ] }
    root@localhost:~#
    
    

    @ahmed the database needs to be running to use MongoDump.

  • @ahmed the database needs to be running to use MongoDump.

    @phenomlab

    Nodebb.org documentation states that Mongodb must be stopped before backup
    nodebb.org documentation should be updated
    I think I saw it wrong

    I will try as you say

  • @phenomlab

    Nodebb.org documentation states that Mongodb must be stopped before backup
    nodebb.org documentation should be updated
    I think I saw it wrong

    I will try as you say

    @ahmed I never stop the database when backing up. Never did it with mysql either. I’m not saying it’s right but it’s always worked for me and the backup schedules I’ve created for others who have used that to perform recovery.

  • @ahmed I never stop the database when backing up. Never did it with mysql either. I’m not saying it’s right but it’s always worked for me and the backup schedules I’ve created for others who have used that to perform recovery.

    @phenomlab

    I’m trying to take a backup while Mongodb is running, but this time it gives an authentication error.

    root@localhost:~# mongodump --port 27017 -u "nodebb" -p "Em26452645" --db=nodebb --out=backup/ahmed
    2024-03-24T19:15:41.690+0300    Failed: can't create session: failed to connect to mongodb://localhost:27017/: connection() error occurred during connection handshake: auth error: unable to authenticate using mechanism "SCRAM-SHA-256": (AuthenticationFailed) Authentication failed.
    root@localhost:~#
    root@localhost:~#
    root@localhost:~#
    root@localhost:~# mongodump
    2024-03-24T19:15:54.554+0300    Failed: error creating intents to dump: error getting database names: (Unauthorized) Command listDatabases requires authentication
    
    
  • @phenomlab

    I’m trying to take a backup while Mongodb is running, but this time it gives an authentication error.

    root@localhost:~# mongodump --port 27017 -u "nodebb" -p "Em26452645" --db=nodebb --out=backup/ahmed
    2024-03-24T19:15:41.690+0300    Failed: can't create session: failed to connect to mongodb://localhost:27017/: connection() error occurred during connection handshake: auth error: unable to authenticate using mechanism "SCRAM-SHA-256": (AuthenticationFailed) Authentication failed.
    root@localhost:~#
    root@localhost:~#
    root@localhost:~#
    root@localhost:~# mongodump
    2024-03-24T19:15:54.554+0300    Failed: error creating intents to dump: error getting database names: (Unauthorized) Command listDatabases requires authentication
    
    

    @ahmed are you backing up remotely?

    Try this - obviously, substitute where necessary to match your environment

    mongodump -u root --password 'secret' --authenticationDatabase admin
    

Did this solution help you?
Did you find the suggested solution useful? Support 💗 Sudonix with a coffee
If your organisation needs deeper expertise around infrastructure, security, or technology leadership, learn more about Phenomlab Ltd. Many of the deeper technical guides behind Sudonix are published there.

Related Topics
  • Mongo Completely Broken.

    General mongodb
    20
    3 Votes
    20 Posts
    3k Views
    @Sampo2910 said in Mongo Completely Broken.: I can see you cringing Yes, that does make me slightly uncomfortable but OK.
  • Correct Categories

    General unresolved resolved question
    6
    2 Votes
    6 Posts
    904 Views
    @Madchatthew No way - I want people to post here! That’s the point of this platform.
  • mongodb backup problem

    Moved Configure mongodb
    3
    1
    1 Votes
    3 Posts
    848 Views
    You might want to also review this post https://sudonix.org/topic/389/mongodb-backup-script
  • mongodb replica set

    Configure mongodb docker ansible
    11
    2 Votes
    11 Posts
    2k Views
    @veronikya said in mongodb replica set: The host’s local dns resolution is not configured. The problem of the host’s hosts being unable to be resolved in docker has been solved. Surprisingly Solution: Edit the /etc/resovel.conf file Add 127.0.0.53 One immediate issue I can think of here is that editing resolv.conf directly is no longer supported and not recommended (because the changes do not survive a reboot) - unless you install the resolvconf package?
  • Nodebb: failed to restore a mongo dump

    Solved Configure mongodb
    2
    1 Votes
    2 Posts
    684 Views
    @phenomlab In fact I specified the sub rep and not the rep DON’T DO THIS: nodebb@nodebbpwclonedb:~/nodebb$ sudo mongorestore --username admin --password XXXXXXXXXXXXXX --nsInclude nodebb.objects --drop /home/nodebb/nodebb_DB_20230107/nodebb/ BUT THIS : nodebb@nodebbpwclonedb:~/nodebb$ sudo mongorestore --username admin --password XXXXXXXXXXXXXX --nsInclude nodebb.objects --drop /home/nodebb/nodebb_DB_20230107/
  • Mongodb Authorisation.

    Solved General mongodb
    17
    2 Votes
    17 Posts
    2k Views
    @Sampo2910 I just saw this on the NodeBB community site and it seems very much in line with the issue you are experiencing. Worth a look I think https://community.nodebb.org/topic/16826/does-nodebb-work-with-mongodb-6-0
  • Issues with 2nd NodeBB installation

    Solved General
    22
    3 Votes
    22 Posts
    4k Views
    @cagatay yes, that will be fine. Just watch for potential caching conflicts as you will have two sites writing to the one instance of iframely.
  • mongorestore "E11000 duplicate key error collection"

    Solved Configure mongodb restore
    1
    1 Votes
    1 Posts
    1k Views
    No one has replied