External database setup#
This guide explains how to set up external databases for CLP instead of using the bundled databases. If the host(s) on which you’re running CLP are ephemeral, you should use external databases for metadata storage, and object storage for CLP’s archives and streams; this will ensure data is persisted even if a host is replaced.
Warning
Both the CLP Docker Compose project and the CLP Helm chart include MariaDB/MongoDB databases by default. This guide is only for users who want to customize their deployment by using their own database servers or cloud-managed databases (e.g., AWS RDS, Azure Database).
CLP requires two types of databases:
MariaDB/MySQL - for storing:
metadata about CLP’s archives, files, compression jobs, and query jobs.
metadata about Spider’s jobs (only when Spider is used for scheduling).
MongoDB - for caching query results.
MariaDB/MySQL setup#
You can use any compatible MariaDB or MySQL database installation or cloud-managed service. Below are instructions for:
MariaDB on Ubuntu#
Install MariaDB server:
sudo apt update
sudo apt install mariadb-server
If CLP components will connect from a different host, you need to configure MariaDB to accept remote connections:
Edit the MariaDB configuration file:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Find the
bind-addressline and change it to allow connections from all interfaces:bind-address = 0.0.0.0
Restart MariaDB:
sudo systemctl restart mariadb
Next, follow the steps for using CLP and/or Spider with the database.
AWS RDS for MariaDB/MySQL#
Create a MariaDB or MySQL RDS instance in the AWS Console.
Note the endpoint hostname and port (the default is
3306).Ensure the RDS security group allows inbound connections on port 3306 from your CLP hosts.
You can then connect to the instance with mysql -h <rds-endpoint> -u admin -p.
Next, follow the steps for using CLP and/or Spider with the database.
MongoDB setup#
CLP is compatible with any MongoDB database. For installation instructions, see the MongoDB installation documentation.
Warning
Running an external MongoDB on the same host as CLP (i.e., using localhost or 127.0.0.1 as
the results_cache host) is not supported. CLP’s results-cache-indices-creator initializes a
MongoDB replica set using the configured hostname, which MongoDB must be able to resolve to itself;
localhost from inside a Docker container does not resolve to the host machine.
Instead, either:
Keep
results_cachein thebundledlist (recommended for single-host deployments).Use a truly remote MongoDB instance and specify its hostname or IP.
If you must use a same-host MongoDB, configure
results_cache.hostinclp-config.yamlto the host’s non-loopback IP address (e.g.,192.168.1.10) and ensure MongoDB is bound to that address.
Creating the CLP database in MongoDB#
MongoDB automatically creates databases and collections when first accessed, so no manual database
creation is needed. CLP will create the necessary database and collections (clp-query-results by
default) when it first connects.
Configuring MongoDB for remote connections#
If CLP components will connect from a different host:
Edit the MongoDB configuration file:
sudo nano /etc/mongod.conf
Find the
net.bindIpsetting and change it to allow connections from all interfaces:net: port: 27017 bindIp: 0.0.0.0
Restart MongoDB:
sudo systemctl restart mongod
Warning
For production deployments, it’s highly recommended to enable authentication and SSL/TLS for MongoDB. See the MongoDB security documentation for details.
Verifying the MongoDB connection#
You can verify the MongoDB connection by running:
mongosh "mongodb://<mongodb-hostname-or-ip>:27017/clp-query-results"
Using AWS DocumentDB or MongoDB Atlas#
When using AWS DocumentDB or MongoDB Atlas:
Create a cluster in the AWS Console or MongoDB Atlas.
Note the connection string/endpoint provided.
Ensure the security group or IP access list allows connections from your CLP hosts.
Use the provided connection string when configuring CLP (see below).
Using an external database with CLP#
To use an external database with CLP, you’ll need to:
Creating the CLP database#
The steps below are for a MariaDB installation on Ubuntu but should be adaptable for the database you’re using.
Connect to MariaDB as root:
sudo mysqlCreate the CLP database:
CREATE DATABASE `clp-db`;
Create a user for CLP (replace
<password>with a secure password):CREATE USER 'clp-user'@'%' IDENTIFIED BY '<password>';
Note
The
'%'allows connections from any host. For better security, replace'%'with the specific hostname or IP address from which CLP will connect (e.g.,'clp-user'@'192.168.1.10').Grant privileges to the user:
GRANT ALL PRIVILEGES ON `clp-db`.* TO 'clp-user'@'%'; FLUSH PRIVILEGES;
Exit the MariaDB shell:
EXIT;
You can verify the connection by running:
mysql -h <mariadb-hostname-or-ip> -u clp-user -p clp-db
Configuring CLP to use an external database#
Edit
etc/clp-config.yamlto specify which services are bundled:# Remove "database" and "results_cache" from this list to use external instances. bundled: # - "database" - "queue" - "redis" # - "results_cache" - "otel_collector"
Configure the connection details for your external databases in
etc/clp-config.yaml:database: host: "<mariadb-hostname-or-ip>" port: <mariadb-port> results_cache: host: "<mongodb-hostname-or-ip>" port: <mongodb-port>
Set the credentials in
etc/credentials.yaml:database: username: "clp-user" password: "<your-mariadb-password>"
Note
When using external databases in a multi-host deployment, you do not need to start the
database and results-cache Docker Compose services. Skip those services when following the
multi-host deployment guide. However, you still need to run the database
initialization jobs (db-table-creator and results-cache-indices-creator).
Edit your Helm values file to specify which services are bundled:
clpConfig: # Remove "database" and "results_cache" from this list to use external instances. bundled: # - "database" - "queue" - "redis" # - "results_cache" - "otel_collector" - "presto"
Configure the connection details for your external databases in the values file:
clpConfig: database: type: "mariadb" # "mariadb" or "mysql" host: "<mariadb-hostname-or-ip>" port: <mariadb-port> results_cache: host: "<mongodb-hostname-or-ip>" port: <mongodb-port>
Set the credentials in the values file:
credentials: database: username: "clp-user" password: "<your-mariadb-password>"
Using an external database with Spider#
To use an external database with Spider, you’ll need to:
Creating the Spider database#
Connect to MariaDB as root:
sudo mysqlCreate the Spider database:
CREATE DATABASE `spider-db`;
Grant
clp-userprivileges on the Spider database.Note
If you want, you can use a separate user for the Spider database. Simply create a user by following step 3 in Creating the CLP database, then replace
clp-userwith that user in all remaining instructions below.GRANT ALL PRIVILEGES ON `spider-db`.* TO 'clp-user'@'%'; FLUSH PRIVILEGES;
Configuring Spider to use an external database#
Edit your Helm values file to specify that the Spider database is not bundled:
spider: spiderConfig: # Remove "database" from this list to use external instances. bundled: [ # "database" ]
Configure the connection details for the Spider database in the values file:
spider: spiderConfig: database: host: "<mariadb-hostname-or-ip>" port: <mariadb-port> name: "spider-db" username: "clp-user" password: "<your-mariadb-password>"