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
, andnano
installed
If MongoDB and Elasticsearch are not installed, follow these quick setup guides:
Install MongoDB
sudo dnf install -y mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongod
Install Elasticsearch
sudo dnf install -y elasticsearch
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch
Installing Monstache
Download Monstache
wget https://github.com/rwynn/monstache/releases/download/v7.5.6/monstache-7.5.6-linux-amd64.zip
Unzip the downloaded file
unzip monstache-7.5.6-linux-amd64.zip cd monstache
Make Monstache executable
chmod +x monstache
Verify installation
./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:
nano monstache.config.toml
Add the following content:
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:
./monstache -f monstache.config.toml
To run Monstache as a background service:
nohup ./monstache -f monstache.config.toml &
Running Monstache as a Systemd Service
To run Monstache as a systemd service, create a new service file:
sudo nano /etc/systemd/system/monstache.service
Add the following content:
[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:
sudo systemctl daemon-reload
sudo systemctl enable monstache
sudo systemctl start monstache
To check the status of the service:
sudo systemctl status monstache
Verifying Sync
To check if Monstache is syncing data correctly:
- Insert a document into MongoDB:
mongo use testdb db.users.insert({"name": "John Doe", "email": "[email protected]"})
- 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.