Setup

Stack config: https://github.com/one137/dockerhost-stacks/blob/main/stacks/50-mongodb.yml

Add ct-npm to 50-mongodb_internal network

Add a stream host to NPM, through the UI or:

curl -sX POST -H "Authorization: Bearer ${NPM_TOKEN}" -H "Content-Type:application/json" -d '{"incoming_port": 27017, "forwarding_port": 27017, "forwarding_host": "ct-mongodb", "tcp_forwarding": true, "udp_forwarding": true}' http://localhost:81/api/nginx/streams | jq

Connect: mongosh mongodb://${ROOT_USERNAME}:${ROOT_PASSWORD}@mongodb.one137.dev

XFS

To use an XFS filesystem, see Format and mount a NAS iSCSI drive (XFS for Mongo)

Addressing Mongo warnings/optimizations

Connection warning can be suppressed by —quiet (mongosh --quiet mongodb://***:***@mongodb.one137.dev:27017).

Otherwise, to actually address them (probably only if Mongo lives in its own VM, and if high perf is needed):

  • sudo vim /etc/sysctl.conf and add vm.max_map_count=1677720 and vm.swappiness=1, then sudo sysctl -p to apply
  • Add following commands to /etc/rc.local if available or create a custom systemd service for them to make them permanent, if needed (not tested):
    • echo always | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
    • echo defer+madvise | sudo tee /sys/kernel/mm/transparent_hugepage/defrag
    • echo 0 | sudo tee /sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_none