Configure ferret module, and use multiple ferret nodes.
This is the multi-page printable view of this section. .
FERRET
MongoDB has lost its open-source appeal and is no longer suitable for many cases. In contrast, PostgreSQL offers robust, native JSON support and outperforms MongoDB as a document database.
Thus, FerretDB provides a mongo wire-protocol-compatible layer upon postgres, enabling MongoDB users to migrate smoothly to PostgreSQL’s superior platform.
FERRET is an OPTIONAL module in Pigsty.
It requires the documentdb extensions to work since v2.0.
Pigsty has packaged that and provides a mongo.yml template to help you deploy a FerretDB cluster with ease.
Customize ferret components with 15 parameters
Create, remove, expand, shrink, upgrade ferret cluster
Ansible playbooks that can be used in this module
Dashboards, metrics, record & alerting rules.
How to use the mcli and configure backup repo
1 - Usage
Install Client Tools
You can use MongoDB’s command-line tool MongoSH to access FerretDB.
Use the pig command to add MongoDB repository, then install mongosh using yum or apt:
Connect to FerretDB
You can access FerretDB using MongoDB connection strings with any MongoDB driver in any language. Here’s an example using the mongosh CLI tool:
Authentication
You can log in with different users. See FerretDB: Authentication for details.
Quick Start
You can connect to FerretDB and use it as if it were a MongoDB cluster.
MongoDB commands are translated to SQL and executed in the underlying PostgreSQL:
If you’re not familiar with MongoDB, here’s a quick tutorial that works with FerretDB: Perform CRUD Operations with MongoDB Shell
To generate sample workload, you can use this simple test script with mongosh:
You can check FerretDB’s supported MongoDB commands and known differences. For basic usage, these differences are usually not significant.
2 - Configure
FerretDB Cluster
Before deploying a Mongo (FerretDB) cluster, you need to define it in the inventory using the relevant parameters.
The following example uses the default single-node pg-meta cluster’s meta database as FerretDB’s underlying storage:
Here, mongo_cluster and mongo_seq are essential identity parameters. For FerretDB, mongo_pgurl is also required to specify the underlying PG location.
Note that the mongo_pgurl parameter requires a PostgreSQL superuser. In this example, a dedicated mongod superuser is defined for FerretDB.
Note that FerretDB’s authentication is entirely based on PostgreSQL. You can create other regular users using either FerretDB or PostgreSQL.
PostgreSQL Cluster
FerretDB 2.0+ requires an extension: DocumentDB, which depends on several other extensions. Here’s a template for creating a PostgreSQL cluster for FerretDB:
High Availability
You can use Services to connect to a highly available PostgreSQL cluster and deploy multiple FerretDB instance replicas with L2 VIP binding for FerretDB layer high availability.
3 - Parameter
There are 9 parameters in the FERRET module.
| Parameter | Type | Level | Comment |
|---|---|---|---|
mongo_seq |
int | I | mongo instance identifier, REQUIRED |
mongo_cluster |
string | C | mongo cluster name, MONGO by default |
mongo_pgurl |
pgurl | C/I | underlying postgres URL for ferretdb |
mongo_ssl_enabled |
bool | C | mongo/ferretdb ssl enabled, false by default |
mongo_listen |
ip | C | mongo listen address, empty for all addr |
mongo_port |
port | C | mongo service port, 27017 by default |
mongo_ssl_port |
port | C | mongo tls listen port, 27018 by default |
mongo_exporter_port |
port | C | mongo exporter port, 9216 by default |
mongo_extra_vars |
string | C | extra environment variables for MONGO server |
Defaults
The default parameters are defined in roles/ferret/defaults/main.yml
mongo_cluster
name: mongo_cluster, type: string, level: C
mongo cluster name, required identity parameter.
default value is MONGO, but you should define it explicitly for production use.
Comply with regexp [a-z][a-z0-9-]*, it is recommended to use descriptive names and start with mongo-
mongo_seq
name: mongo_seq, type: int, level: I
mongo instance sequence number, unique integer among mongo cluster is required
You have to explicitly define the sequence number for each mongo instance. integer start from 0 or 1.
mongo_pgurl
name: mongo_pgurl, type: pgurl, level: C/I
underlying postgres URL for ferretdb connection.
no default value, you have to define it explicitly. This is the PostgreSQL database URL that FerretDB will use as its backend storage.
Format: postgres://username:password@host:port/database
mongo_ssl_enabled
name: mongo_ssl_enabled, type: bool, level: C
mongo/ferretdb ssl enabled flag.
default value is false. Set to true to enable SSL/TLS encryption for mongo connections.
mongo_listen
name: mongo_listen, type: ip, level: C
mongo listen address for binding.
default value is empty string '', which means listen on all available addresses. You can specify a specific IP address to bind to.
mongo_port
name: mongo_port, type: port, level: C
mongo service port for client connections.
default value is 27017, which is the standard MongoDB port. Change this if you need to avoid port conflicts.
mongo_ssl_port
name: mongo_ssl_port, type: port, level: C
mongo tls listen port for encrypted connections.
default value is 27018. This port is used when SSL/TLS is enabled for secure connections.
mongo_exporter_port
name: mongo_exporter_port, type: port, level: C
mongo exporter port for metrics collection.
default value is 9216. This port is used by the monitoring exporter to expose metrics for Prometheus.
mongo_extra_vars
name: mongo_extra_vars, type: string, level: C
extra environment variables for MONGO server.
default value is empty string ''. You can specify additional environment variables that will be passed to the FerretDB process.
4 - Administration
Create FerretDB Cluster
After defining the FerretDB cluster in the inventory, you can install it with:
Since FerretDB uses PostgreSQL as its underlying storage, running this playbook multiple times is generally safe.
Remove FerretDB Cluster
To remove a Mongo/FerretDB cluster, run the mongo_purge subtask of mongo.yml playbook with the mongo_purge parameter:
5 - Playbook
There’s a built-in playbook mongo.yml for installing FerretDB on nodes.
mongo.yml
mongo.yml: Install MongoDB/FerretDB on the target host.
This playbook consists of the following subtasks:
mongo_check: check mongo identitymongo_dbsu: create os user mongodmongo_install: install mongo/ferretdb rpmmongo_purge: purge mongo/ferretdbmongo_config: config mongo/ferretdbmongo_cert: issue mongo/ferretdb ssl certsmongo_launch: launch mongo/ferretdb servicemongo_register: register mongo/ferretdb to prometheus
6 - Monitor
There is one dashboard for FERRET module for now.
Mongo Overview
Mongo Overview: Overview of a Mongo/FerretDB cluster