Comprehensive Architectural Deployment of the Elastic (ELK) Stack on Ubuntu Linux

The Elastic Stack, colloquially known as the ELK stack, represents a powerful ecosystem of open-source projects designed to provide a centralized platform for log aggregation, real-time analysis, and sophisticated data visualization. In the modern landscape of distributed systems and microservices, the ability to ingest massive volumes of telemetry data and transform it into actionable insights is a critical requirement for operational stability. The stack is composed of three core pillars: Elasticsearch, Logstash, and Kibana. Elasticsearch serves as the distributed search and analytics engine, utilizing a RESTful API to manage schema-free JSON documents. Logstash acts as the server-side data processing pipeline, capable of ingesting data from disparate sources, transforming it through various filters, and shipping it to a destination. Kibana provides the window into this data, offering a web-based user interface for creating dashboards, histograms, and geospatial visualizations. Deploying this stack on Ubuntu—ranging from the long-term support (LTS) versions 20.04 and 22.04 to the latest 24.04 Noble Numbat—requires a precise sequence of environment preparation, repository configuration, and component tuning to ensure high availability and performance.

Fundamental System Requirements and Resource Allocation

Before initiating the installation process, it is imperative to align the hardware specifications with the demands of the Elastic Stack. Because Elasticsearch is a memory-intensive application that relies heavily on the Java Virtual Machine (JVM), insufficient resources will lead to frequent Out-Of-Memory (OOM) kills or severe performance degradation.

The following table delineates the minimum and recommended resource allocations per component:

Component Minimum RAM Recommended RAM CPU Requirement Minimum Disk Space
Elasticsearch 2GB 4GB+ 2 Cores 50GB+
Logstash 1GB 2GB+ 1 Core 10GB
Kibana 1GB 2GB+ 1 Core 1GB
Total Stack 4GB 8GB+ 4 Cores 61GB+

The technical justification for these requirements stems from the way Elasticsearch indexes data; it requires significant heap space to maintain the inverted index and handle concurrent search queries. From an impact perspective, running the stack on a machine with less than 4GB of RAM will likely result in the failure of the Elasticsearch service to start or an inability to handle basic query loads, rendering the monitoring system useless. Contextually, these requirements imply that for production environments, a dedicated server or a high-resource virtual machine is mandatory, rather than a lightweight container or a low-tier VPS.

Phase 1: Environment Preparation and Java Runtime Installation

The Elastic Stack is developed in Java, making the Java Runtime Environment (JRE) or Java Development Kit (JDK) a strict prerequisite. Without a compatible Java installation, the Elasticsearch binary cannot execute.

The initial step involves ensuring the operating system is current to avoid dependency conflicts.

sudo apt update
sudo apt upgrade -y

For Ubuntu 24.04 and other recent versions, OpenJDK 17 is the recommended stable LTS release. This version provides the necessary performance enhancements and security patches required for the 8.x series of the Elastic Stack.

sudo apt install openjdk-17-jdk -y
OR for a headless environment (server without GUI):
sudo apt install openjdk-17-jre-headless -y

To verify the successful installation of the runtime, the version command must be executed:

java -version

The technical necessity of using the -headless version in server environments is to reduce the installation footprint by removing GUI-related libraries that are unnecessary for a background service. The real-world impact of skipping this step is a catastrophic failure during the Elasticsearch service startup, as the system will be unable to locate the java executable in the system path.

Phase 2: Configuring the Elastic Repository and GPG Keys

The Elastic Stack components are not hosted in the default Ubuntu APT repositories. To install and maintain them via the package manager, the official Elastic repository must be added. This involves a two-step process: importing the GPG key to ensure package integrity and adding the repository URL to the sources list.

The GPG key is essential for security; it allows the APT package manager to verify that the software downloaded from the Elastic servers has not been tampered with by a third party.

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg

Once the key is securely stored in the keyring, the repository definition is added to the system:

echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list

After adding the repository, the local package cache must be refreshed:

sudo apt update

In some instances, particularly on Ubuntu 24.04, users may encounter PGP key errors such as NO_PUBKEY D27D666CD88E42B4. This occurs if the key import fails or if the system expects the key in a specific directory. The resolution is to re-run the wget and gpg --dearmor sequence precisely as described. If the repository method continues to fail, an alternative administrative path is to download the .deb package directly and install it using dpkg -i.

Phase 3: Elasticsearch Installation and Deep Configuration

Elasticsearch is the heart of the stack, providing the indexing and search capabilities.

sudo apt install elasticsearch -y

After installation, the primary configuration file must be modified to define the node's behavior and network accessibility. This is handled via the elasticsearch.yml file.

sudo nano /etc/elasticsearch/elasticsearch.yml

The following configuration parameters are critical for a single-node deployment:

  • cluster.name: elk-cluster (Defines the identity of the cluster)
  • node.name: node-1 (Assigns a specific name to this instance)
  • path.data: /var/lib/elasticsearch (Specifies where the indexed data is stored)
  • path.logs: /var/log/elasticsearch (Specifies the location of system logs)
  • network.host: localhost (Restricts access to the local machine for security)
  • http.port: 9200 (The default port for REST API communication)
  • discovery.type: single-node (Tells Elasticsearch not to look for other nodes, preventing bootstrap errors)

Security is a paramount concern. The X-Pack security settings must be enabled to protect the data from unauthorized access:

xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl.enabled: true
xpack.security.transport.ssl.enabled: true

The technical implication of enabling SSL/TLS is that all communications between the components (Kibana to Elasticsearch) must be encrypted. This prevents "man-in-the-middle" attacks where sensitive log data could be intercepted.

Phase 4: JVM Heap Tuning and Service Initialization

Elasticsearch performance is heavily dependent on the JVM heap size. By default, the heap may be set too low or too high for the available system RAM. The general rule of thumb is to allocate 50% of the available physical RAM to the JVM, but not exceeding 31GB to avoid the overhead of compressed object pointers.

To configure the heap:

sudo nano /etc/elasticsearch/jvm.options.d/heap.options

Add the following lines (assuming 4GB of RAM, we allocate 2GB):

-Xms2g
-Xmx2g

Once the tuning is complete, the service must be enabled to start on boot and then manually started:

sudo systemctl daemon-reload
sudo systemctl enable elasticsearch
sudo systemctl start elasticsearch

To verify that the service is operational:

sudo systemctl status elasticsearch

Because security is enabled, the elastic superuser requires a password. This can be generated using the built-in reset tool:

sudo /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic

This command generates a secure password that must be recorded immediately. The impact of losing this password is a total lockout from the cluster management API, necessitating a full reset of the security configuration.

Phase 5: Kibana Installation and Visualization Setup

Kibana serves as the user interface for the Elastic Stack. It allows administrators to query the data indexed in Elasticsearch and build visual dashboards.

sudo apt install kibana -y

The Kibana configuration file governs how the UI is served and how it connects to the backend.

sudo nano /etc/kibana/kibana.yml

Key settings include:

  • server.port: 5601 (The default port for the web interface)
  • server.host: "0.0.0.0" (Allows Kibana to be accessed from any IP address, essential for remote access)
  • server.name: "kibana-server" (A descriptive name for the server instance)

For production environments, exposing Kibana directly to the internet on port 5601 is a security risk. It is strongly recommended to install Nginx as a reverse proxy. This allows the administrator to implement a TLS/SSL certificate, ensuring that the login page and the data dashboards are encrypted.

Phase 6: Data Ingestion with Logstash and Filebeat

While Elasticsearch stores data, it does not "collect" it. Logstash and Filebeat are used to ship data into the cluster. Logstash is a heavy-duty processor, while Filebeat is a lightweight shipper.

Installing Filebeat

Filebeat is often installed on the servers where the logs are actually generated (e.g., a web server).

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.9.2-amd64.deb
sudo dpkg -i filebeat-8.9.2-amd64.deb

The configuration of Filebeat involves defining which files to monitor.

sudo nano /etc/filebeat/filebeat.yml

Within the filestream input section, the following configuration is applied to monitor Apache logs:

  • enabled: true (Activates the input)
  • paths: ["/var/log/*.log", "/var/log/apache2/*.log"] (The glob patterns for log files)

To route data through Logstash instead of sending it directly to Elasticsearch, the output.elasticsearch section must be commented out, and the output.logstash section enabled:

output.logstash.hosts: ["192.168.x.x:5044"]

The technical reason for using Filebeat as a shipper for Logstash (rather than Logstash reading files directly) is to reduce the resource load on the source server. Filebeat is written in Go and has a minimal footprint, whereas Logstash is Java-based and consumes significantly more RAM.

sudo systemctl enable filebeat && sudo systemctl start filebeat
sudo systemctl status filebeat

Verification of the Full Stack Integration

To ensure the entire pipeline is functioning, the administrator must verify the connectivity between the layers.

  1. Test Elasticsearch connectivity using the generated password:
    curl -k -u elastic:YOUR_PASSWORD https://localhost:9200

  2. Access the Kibana dashboard via a web browser at http://<SERVER_IP>:5601.

  3. Verify that Filebeat is shipping logs by checking the "Discover" tab in Kibana to see if the log entries from /var/log/apache2/*.log are appearing in real-time.

Conclusion: Strategic Analysis of ELK Deployment

The installation of the Elastic Stack on Ubuntu is not merely a sequence of commands but an exercise in systems engineering. The interdependence of the three components creates a rigid requirement for version parity; as noted, using the same version across Elasticsearch, Logstash, and Kibana is mandatory to avoid API incompatibilities.

The transition from basic installation to a production-ready environment requires a shift in focus toward security and resource management. The implementation of X-Pack security and the use of an Nginx reverse proxy are not optional for any system exposed to a network. Furthermore, the "Deep Drilling" into JVM heap settings demonstrates that the success of an ELK deployment is determined by the underlying hardware's ability to support the Java runtime.

From a DevOps perspective, the move toward a "Beats -> Logstash -> Elasticsearch -> Kibana" architecture (the refined ELK stack) allows for a highly scalable telemetry pipeline. By offloading the initial data collection to lightweight agents like Filebeat and Metricbeat, organizations can monitor hundreds of servers without overloading their source infrastructure. This architectural decision transforms the stack from a simple log viewer into a comprehensive observability platform capable of handling terabytes of data with sub-second search latency. The final result is a robust, encrypted, and scalable monitoring solution that provides total visibility into the health and security of the digital infrastructure.

Sources

  1. LinuxTechi
  2. OneUptime
  3. Elastic Discuss
  4. PortForwarded
  5. DigitalOcean

Related Posts