Skip to content

Instantly share code, notes, and snippets.

@riturajborpujari
Last active January 22, 2021 10:00
Show Gist options
  • Save riturajborpujari/2092c611f5bd851c4c095e9fcf153bb4 to your computer and use it in GitHub Desktop.
Save riturajborpujari/2092c611f5bd851c4c095e9fcf153bb4 to your computer and use it in GitHub Desktop.
MongoSQL as a service

MongoSQL as service

Run mongosql as a service with auto start on server restart

Download MongoSQL

  1. Download the BI Connector from the MongoDB Download Center

  2. Install the MongoDB Connector for BI.

    Extract the .tar archive you downloaded.

    tar -xvzf mongodb-bi-linux-{arch}-{platform}-{version}.tgz

    Install the programs within the bin/ directory into a directory listed in your system PATH.

    sudo install -m755 bin/mongo* /usr/local/bin/

  3. To install and run mongosqld as a system service, run the following commands:

    sudo mongosqld install --config <pathToConfigFile>/mongosqld.conf

    sudo systemctl start mongosql.service

  4. To enable the service so it starts automatically at boot time, run the following:

    systemctl enable mongosql.service

Run MongoSQL

Command bin/mongosqld --schemaSource <target_database_name> --auth --mongo-username=<username> --mongo-password=<password> --sslMode requireSSL --sslPEMKeyFile <path_to_ssl_key_pem>

Example bin/mongosqld --schemaSource TRLPDB --auth --mongo-username=user --mongo-password=getmein --sslMode requireSSL --sslPEMKeyFile ./ssl/mongo.pem

Issue

Currently only cleartext authentication plugin is supported by Cube.js Mongo BI Driver. It requires SSL to be set up from mongosqld in order to encrypt passed credentials from CubeJs.

Self-signed certificate can be used to provide this encryption.

  1. Generate a self-signed SSL key and certificate file with the following command:

    openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem

  2. Concat it together to create sslPEMKeyFile:

    cat key.pem certificate.pem > mongo.pem

  3. Start mongosqld with enabled SSL:

    ./mongosqld --auth --sslMode requireSSL --sslPEMKeyFile mongo.pem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment