How to install MongoDB database server in Plesk?

Follow

Comments

22 comments

  • Avatar
    DANIEL VENGOECHEA (Edited )

     

    ***** UPDATE 20-07-2019 *****

    Plesk team fixed the issue on their guide . You can fallow again the guide and the variables they mention.

     

    ****** BIG WARNING ******

    If you dont do this, all your database data will be DELETED

     

    On step # 5. Map Docker container to the location on filesystem, to ensure that both the data and the configuration will persist:

    The image presented on this GUIDE is not updated, so add the same variables also on the second column (host column)

     

     

    This will create on your file system the Database DATA and it will be read and not deleted from there. 

     

    **please plesk support UPDATE this GUIDA, i just lost many of my clients data because of this.

     

    2
    Comment actions Permalink
  • Avatar
    Alexandr Bashurov

    @Mattia Di Giuseppe

    The shell client has to be installed on the host server indeed. You may do it as follows:

    # apt install -y mongodb-clients

    Article was updated to mention it.

    1
    Comment actions Permalink
  • Avatar
    Vladimir Chernikov

    Hello @Cbordon,

    >> Since I am using MongoDB via the Docker, and the database is set up on localhost, is it safe to not set a password?

    It is not safe and we highly recommend to set the root password.

    >> If a password is recommended do you know how I can pass the authentication checks?

    To authenticate with root login and password use the following command via SSH:
    mongo admin -u root -p yourpassword

    At first, you should create the database:
    use testdb

    Then add the user to this database:
    db.createUser(
    {
    user: "testuser",
    pwd: "12345678",
    roles: [
    { role: "read", db: "testdb" }
    ]
    }
    )

    Then it will be possible to authenticate this user:
    db.auth("testuser", "12345678");
    1

    Note: db.auth() returns 0 when authentication is not successful, and 1 when the operation is successful.

    Please refer to the following articles for more information:
    https://docs.mongodb.com/manual/tutorial/create-users/
    https://docs.mongodb.com/manual/reference/method/db.auth/

    0
    Comment actions Permalink
  • Avatar
    Thomas Kim (Edited )

    Actually, the warning post by @DANIEL VENGOECHEA is correct somehow, even though I am not facing any data loss issue, but a login issue. I have tested it here with and without the variables after the 2nd rows. (like he mentioned above)

    I was facing an authentication error when trying to log in. But after changing the directories as he said. I managed to log in from SSH, and Mongo Compass.

    I double-checked by switching back to only 2 rows of (Map Docker to the filesystem) and log in again. Failed due to Authentication Error. and cannot show dbs.

    Anyway, thanks for this helpful post and helpful community. I managed to connect it :)

    0
    Comment actions Permalink
  • Avatar
    Cbordon

    Thank you for your timely reply.

    Following these instructions gave me a different authentication error:

    Error: couldn't add user: not authorized on testdb to execute command { createUser......

    0
    Comment actions Permalink
  • Avatar
    Cbordon

    The rated answer mentions accessing mongod without --auth

    Following the instructions on this page, it didn't require me to install mongod.

    Is that something I should add? If so, how would I go about doing that on plesk server?

    0
    Comment actions Permalink
  • Avatar
    Mattia Di Giuseppe

    How can i configure mongo shell? If i type mongo the shell tell me to install mongo from apt.

    Thanks

    0
    Comment actions Permalink
  • Avatar
    Daria Gavrilova

    Рello @Chris Williams,

    Thank you for your question.

    The image, which is provided in the article, is the correct one.
    Before posting all actions and images it was double checked on the test environment.

    0
    Comment actions Permalink
  • Avatar
    Alisa Kasyanova

    @Mattia Di Giuseppe

    Hi! You may search for any errors in log files and check them in our KB articles or MongoDB documentation. You may also contact MongoDB support since they are experts in MongoDB and can help you with the setup.

    0
    Comment actions Permalink
  • Avatar
    Alisa Kasyanova

    @Cbordon
    Seems that you need to create admin user, and then create testuser under admin. Check the following thread.

    0
    Comment actions Permalink
  • Avatar
    Chris Williams

    @Daria,

    Your image and the image that @Daniel Vengoechea posted don't match up exactly.

    Can you confirm that we need to follow your image and not his?

    Thanks!

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    Hello @Alvaro,

    Please, check this link.

    If it would not help, contact the container developers.

    0
    Comment actions Permalink
  • Avatar
    Mattia Di Giuseppe

    @Alexandr Bashurov

    Yes I have fixed it but now I have problems with web client for Mongo. I have installed pecl extension but any of web clients works. Can u help me? Thanks 

    0
    Comment actions Permalink
  • Avatar
    Alisa Kasyanova

    @James Scholey
    Hi! Try to login with: mongo -u user -p password --authenticationDatabase admin

    0
    Comment actions Permalink
  • Avatar
    Daria Gavrilova

    Hello @Daniel Vengoechea,

    Thank you for your input.

    The article was modified accordingly.

    0
    Comment actions Permalink
  • Avatar
    Daria Gavrilova

    Hello @Thomas Kim,

    Thank you for your input!

    Glad to hear that the issue was solved!

    0
    Comment actions Permalink
  • Avatar
    Alvaro Garcia

    Thanks @Ivan, one last question, how to enable the auth on the mongodb instance?

    With the enviroment variable AUTH = yes ?

    0
    Comment actions Permalink
  • Avatar
    Cbordon

    I was finally able to create a user.

    I ended up using @Daniel Vengoechea's answer and all of my authentication checks started passing.

    Thank you for your help!

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    Hello @Alvaro, as I can see the same error was discussed here: https://talk.plesk.com/threads/docker-doesnt-start-any-single-image-iptables-error-bug.341757/

    As a resolution, the server was restarted, have you tried it?

     

    Another workaround was discussed here: https://github.com/moby/moby/issues/1871

    0
    Comment actions Permalink
  • Avatar
    Cbordon

    I have followed all of the steps in the guide and was successfully able to set up mongodb.

    However, I am having issues with authentication from my NodeJS App, setup similarly to this: (https://www.plesk.com/blog/product-technology/node-js-plesk-onyx/)

     

    I can not pass authentication checks from my app or by mongo shell in ssh

    db.auth("user", "pass");

     

    Removing these from the Docker image makes everything work:

    MONGO_INITDB_ROOT_USERNAME

    MONGO_INITDB_ROOT_PASSWORD

     

    But I am obviously not password protected anymore.

     

    Since I am using MongoDB via the Docker, and the database is set up on localhost, is it safe to not set a password?

    If a password is recommended do you know how I can pass the authentication checks?

     

    Thank you very much.

    0
    Comment actions Permalink
  • Avatar
    James Scholey

    When following this example running plesk on Debian 8, I am faced with authentication errors when running the mongo shell via ssh. Either that authorisation is required or that the authentication mechanism is not defined??

    0
    Comment actions Permalink
  • Avatar
    Alvaro Garcia

    Hi Robert, i have done what you say and I get the following error, what can it be?

    Error: {"message":"driver failed programming external connectivity on endpoint mongo (ee36c8720ed12a1cd8b3cac64bdcd552544415f64be1ea0e6b998ebf49fd75c6): (COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -A DOCKER ! -i docker0 -o docker0 -p tcp -d 172.17.0.2 --dport 27017 -j ACCEPT' failed: iptables: No chain/target/match by that name.\n)"}

     

     

    Thanks!!

    -1
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request