DatabaseFeatured

Syncing MongoDB to Elasticsearch: Installing Monstache on Rocky Linux

Introduction

Monstache is a powerful tool that syncs data from MongoDB to Elasticsearch in real time. This guide will walk you through the process of installing and configuring Monstache on Rocky Linux.

Prerequisites

Before installing Monstache, ensure you have the following:

  • A Rocky Linux server
  • MongoDB installed and running
  • Elasticsearch installed and running
  • wget, unzip, and nano installed

If MongoDB and Elasticsearch are not installed, follow these quick setup guides:

Install MongoDB

Bash
sudo dnf install -y mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongod

Install Elasticsearch

Bash
sudo dnf install -y elasticsearch
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch

Installing Monstache

Download Monstache

Bash
wget https://github.com/rwynn/monstache/releases/download/v7.5.6/monstache-7.5.6-linux-amd64.zip

Unzip the downloaded file

Bash
unzip monstache-7.5.6-linux-amd64.zip cd monstache

Make Monstache executable

Bash
chmod +x monstache

Verify installation

Bash
./monstache -v

If Monstache is installed correctly, it will output the version information.

Configuring Monstache

Create a configuration file monstache.config.toml in the Monstache directory:

Bash
nano monstache.config.toml

Add the following content:

TOML
mongo-url = "mongodb://localhost:27017"
elastic-url = "http://localhost:9200"
enable-http-server = true

Save and exit nano by pressing CTRL + X, then Y, and Enter.

Modify these settings according to your environment.

Running Monstache

Start Monstache using the configuration file:

Bash
./monstache -f monstache.config.toml

To run Monstache as a background service:

Bash
nohup ./monstache -f monstache.config.toml &

Running Monstache as a Systemd Service

To run Monstache as a systemd service, create a new service file:

Bash
sudo nano /etc/systemd/system/monstache.service

Add the following content:

Bash
[Unit]
Description=Monstache Service
After=network.target

[Service]
ExecStart=/path/to/monstache -f /path/to/monstache.config.toml
Restart=always
User=root
Group=root
WorkingDirectory=/path/to/monstache

[Install]
WantedBy=multi-user.target

Replace /path/to/monstache with the actual path where Monstache is installed.

Save and exit nano by pressing CTRL + X, then Y, and Enter.

Then, reload systemd and enable the service:

Bash
sudo systemctl daemon-reload
sudo systemctl enable monstache
sudo systemctl start monstache

To check the status of the service:

Bash
sudo systemctl status monstache

Verifying Sync

To check if Monstache is syncing data correctly:

  1. Insert a document into MongoDB:mongo use testdb db.users.insert({"name": "John Doe", "email": "[email protected]"})
  2. Verify in Elasticsearch:curl -X GET "http://localhost:9200/testdb/_search?pretty"You should see the inserted document in Elasticsearch.

Conclusion

You have successfully installed and configured Monstache on Rocky Linux. Now, MongoDB data will be automatically indexed in Elasticsearch, allowing for powerful search capabilities and real-time synchronization.

Shares: