How to Set Up Centralized Log Management with Graylog on a VPS

Logs on a small VPS start out helpful and end up everywhere. Nginx writes one file, the system writes another, the database writes a third, and when something breaks at 2 a.m., you are reading four files over SSH trying to connect the dots. Centralized log management fixes that by sending every log to one place where you can search it. This guide shows how to set up centralized log management with graylog on a VPS, with the pieces sized for a small server rather than a data centre.

Graylog is an open-source log management platform. It collects logs from your servers, stores them in a searchable index, and gives you a web interface to search, alert, and build dashboards. It is heavier than a simple log file, and it needs three services to run: Graylog itself, MongoDB for its configuration, and OpenSearch for storing the logs. That sounds like a lot for one VPS, but on a 2 GB server with a modest log volume, it runs fine, and the payoff is a single search box for every log you own.

Centralized Log Management with Graylog: How the Pieces Fit

Think of Graylog as three layers. The input layer receives logs, usually over syslog, from your servers and applications. The storage layer, OpenSearch, indexes those logs so a search across millions of lines returns in seconds. The interface layer is the Graylog web UI, where you search, create alerts, and watch dashboards. MongoDB sits underneath holding Graylog’s own settings: users, inputs, streams, and dashboards.

Your VPS sends its logs to Graylog with a shipper, and the simplest shipper is the syslog daemon already running on the server. Configure rsyslog to forward a copy of each log line to the Graylog input, and the logs arrive in near real time. Application logs from Nginx, PHP, and your database join the system logs in the same stream, so one search can follow a request from the web server through the application and into the database. If your logs are currently filling the disk, read the guide to stopping logs from filling the disk first, because centralizing logs you never rotate just moves the problem to a bigger disk.

Planning a Graylog Setup on a Small VPS

A centralized logging small server setup starts with honest sizing, and a graylog setup vps owners run happily usually starts at 2 GB of RAM and 2 CPU cores, with at least 20 GB of free disk for the log index. OpenSearch is the hungry part: give it a fixed heap size, around half the server’s memory, and never let it take all of it, or the rest of the system starves. Graylog itself and MongoDB are lighter. If your VPS also runs the website, size carefully, because a log server competing with the site for memory helps nobody. On a busy server, run Graylog on its own small VPS instead.

Plan your retention before you install anything. Logs arrive constantly, and an index with no retention policy grows until the disk fills. Decide how long to keep logs: thirty days is a good default for a small server. Graylog rotates indexes on a schedule you set, deleting the oldest index when the retention limit is reached. That decision, made once, prevents the most common Graylog failure, which is a full disk three months after installation.

Use Docker Compose for the install. It keeps the three services in containers with a single configuration file, and it makes upgrades a matter of changing a version tag and recreating the containers. The official Graylog Docker Compose file is a solid starting point. Adjust the memory settings and the ports before you start it, and keep the Compose file in version control or at least backed up with the rest of /etc.

Installing Graylog with Docker Compose

A graylog ubuntu install through Docker starts with Docker itself, then a Compose file defining the three services: MongoDB, OpenSearch, and Graylog. OpenSearch needs a couple of system settings first, notably a higher virtual memory map count, which you set with sysctl. Without it, OpenSearch refuses to start, and the error message does not make the cause obvious. Set vm.max_map_count to at least 262144 and make it permanent in sysctl.conf.

Start MongoDB and OpenSearch first, wait for them to report healthy, then start Graylog. Graylog takes a minute or two to come up, and its first-run wizard creates the admin account. Change the default password immediately, and set a proper password secret in the configuration. Graylog’s secrets protect the session data, and leaving the example values in place is a security hole that scanners know how to find. Put the Graylog web interface behind a firewall or a reverse proxy with authentication, and never expose the raw port to the internet.

Once the UI loads, create your first input. A syslog UDP input on port 1514 is the standard starting point, because most Linux services can send syslog without extra software. Note the port and protocol, because every shipper you configure later needs to match them exactly. A mismatch here is the most common reason logs never arrive, and Graylog gives you no error when an input simply receives nothing.

Sending Logs from Your Servers to Graylog

Point rsyslog at Graylog with a forwarding rule that sends a copy of each message to the Graylog input over UDP or TCP. UDP is lighter and never blocks the sender, but it can lose messages on a busy network. TCP guarantees delivery but can block the application if Graylog stops responding. For a small setup, UDP is fine for system logs, and TCP is worth it for the logs you cannot afford to lose, such as payment or authentication events.

Nginx access and error logs deserve their own attention. Ship them through rsyslog or a dedicated forwarder so they land in Graylog with their fields intact. Once they are in, you can search for 5xx errors, slow requests, and suspicious patterns across all your sites at once, instead of grepping one file at a time. The guide to Nginx access and error logs explains what those lines mean, which helps you write searches that find real problems instead of noise.

Searching, Alerting, and Dashboards

Graylog’s search is where the setup pays for itself. Search for an error string across all servers and all services in one query, narrow it by time, and save the search if you will run it again. When the site goes down, the first search is usually the error message from the browser, and Graylog shows you every matching line from every server within seconds. That beats opening four SSH sessions and tailing four files.

Set up two alerts first and add more later. Alert on a spike in 5xx responses from Nginx, and alert when a service logs an error it has never logged before. Alerts go to email or a webhook, and they should fire rarely enough that you read them. An alert that fires ten times a day gets ignored, and an ignored alert is the same as no alert. Tune the thresholds after the first week, once you know what normal looks like for your servers.

Build one dashboard with the numbers you actually check: requests per minute, error rate, disk usage warnings, and failed SSH logins. Keep it to four or five panels. A dashboard with thirty panels is a dashboard nobody reads. The goal is a single screen that tells you whether the servers are healthy, and it should take ten seconds to read.

Keeping Graylog Healthy on a Small Server

Graylog’s own health needs attention. Watch the disk, because the log index grows every day and retention is the only thing that stops it. Watch OpenSearch’s heap, because an undersized heap makes searches slow and an oversized one starves Graylog. Watch the input buffers, because a full buffer means logs are being dropped. A weekly five-minute check of the Graylog system overview page covers all three.

Back up Graylog’s configuration, which lives in MongoDB, and keep the Compose file with it. The log data itself is less critical: if the index is lost, you lose history, but the servers keep producing new logs. The configuration is what takes hours to rebuild, so back that up nightly with the same routine that covers the rest of the server. The Prometheus and Grafana setup guide for a 2 GB VPS is a useful companion if you also want metrics alongside logs, and the guide to monitoring disk, RAM, and CPU usage covers the host-level checks Graylog does not do.

Centralized logging is not about collecting more logs. It is about finding the one line that matters in seconds instead of minutes. Set up Graylog on a quiet afternoon, point two servers at it, write your first two alerts, and use it the next time something breaks. That first fast diagnosis is when the setup pays for itself.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.