. . .

MongoDB Installation


Introduction

ApiOmat uses MongoDB for storing all meta-data like customers, applications and data models. Also, data of applications will be stored in MongoDB if non-transient data is used.

Prerequisites

Open the following ports in the firewall to other ApiOmat nodes:

  • 27017 (Default mongod instance)

  • 27018 (for sharding)

System requirements

(Taken from https://docs.mongodb.com/manual/administration/production-notes/)

The following instance configurations are recommended.

Size

CPU

Memory

Disk

Typical Cloud Instance Types

Small

2 core

8-16 GB RAM

500 GB

AWS: m5.large, m5.xlarge

Azure: Standard_A4_v2, Standard_A8_v2

Large

4 core

32-64+ GB RAM

1000 GB

AWS: m5.2xlarge, m5.4xlarge

Azure: Standard_D4_v3, Standard_D5_v3

The small size instance configuration is appropriate for most initial production deployments, or for development/testing environments. The large size is for production environments where there is a consistently high workload.

Usage of SATA SSD is recommended!

Installation

Supported versions

Please find our supported MongoDB versions in the infrastructure requirements.

Linux and Windows

Linux and Windows

MongoDB is not included in our installation package and must be installed separately. Follow the instructions for Linux or Windows from MongoDB directly.

Docker Compose

Docker Compose
# Docker login
docker login -u <USERNAME> -p <PASSWORD>
 
# Our image is on docker hub: https://hub.docker.com/r/apiomat/mongo-conf/
# Store the following file and execute:
docker-compose -f mongodb.yml up

mongodb.yml:

version: '3'
services:
mongo:
image: mongo:4.0
# if you want mmapv1 storage engine enabled:
# command: --smallfiles --storageEngine mmapv1
# bind port 27017 from container to port 27017 on localhost
ports:
- "27017:27017"
volumes:
- mongo_db:/data/db
- mongo_config:/data/configdb
volumes:
mongo_db:
driver: local
mongo_config:
driver: local

Kubernetes

Kubernetes
# We are using helm to deploy the mongodb replicaset
 
helm init
helm repo update
helm fetch stable/mongodb-replicaset
 
# extract the archive (.tgz) and find the values.yml. Adjust the following parameters:
# - replicaSetName
# - tag of mongodb image should be "3.6"
# - persistentVolume should be enabled
# - storageClass should be adjusted
# - accessModes should be "ReadWriteMany"
# - size should be at least 20Gi
# - The official documentation can be found here: https://github.com/helm/charts/tree/master/stable/mongodb-replicaset
 
helm install stable/mongodb-replicaset --name mongodb --values mongodb-values.yaml

Example of mongodb_values.yml:

replicas: 3
port: 27017
 
 
replicaSetName: replset
 
podDisruptionBudget: {}
# maxUnavailable: 1
# minAvailable: 2
 
auth:
enabled: false
# adminUser: username
# adminPassword: password
# metricsUser: metrics
# metricsPassword: password
# key: keycontent
# existingKeySecret:
# existingAdminSecret:
# exisitingMetricsSecret:
 
# Specs for the Docker image for the init container that establishes the replica set
installImage:
repository: k8s.gcr.io/mongodb-install
tag: 0.6
pullPolicy: IfNotPresent
 
# Specs for the MongoDB image
image:
repository: mongo
tag: 3.6
pullPolicy: IfNotPresent
 
# Additional environment variables to be set in the container
extraVars: {}
# - name: TCMALLOC_AGGRESSIVE_DECOMMIT
# value: "true"
 
# Prometheus Metrics Exporter
metrics:
enabled: false
image:
repository: ssalaues/mongodb-exporter
tag: 0.6.1
pullPolicy: IfNotPresent
port: 9216
path: "/metrics"
socketTimeout: 3s
syncTimeout: 1m
prometheusServiceDiscovery: true
resources: {}
 
# Annotations to be added to MongoDB pods
podAnnotations: {}
 
securityContext:
runAsUser: 999
fsGroup: 999
runAsNonRoot: true
 
resources: {}
# limits:
# cpu: 500m
# memory: 512Mi
# requests:
# cpu: 100m
# memory: 256Mi
 
## Node selector
## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector
nodeSelector: {}
 
affinity: {}
 
tolerations: []
 
extraLabels: {}
 
persistentVolume:
enabled: true
## mongodb-replicaset data Persistent Volume Storage Class
## If defined, storageClassName: <storageClass>
## If set to "-", storageClassName: "", which disables dynamic provisioning
## If undefined (the default) or set to null, no storageClassName spec is
## set, choosing the default provisioner. (gp2 on AWS, standard on
## GKE, AWS & OpenStack)
##
storageClass: ""
accessModes:
- ReadWriteMany
size: 20Gi
annotations: {}
 
# Annotations to be added to the service
serviceAnnotations: {}
 
tls:
# Enable or disable MongoDB TLS support
enabled: false
# Please generate your own TLS CA by generating it via:
# $ openssl genrsa -out ca.key 2048
# $ openssl req -x509 -new -nodes -key ca.key -days 10000 -out ca.crt -subj "/CN=mydomain.com"
# After that you can base64 encode it and paste it here:
# $ cat ca.key | base64 -w0
# cacert:
# cakey:
 
# Readiness probe
readinessProbe:
initialDelaySeconds: 5
timeoutSeconds: 1
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
 
# Liveness probe
livenessProbe:
initialDelaySeconds: 30
timeoutSeconds: 5
failureThreshold: 3
periodSeconds: 10
successThreshold: 1

Configuration

Linux and Windows

Linux and Windows

The following configuration files are provided:

/etc/mongod.conf

The main configuration file provided by MongoDB, which contains all necessary information to start mongodb.

As of Yambas 2.6.5 it is possible to enable an SSL/TLS encrypted connection between the MongoDB and Yambas. Note that the CA-Certificate that signed the certificate of the connection has to be part of the cacerts java keystore which is used to run Yambas. Be sure that the CA certificate is imported there.

More information about all possible settings can be found at the mongodb website.

/etc/apiomat/apiomat.yaml

The main ApiOmat configuration file provided with YAMBAS installation, which contains all necessary information to connect from YAMBAS to mongodb.

Key

Default

Explanation

yambas.mongodb.hosts.live

localhost:27017

comma separated list of mongo nodes for LIVE system (URL with port separated by colon)

yambas.mongodb.hosts.staging

localhost:27017

comma separated list of mongo nodes for STAGING system (URL with port separated by colon)

yambas.mongodb.hosts.test

localhost:27017

comma separated list of mongo nodes for TEST system (URL with port separated by colon)

yambas.mongodb.hosts

localhost:27017

comma separated list of mongo nodes for all systems (URL with port separated by colon)

yambas.mongodb.connections

100

Number of connections of this YAMBAS node to the master DB; only change if you know what you are doing!

yambas.mongodb.dumpPath

Directory where to store DB dumps for Restore Module

yambas.mongodb.binPath

Binary of mongo client for Restore Module

Docker

Docker

Environmental Variables

Required variables are printed in bold.

Key

Default

Explanation

STORAGE_ENGINE

mmapv1

Here you can customize the storage engine of mongodb. Default is Wired Tiger.

USE_SMALL_FILES

false

use mongodb small files option

REPL_SET (M)

This variable can be used to prepare a manual mongodb replication set. The initialization has to be done manually until now.

MONGODB_DEFAULT

Service names of all docker containers (for example: mongo1,mongo2,mongo3 )

INITIAL_PRIMARY

Service name for the docker container that becomes the primary (for example: mongo1)

TRY_TIMES

How often should the Docker Container try to set up the Replset?

Authentication setup

Authentication on mongodb is described on a separate page.

Cluster setup

Setting up replication on mongodb is described on a separate page.

Logging

Linux

Linux

Logging is done to a separate logfile. The logging file name can be configured in mongod.conf.

tail -f /var/log/mongodb/mongod.log

Docker

Docker

Please replace <MONGO_CONTAINER_ID> with your running container ID. You can list your running container using 'docker container list' command.

docker logs -f <MONGO_CONTAINER_ID>

Windows

Windows

All logs are written to Event manager.

Next steps

Install further microservices.