Skip to content

MongoDB BI Connector Reference Guide

1. Overview

2. Installation

  • System: This document is based on Centos 7.x installation
  • mongodb bi connector version: mongodb-bi-linux-x86_64-rhel70-v2.14.2.tgz

2.1 Installation Requirements

Installing mongodb bi connector requires the system to have openssl installed. If not installed, you can use the yum command to install it.

bash
yum -y install openssl

2.2 Installation

Installing mongodb is very simple. Execute the following command to extract:

bash
tar -xzvf mongodb-bi-linux-x86_64-rhel70-v2.14.2.tgz

2.3 Configuration

The configuration file for mongosqld uses the yaml format, and most parameters also have corresponding command-line parameters.

2.3.1 Log Parameters

yml
systemLog:
  logAppend: <boolean>
  logRotate: "rename" or "reopen"
  path: <string>
  quiet: <boolean>
  verbosity: <integer>

Parameter Description:

ParameterTypeDefault ValueCorresponding Command-line ParameterDescription
systemLog.logAppendboolean--logAppendOutputs logs to the log file specified by systemLog.path, and must set systemLog.logRotate
systemLog.pathstringrename--logRotateSpecifies how the log should rotate, with two options:
rename : Closes the existing file and renames it, appending a timestamp in RFC3339 format to the filename. A new log file is then created.
reopen : Closes the file and then reopens it.
systemLog.pathstring--logPathSpecifies the file to store the output logs
systemLog.quietboolean--quietHides all log output
systemLog.verbosityinteger--verbose / -vSets this option to output more detailed logs

2.3.2 Schema Parameters

yml
schema:
  path: <string>
  maxVarcharLength: <integer>

Parameter Description:

ParameterTypeDefault ValueCorresponding Command-line ParameterDescription
schema.pathstring--schemaSpecifies the schema file or directory
schema.maxVarcharLengthinteger--maxVarcharLengthSpecifies the maximum character length for varchar fields. If exceeded, it will be truncated to the specified length and a warning log will be printed

2.3.2 Data Sample Parameters

yml
schema:
  sample:
    size: <integer>
    prejoin: <boolean>
    namespaces: <array of strings>
    uuidSubtype3Encoding: <[old|csharp|java]>
  stored:
    mode: <[custom|auto]>
    source: <string>
    name: <db-name>
  refreshIntervalSecs: <integer>

Parameter Description:

ParameterTypeDefault ValueCorresponding Command-line ParameterDescription
schema.stored.modeintegercustom--schemaModeConfigures the sample model for mongosqld, must be used with schema.stored.source, with two options:
custom : mongosqld reads the stored schema from the MongoDB database
auto : mongosqld samples the schema and writes it to the MongoDB database
schema.stored.sourcestring--schemaSourceSpecifies the database to store schema information
schema.stored.namestringdefaultSchema--schemaNameThe schema name used for reading and writing
schema.sample.sizeinteger1000--sampleSizeThe number of documents sampled per database when collecting schema information
schema.sample.prejoinboolean--prejoinSchema option to combine array and non-array data into a single table
schema.sample.namespacesstring or string array--sampleNamespacesSpecifies the database and collection to include or exclude in the data sampling process for creating the schema
schema.sample.uuidSubtype3Encodingstring--uuidSubtype3Encoding / -bSpecifies the encoding used to generate the UUID binary subtype, including:
old : Old BSON binary subtype representation
csharp : C# or .NET legacy UUID representation
java : Java legacy UUID representation
schema.refreshIntervalSecsinteger0--schemaRefreshIntervalSecsThe interval in seconds for mongosqld to resample and create the schema. The default is 0, meaning no resampling after initialization during the connection. The value must be a positive integer

2.3.3 Runtime Parameters

yml
runtime:
  memory:
    maxPerStage: <integer>
    maxPerServer: <integer>
    maxPerConnection: <integer>

Parameter Description:

ParameterTypeDefault ValueCorresponding Command-line ParameterDescription
runtime.memory.maxPerStageintegerSpecifies the maximum memory (in bytes) that can be used by a query execution stage
runtime.memory.maxPerServerintegerSpecifies the maximum memory (in bytes) that can be used by the mongosqld process
runtime.memory.maxPerConnectionintegerSpecifies the maximum memory (in bytes) that can be used by a mongosqld client connection

2.3.4 Network Parameters

yml
net:
  bindIp: <string>
  port: <integer>
  unixDomainSocket:
    enabled: <boolean>
    pathPrefix: <string>
    filePermissions: <string>
  ssl:
    mode: <string>
    allowInvalidCertificates: <boolean>
    PEMKeyFile: <string>
    PEMKeyPassword: <string>
    CAFile: <string>
    minimumTLSVersion: <string>

Parameter Description:

