Since | Removed |
---|---|
2.8.0 | 2.9.0 |
This notice is raised when the MAAS snap is configured in all
mode, that is, it also runs the PostgreSQL database server inside the snap.
When setting up the MAAS snap via maas init
, one of the available modes has traditionally been all
. This install mode uses a PostgreSQL server, exclusively for MAAS, inside the snap itself. While this is a great quick-start configuration for small installations and test rigs, it doesn’t provide features needed for production systems, like database replication. Without these features, the scalability and availability of a MAAS installation is severely constrained. For this reason, we’ve deprecated the use of PostgreSQL inside the MAAS snap, and we provide some alternative means to install and configure MAAS – along with tools to migrate current installations.
When setting up the maas snap via maas init
, one of the available modes is all
. This install mode uses a PostgreSQL server – exclusively for MAAS – inside the snap itself.
While this is a great quick-start configuration for small installations and test rigs, it doesn’t provide features needed for production systems, like database replication. Without these features the scalability of a MAAS installation is severely constrained.
For this reason, we’re deprecating the use of PostgreSQL inside the snap, and providing some helper scripts to set up PostgreSQL for use with MAAS. We’re also providing tools to help migrate current installations. Basically, we’re replacing the all
mode with region+rack
. In this configuration, the region controller connects to an external database over the network.
Installing MAAS with local PostgreSQL
After installing the maas
snap, you can set up PostgreSQL – even if it’s running on a different machine – with the following procedure:
-
You will need to install PostgreSQL on the machine where you want to keep the database. This can be the same machine as the MAAS region/rack controllers or a totally separate machine. If PostgreSQL (version 10 or better) is already running on your target machine, you can skip this step. To install PostgreSQL, run these commands:
sudo apt update -y sudo apt install -y postgresql
-
You want to make sure you have a suitable PostgreSQL user, which can be accomplished with the following command, where
$MAAS_DBUSER
is your desired database username, and$MAAS_DBPASS
is the intended password for that username. Note that if you’re executing this step in a LXD container (as root, which is the default), you may get a minor error, but the operation will still complete correctly.sudo -u postgres psql -c "CREATE USER \"$MAAS_DBUSER\" WITH ENCRYPTED PASSWORD '$MAAS_DBPASS'"
-
Create the MAAS database with the following command, where
$MAAS_DBNAME
is your desired name for the MAAS database (typically known asmaas
). Again, if you’re executing this step in a LXD container as root, you can ignore the minor error that results.sudo -u postgres createdb -O "$MAAS_DBUSER" "$MAAS_DBNAME"
-
Edit
/etc/postgresql/10/main/pg_hba.conf
and add a line for the newly created database, replacing the variables with actual names. You can limit access to a specific network by using a different CIDR than0/0
.host $MAAS_DBNAME $MAAS_DBUSER 0/0 md5
-
You can then initialise MAAS via the following command:
sudo maas init region+rack --database-uri "postgres://$MAAS_DBUSER:$MAAS_DBPASS@$HOSTNAME/$MAAS_DBNAME"
Don’t worry; if you leave out any of the database parameters, you’ll be prompted for those details.
Migrating an existing snap install
If you’re currently running MAAS from a snap in all
mode, you can easily migrate your database to a local PostgreSQL server with the following command:
sudo /snap/maas/current/helpers/migrate-snap-database
This will install PostgreSQL from the archive and migrate the MAAS database to it.
Note that if PostgreSQL is already installed on the machine, the script will move the current datadir out of the way and replace it with the one from the snap, after confirmation with the user. If you want to keep the current database set and just import the MAAS database, you’ll need to perform a manual dump/restore of the MAAS database, explained below.
The migration script will automatically adjust the snap configuration to use the new database. However, note that the target database must be at least the same version as the one currently used in the snap (PostgreSQL 10). Consequently, the migration script only supports Ubuntu 18.04 (bionic) or later.
Manually exporting the MAAS database
If you want to export the database from the snap to an already setup PostgreSQL server, possibly on a different machine, you can manually export it from MAAS as follows. With MAAS running (as this ensures access to the database), run:
export PGPASS=$(sudo awk -F':\\s+' '$1 == "database_pass" {print $2}' \
/var/snap/maas/current/regiond.conf)
sudo pg_dump -U maas -h /var/snap/maas/common/postgres/sockets \
-d maasdb -F t -f maasdb-dump.tar
This will produce a binary dump in maasdb-dump.tar
. You can then stop the MAAS snap via
sudo snap stop maas
Before importing it to the new database server, you need to create a user and database for MAAS:
sudo -u postgres \
psql -c "CREATE USER maas WITH ENCRYPTED PASSWORD '<password>'"
sudo -u postgres createdb maasdb -O maas
Also, make sure that remote access is set up for the newly created maas
user in /etc/postgresql/10/main/pg_hba.conf
. The file should contain a line similar to:
host maasdb maas 0/0 md5
Be sure to replace 0/0
, above, with the proper CIDR to restrict acccess to a specific subnet. Finally, you can import the database dump with:
sudo -u postgres pg_restore -d maasdb maasdb-dump.tar
To finish the process, you’ll need to update the MAAS snap config to:
- update the database config in
/var/snap/maas/current/regiond.conf
with the properdatabase_host
anddatabase_pass
- change the content of
/var/snap/maas/common/snap_mode
fromall
toregion+rack
Using a local PostgreSQL server is a little bit of work, but it provides great benefits in terms of MAAS scalability and performance.