MeshCentral Migration with PostgreSQL on Debian 12
Updated On: Feb. 24, 2025 Author: Kevin

MeshCentral Migration with PostgreSQL on Debian 12

This tutorial explains how to migrate MeshCentral to a new Debian 12 server using PostgreSQL as the database backend. It also covers transferring the meshcentral-data directory, which contains critical files such as certificates.

1. Install Node.js 23.x

Follow these steps to install Node.js 23.x on your Debian 12 server:

# Ensure curl is installed
sudo apt-get install -y curl

# Download the Node.js 23.x setup script
curl -fsSL https://deb.nodesource.com/setup_23.x -o nodesource_setup.sh

# Run the setup script
sudo -E bash nodesource_setup.sh

# Install Node.js
sudo apt-get install -y nodejs

# Verify the installation
node -v

2. Install PostgreSQL

Set up PostgreSQL to serve as the database for MeshCentral:

sudo apt update
sudo apt -y install postgresql
sudo systemctl start postgresql
sudo systemctl enable postgresql

Verify that PostgreSQL is running:

sudo systemctl status postgresql

3. Configure PostgreSQL for MeshCentral

Log in to PostgreSQL and configure the database and user:

sudo -u postgres psql
CREATE DATABASE meshcentral;
CREATE USER meshadmin WITH ENCRYPTED PASSWORD 'yourpassword';
GRANT ALL PRIVILEGES ON DATABASE meshcentral TO meshadmin;
\q

Replace yourpassword with the password you will use in MeshCentral's config.json.

4. Transfer Existing MeshCentral Data

On the old server, stop the MeshCentral service to avoid conflicts while transferring files:

sudo systemctl stop meshcentral

Transfer the meshcentral-data directory, which contains your certificates and other critical data, to the new server:

scp -r /path/to/meshcentral-data user@newserver:/path/to/destination

On the new server, move the transferred directory to the appropriate location (e.g., /home/kevin/meshcentral/):

mv /path/to/destination/meshcentral-data /home/kevin/meshcentral/

5. Install and Configure MeshCentral

Install MeshCentral on the new server:

npm install meshcentral

Export your database on the old server:

node ./node_modules/meshcentral --dbexport dbbackup.json

Transfer the database backup to your new server:

scp dbbackup.json user@newserver:/path/to/destination

On the new server, import the database:

node ./node_modules/meshcentral --dbimport /path/to/dbbackup.json

6. Create a Systemd Service for MeshCentral

Create a systemd service file to manage MeshCentral:

sudo nano /etc/systemd/system/meshcentral.service

Add the following content to the file:

[Unit]
Description=MeshCentral Server
[Service]
Type=simple
LimitNOFILE=1000000
ExecStart=/usr/bin/node /home/kevin/meshcentral/node_modules/meshcentral
WorkingDirectory=/home/kevin/meshcentral
Environment=NODE_ENV=production
User=kevin
Group=kevin
Restart=always
# Restart service after 10 seconds if node service crashes
RestartSec=10
# Set port permissions capability
AmbientCapabilities=cap_net_bind_service
[Install]
WantedBy=multi-user.target

Enable and start the service:

sudo systemctl enable meshcentral.service
sudo systemctl start meshcentral.service
sudo systemctl status meshcentral.service

7. Verify the Setup

Access your MeshCentral instance at the configured URL (e.g., https://yourdomain.com) and confirm it is working as expected. Check the logs if you encounter issues.

8. Cleanup

Remove the database export file after confirming the setup:

rm dbbackup.json

Conclusion

You have successfully migrated MeshCentral to a new Debian 12 server using PostgreSQL. Transferring the meshcentral-data directory ensures that your SSL certificates and other critical data are preserved for a seamless transition.

 

 

This is another great resource to understand how migrations are done in Mesh Central