DEV Community

Cover image for Install Meilisearch on Ubuntu 24.04: The High-Performance Elasticsearch Alternative
Jakson Tate
Jakson Tate

Posted on • Originally published at servermo.com

Install Meilisearch on Ubuntu 24.04: The High-Performance Elasticsearch Alternative

When developers require full-text search capabilities, they frequently default to installing Elasticsearch. This represents a catastrophic architectural blunder for modern web applications. Elasticsearch is built upon the archaic Java Virtual Machine—a bloated ecosystem that demands massive amounts of memory merely to initialize the service.

Operating a Java-based search cluster forces organizations to lease expensive RAM-heavy virtual machines, skyrocketing monthly infrastructure expenditures. Furthermore, configuring Elasticsearch to tolerate basic human typos requires excruciating custom mapping logic.

Meilisearch completely destroys this paradigm. Engineered natively in Rust, it operates as a single, incredibly lightweight binary. It requires mere megabytes of RAM, delivers typo-tolerant search queries out of the box, and guarantees magnificent response times.


Phase 1: The Elasticsearch Performance Trap

Understanding the hardware resource disparity is vital before making architectural choices. Review the empirical benchmark comparison below:

Architectural Metric Legacy Elasticsearch Modern Meilisearch
Core Technology Heavy Java Virtual Machine (JVM) Native Compiled Rust
Minimum Memory Required 4 GB – 8 GB < 50 MB
Typo Tolerance Requires Custom Mapping Scripts Enabled Natively by Default
Average Query Latency ~100 ms Sub-50 ms

Phase 2: The Core Bare Metal Installation

Executing background databases under personal root accounts is a critical security vulnerability. If the search engine is ever compromised, the attacker instantly gains absolute control over the host system. You must create an isolated, restricted system user to run this daemon safely.

# Update system repositories and install curl
sudo apt update && sudo apt install curl -y