ParameterTypeDefault ValueCorresponding Command-line ParameterDescription
net.bindIpstring127.0.0.1Host part of --addrSpecifies the host address to listen on, multiple addresses separated by ","
net.portinteger3307Port part of --addrSpecifies the port to listen on
net.unixDomainSocket.enabledbooleantrue : Indicates listening on a Unix domain socket
false : Disables listening on a Unix domain socket, equivalent to the command-line parameter --noUnixSocket
net.unixDomainSocket.pathPrefixstring/tmp--unixSocketPrefixSpecifies the directory for the mongosqld Unix domain socket. mongosqld will create a mysql.sock socket in this path. If not specified, it will create /tmp/mysql.sock
net.unixDomainSocket.filePermissionsstring448--filePermissionsSpecifies the permissions for the Unix domain socket file
net.ssl.allowInvalidCertificatesboolean--sslAllowInvalidCertificatesAllows MySQL clients to provide invalid client TLS/SSL certificates
net.ssl.modestringdisabled--sslModeEnables or disables TLS/SSL connections to mongosqld. Includes the following 3 options:
disabled : mongosqld does not accept connections protected by TLS/SSL
allowSSL : mongosqld accepts connections protected by TLS/SSL (also accepts connections without TLS/SSL)
requireSSL : mongosqld only accepts connections protected by TLS/SSL
net.ssl.PEMKeyFilestring--sslPEMKeyFileSpecifies the .pem file containing the TLS/SSL certificate and MySQL client key. Can use relative or absolute paths
net.ssl.PEMKeyPasswordstring--sslPEMKeyPasswordSpecifies the password to decrypt the private key specified by net.ssl.PEMKeyFile
net.ssl.CAFilestring--sslCAFileSpecifies the mongosqld .pem file containing the root certificate chain of the certificate authority. Can use relative or absolute paths
net.ssl.minimumTLSVersionstringTLS1_1--minimumTLSVersionSpecifies the minimum TLS version, with 3 options: TLS1_0, TLS1_1, TLS1_2

2.3.5 Security Parameters

yml
security:
  enabled: <boolean>
  defaultMechanism: <string>
  defaultSource: <string>
  gssapi:
    hostname: <string>
    serviceName: <string>

Parameter Description:

ParameterTypeDefault ValueCorresponding Command-line ParameterDescription
security.enabledboolean--authRequires client requests to be authenticated
security.defaultMechanismstringSCRAM-SHA-1--defaultAuthMechanismSpecifies the default authentication mechanism, including SCRAM-SHA-1, SCRAM-SHA-256, PLAIN, GSSAPI
security.defaultSourcestringadmin--defaultAuthSourceSpecifies the default source for MongoDB authentication
security.gssapi.hostnamestringFirst IP specified by net.bindIp--gssapiHostnameConfigures the FQDN for Kerberos authentication
security.gssapi.serviceNamestringmongosql--gssapiServiceNameThe service name registered with Kerberos
security.gssapi.constrainedDelegationstringFalse--gssapiConstrainedDelegationUses proxy credentials for Kerberos authorization, enabling constrained delegation

2.3.6 MongoDB Host Parameters

yml
mongodb:
  versionCompatibility: <string>
  net:
    uri: <string>
    ssl:
      enabled: <boolean>
      allowInvalidCertificates: <boolean>
      allowInvalidHostnames: <boolean>
      PEMKeyFile: <string>
      PEMKeyPassword: <string>
      CAFile: <string>
      CRLFile: <string>
      FIPSMode: <boolean>
    auth:
      username: <username>
      password: <password>
      source: <auth-db-name>
      mechanism: <auth-mechanism>
      gssapiServiceName: <service>

Parameter Description:

ParameterTypeDefault ValueCorresponding Command-line ParameterDescription
mongodb.versionCompatibilitystring--mongo-versionCompatibilityLimits the features provided by mongosqld based on the given MongoDB version. This is only necessary when the replica set and its members use different versions, or during a rolling upgrade of MongoDB
mongodb.net.uristringmongodb://localhost:27017--mongo-uriSpecifies the MongoDB connection string
mongodb.net.ssl.enabledbooleanFalseIndicates whether to use TLS/SSL to connect to the MongoDB instance
mongodb.net.ssl.allowInvalidCertificatesboolean--mongo-sslAllowInvalidCertificatesAllows MongoDB to provide invalid TLS/SSL certificates
mongodb.net.ssl.allowInvalidHostnamesboolean--mongo-sslAllowInvalidHostnamesAllows mongosqld to connect to MongoDB using a hostname different from the one in the TLS/SSL certificate
mongodb.net.ssl.PEMKeyFilestring--mongo-sslPEMKeyFileSpecifies the .pem file containing the TLS/SSL certificate and key for mongosqld to connect to MongoDB. Can use relative or absolute paths
mongodb.net.ssl.PEMKeyPasswordstring--mongo-sslPEMKeyPasswordSpecifies the path to the file containing the certificate and private key for connecting to MongoDB
mongodb.net.ssl.CAFilestring--mongo-sslCAFileSpecifies the MongoDB .pem file containing the root certificate chain of the certificate authority. Can use relative or absolute paths
mongodb.net.ssl.CRLFilestring--mongo-sslCRLFileSpecifies the MongoDB .pem file containing the list of revoked certificates
mongodb.net.ssl.FIPSModeboolean--mongo-sslFIPSModeEnables FIPS mode in the installed OpenSSL library
mongodb.net.ssl.minimumTLSVersionstring--mongo-minimumTLSVersionSpecifies the minimum TLS version, with 3 options: TLS1_0, TLS1_1, TLS1_2
mongodb.net.auth.usernamestring--mongo-username / -uSpecifies the username for discovering the schema. Only needed if --auth is enabled. Must be a valid MongoDB user with listDatabases permission
mongodb.net.auth.passwordstring--mongo-password / -pSpecifies the user password
mongodb.net.auth.sourcestringadmin--mongo-authenticationSourceSpecifies the database for authentication
mongodb.net.auth.mechanismstringSCRAM-SHA-1--mongo-authenticationMechanismSpecifies the authentication mechanism, including SCRAM-SHA-1, SCRAM-SHA-256, PLAIN, GSSAPI
mongodb.net.auth.gssapiServiceNamestringmongodb--mongo-gssapiServiceNameSets the Kerberos SPN for Kerberos authentication

2.3.7 Process Management Parameters

yml
processManagement:
  service:
    name: <string>
    displayName: <string>
    description: <string>

Parameter Description:

ParametersTypeDefault ValueCorresponding Command Line ParameterDescription
processManagement.service.namestring--serviceNameSystem service name for running mongosqld
processManagement.service.displayNamestring--serviceDisplayNameDisplay name for the system service running mongosqld
processManagement.service.descriptionstring--serviceDescriptionDescription for the system service running mongosqld

2.4 Configuration File Example

Below is a sample configuration file:

yml
systemLog:
  logAppend: false
  path: "/var/log/mongosqld/mongosqld.log"
  verbosity: 2

security:
  enabled: true

mongodb:
  net:
    uri: "mongo.example.com:27017"
    auth:
      username: "root"
      password: "changeme"

net:
  bindIp: 192.0.2.14
  port: 3307
  ssl:
    mode: "allowSSL"
    PEMKeyFile: "/vagrant/certificates/mongosqld-server.pem"
    CAFile: "/vagrant/certificates/ca.crt"

schema:
  sample:
    namespaces: "inventory.*"

processManagement:
  service:
    name: mongosqld
    displayName: mongosqld
    description: "BI Connector SQL proxy server"

3. Start

  1. Start using command line parameters
bash
bin/mongosqld --mongo-uri "mongodb://127.0.0.1:27017" --auth  -u root -p 123456 --addr "0.0.0.0:3307"
  1. Start using a configuration file
bash
bin/mongosqld --config <pathToConfigFile>/mongosqld.conf

4. Containerization

4.1 Create Image

  1. Write a Dockerfile
dockerfile
FROM ubuntu:xenial

COPY mongo* /usr/local/bin/

RUN apt-get update \
 && apt-get install -y --no-install-recommends ca-certificates numactl procps gnupg dirmngr gnupg-curl \
 && apt-get install -y rsyslog \
 && service rsyslog start

EXPOSE 3307

ENTRYPOINT ["mongosqld"]
  1. Write a build.sh script
bash
#! /bin/sh

cd $(dirname $0)

set -ex

DOCKER_FILE=mongodb-bi.Dockerfile

IMAGE_NAME=mongodb-bi-connector
IMAGE_VERSION=2.14.2

MONGODB_BI="mongodb-bi-linux-x86_64-ubuntu1604-v${IMAGE_VERSION}"
MONGODB_BI_URL="https://info-mongodb-com.s3.amazonaws.com/mongodb-bi/v2/${MONGODB_BI}.tgz"

wget -N ${MONGODB_BI_URL}

tar -xzvf ${MONGODB_BI}.tgz

docker build -f $DOCKER_FILE -t ${IMAGE_NAME}:${IMAGE_VERSION} ${MONGODB_BI}/bin/
  1. Create the image Execute the following command
bash
sh build.sh

4.2 Start

Assuming a mongodb has already been installed with the following information:

ConfigurationValue
Address192.16.1.10
Port27017
Usernamemongodb
Passwordmongodb

The start command is as follows:

bash
docker run --name mongodb-bi -i -t -p 3307:3307 -d  mongodb-bi-connector:2.14.2 --mongo-uri "mongodb://192.168.1.10:27017" --auth -u mongodb -p mongodb --addr "0.0.0.0:3307"

Appendix

Official Website

https://docs.mongodb.com/bi-connector/current/local-quickstart/

HENGSHI SENSE Platform User Manual