# Download the compiled Rust binary and move it to the global execution path
curl -fsSL [https://install.meilisearch.com](https://install.meilisearch.com) | sudo sh
sudo mv ./meilisearch /usr/local/bin/

# Create a restricted system user explicitly denying shell login access
sudo useradd -r -s /usr/sbin/nologin meilisearch

# Provision persistent database, snapshot, and configuration directories securely
sudo mkdir -p /var/lib/meilisearch/data.ms /var/lib/meilisearch/dumps /var/lib/meilisearch/snapshots /etc/meilisearch
sudo chown -R meilisearch:meilisearch /var/lib/meilisearch
Enter fullscreen mode Exit fullscreen mode

Phase 3: The Systemd Security Blueprint

If you launch Meilisearch without a master key, the engine defaults to an unauthenticated development mode, exposing all your indexed data directly to the public internet.

🔑 The Base64 Parsing Trap

Generating keys using Base64 encoding frequently outputs special characters like = and /, which violently break systemd environment parsers. Always generate pure hexadecimal strings to ensure flawless configuration booting.

# Generate a 32-byte secure alphanumeric master key
MEILI_MASTER_KEY=$(openssl rand -hex 32)

# Inject the key securely into an isolated environment file
echo "MEILI_MASTER_KEY=$MEILI_MASTER_KEY" | sudo tee /etc/meilisearch/env >/dev/null
sudo chmod 600 /etc/meilisearch/env
sudo chown meilisearch:meilisearch /etc/meilisearch/env

# Create the primary systemd service configuration file
sudo nano /etc/systemd/system/meilisearch.service
Enter fullscreen mode Exit fullscreen mode

Paste the following hardened configuration block into your service file:

[Unit]
Description=Meilisearch Enterprise Search Engine
After=network.target

[Service]
Type=simple
User=meilisearch
Group=meilisearch
EnvironmentFile=/etc/meilisearch/env

# Production startup arguments: payload overrides, snapshot scheduling, and memory limits
ExecStart=/usr/local/bin/meilisearch \
  --env production \
  --db-path /var/lib/meilisearch/data.ms \
  --dump-dir /var/lib/meilisearch/dumps \
  --snapshot-dir /var/lib/meilisearch/snapshots \
  --schedule-snapshot \
  --snapshot-interval-sec 86400 \
  --http-payload-size-limit 500000000 \
  --max-indexing-memory 2048Mb \
  --http-addr 127.0.0.1:7700

Restart=on-failure
RestartSec=5

# SRE HIDDEN GEM: Unlock high socket throughput to prevent connection crashes
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode

Enable and boot your newly configured service:

sudo systemctl daemon-reload
sudo systemctl enable --now meilisearch
sudo systemctl status meilisearch
Enter fullscreen mode Exit fullscreen mode

Phase 4: Conquering the Payload Limit Trap

When attempting to import large databases, developers frequently collide with a fatal 413 Payload Too Large error. By default, Meilisearch restricts incoming HTTP requests to 100 MB.

We resolved this inside the systemd service above by passing --http-payload-size-limit 500000000 (500 MB).

⚠️ The Gzip Memory Explosion

Compressing a 5 GB database with Gzip and transmitting it in a single command is a dangerous trap. While Gzip reduces transfer time, Meilisearch must decompress the file directly into active RAM, triggering an immediate Out of Memory (OOM) kernel panic.

To import massive enterprise datasets safely, use newline-delimited JSON (.ndjson) and slice your file into ~100,000-row chunks:

# Split your massive dataset into manageable batches
split -l 100000 massive_database.ndjson chunk_

# Stream batches sequentially
curl -X POST '[http://127.0.0.1:7700/indexes/products/documents](http://127.0.0.1:7700/indexes/products/documents)' \
  -H 'Content-Type: application/x-ndjson' \
  -H "Authorization: Bearer YOUR_SECURE_MASTER_KEY" \
  --data-binary @chunk_aa
Enter fullscreen mode Exit fullscreen mode

Phase 5: Eradicating OOM Killer Crashes

During intensive indexing operations, Meilisearch aggressively uses RAM to process tokens and typos. If memory is unconstrained, the Linux Kernel OOM killer will terminate the process to save the host OS.

We protected against this by setting --max-indexing-memory 2048Mb in our systemd service. Additionally, we enabled snapshot persistence (--schedule-snapshot and --snapshot-interval-sec 86400) to guarantee durable daily backups written directly to disk.


Phase 6: The Enterprise Nginx Reverse Proxy

Since Meilisearch listens strictly on 127.0.0.1:7700, wrap it behind an Nginx reverse proxy with SSL encryption to expose it safely to your web applications:

# Install Nginx and Let's Encrypt Certbot
sudo apt install nginx certbot python3-certbot-nginx -y

# Create site configuration
sudo nano /etc/nginx/sites-available/meilisearch
Enter fullscreen mode Exit fullscreen mode

Paste the routing configuration (ensuring client_max_body_size matches your Meilisearch payload limit):

server {
    listen 80;
    server_name search.yourdomain.com;

    # Match Meilisearch payload limits to prevent Nginx 413 blocks
    client_max_body_size 500M;

    location / {
        proxy_pass [http://127.0.0.1:7700](http://127.0.0.1:7700);
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_read_timeout 60s;
    }
}
Enter fullscreen mode Exit fullscreen mode

Activate the routing rule and apply SSL encryption:

sudo ln -s /etc/nginx/sites-available/meilisearch /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

# Issue Let's Encrypt SSL Certificate
sudo certbot --nginx -d search.yourdomain.com
Enter fullscreen mode Exit fullscreen mode

Phase 7: The ServerMO Bare Metal Advantage

Deploying memory-intensive search engines on shared public cloud instances introduces noisy-neighbor latency and choke points on shared hypervisor disk I/O.

Hosting your search clusters on ServerMO Dedicated Bare Metal Servers gives you unshared access to ultra-fast NVMe storage and unmetered network performance—delivering lightning-fast, sub-50ms search queries as your users type.


💬 Frequently Asked Questions

Why is Meilisearch faster than Elasticsearch?

Elasticsearch relies on a heavy Java Virtual Machine that demands significant RAM and computing overhead. Meilisearch is compiled natively in Rust, delivering typo-tolerant, sub-50ms responses using under 50 MB of initial memory.

How do I fix the Meilisearch "Payload Too Large" error?

Meilisearch caps HTTP payloads at 100 MB by default. Pass --http-payload-size-limit 500000000 to your startup flags and chunk massive import files into 100,000-line .ndjson batches.

How do I prevent the Linux OOM killer from crashing Meilisearch?

Set a strict memory ceiling during indexing using the --max-indexing-memory 2048Mb parameter in your systemd service file.

Why did my Meilisearch service crash with "too many open files"?

High concurrency can exhaust the default Linux file descriptor limits. Add LimitNOFILE=65536 inside your systemd service file under the [Service] block to handle heavy production traffic.


👉 Read the full engineering guide on ServerMO:

Install Meilisearch Ubuntu 24.04: Elasticsearch Alternative | ServerMO

Top comments (0)