Skip to main content
Back to Articles
Server & DevOpsOctober 3, 202412 min read

How to Set Up OpenSearch for Magento 2.4.7 on Ubuntu 22.04/24.04

Step-by-step instructions for installing and configuring OpenSearch for Magento 2.4.7 on Ubuntu, including single-node setup, optional cluster configuration, security certificates, and Magento integration.

Setting Up OpenSearch for Magento 2.4.7 on Ubuntu

Magento 2.4.7 relies on OpenSearch for optimal search functionality. Properly setting up OpenSearch is crucial to enhance site search performance and improve user experience. This guide provides step-by-step instructions to install and configure OpenSearch for Magento on Ubuntu 22.04/24.04, including setting up an OpenSearch cluster for scalability and high availability.

Prerequisites

  • System Requirements:
    • Ubuntu 22.04 LTS or Ubuntu 24.04 LTS installed.
    • Root or sudo user privileges.
    • Minimum hardware requirements for Magento and OpenSearch.
  • Installed Software:
    • Java 11 or higher (required for OpenSearch).
    • LAMP/LEMP stack (Linux, Apache/Nginx, MySQL/MariaDB, PHP) for Magento.
    • Composer (for Magento installation).

Step 1: Update System Packages

sudo apt update
sudo apt upgrade -y

Step 2: Install Java

sudo apt install openjdk-11-jdk -y
java -version

Step 3: Install OpenSearch

Add the official OpenSearch repository and install:

sudo apt update
sudo apt install opensearch -y

Adding the official OpenSearch repository ensures we get the latest version compatible with Magento 2.4.7.

Step 4: Configure OpenSearch

Single-Node Configuration

Edit the configuration file:

sudo nano /etc/opensearch/opensearch.yml

Update these key settings:

cluster.name: magento-cluster
node.name: node-1
network.host: 127.0.0.1
plugins.security.disabled: true  # Disable security for development only

This configures OpenSearch to communicate with Magento on the local machine. Note: Disabling security is not recommended for production environments.

Optional: Configuring an OpenSearch Cluster

For high availability and scalability, we can configure an OpenSearch cluster.

Step 4.1: Prepare Multiple Nodes

Requirements:

  • At least two or more servers with Ubuntu 22.04/24.04.
  • Each node should have OpenSearch installed following the steps above.

Step 4.2: Configure Each Node

Edit /etc/opensearch/opensearch.yml on each node with these settings:

cluster.name: magento-cluster
node.name: node-1  # Change for each node (node-2, node-3, etc.)
network.host: 0.0.0.0
discovery.seed_hosts: ["node1-ip", "node2-ip", "node3-ip"]
cluster.initial_master_nodes: ["node-1", "node-2"]

Key settings explained:

  • cluster.name: Must be identical across all nodes.
  • node.name: Unique identifier for each node.
  • discovery.seed_hosts: Lists all node IPs for cluster formation.
  • cluster.initial_master_nodes: Helps form the initial cluster.

Step 4.3: Configure Firewall and Network Settings

Allow OpenSearch ports on all nodes:

sudo ufw allow 9200/tcp
sudo ufw allow 9300/tcp
  • Port 9200 is used for REST API calls.
  • Port 9300 is used for node-to-node communication.

Step 4.4: Generate Security Certificates

Navigate to the OpenSearch directory:

cd /usr/share/opensearch/

Generate certificates using the OpenSearch security plugin:

sudo plugins/opensearch-security/tools/securityadmin.sh -cd plugins/opensearch-security/securityconfig/ -ca -cert

Distribute certificates to all nodes and ensure proper permissions are set.

Step 5: Start and Enable OpenSearch

sudo systemctl enable opensearch
sudo systemctl start opensearch

Verify service status:

sudo systemctl status opensearch

Step 6: Install Magento 2.4.7

(Skip if Magento is already installed.)

Install Composer:

sudo apt install composer -y

Set up the web server and PHP extensions:

  • Install Apache/Nginx, PHP 8.x, and required PHP extensions.

Create the Magento project:

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.7

Set file permissions and ownership, then create a MySQL/MariaDB database and user for Magento.

Run the Magento installation script:

bin/magento setup:install --base-url=http://your-domain.com/ \
--db-host=localhost --db-name=magento --db-user=magento_user --db-password=your_password \
--admin-firstname=Admin --admin-lastname=User --admin-email=admin@example.com \
--admin-user=admin --admin-password=Admin123 --language=en_US \
--currency=USD --timezone=America/Chicago --use-rewrites=1 \
--search-engine=opensearch --opensearch-host=127.0.0.1 --opensearch-port=9200

Step 7: Configure Magento to Use OpenSearch

If Magento was already installed, update the search engine configuration:

bin/magento config:set catalog/search/engine opensearch
bin/magento config:set catalog/search/opensearch_server_hostname 127.0.0.1
bin/magento config:set catalog/search/opensearch_server_port 9200
bin/magento indexer:reindex catalogsearch_fulltext
bin/magento cache:flush

Step 8: Verify the Setup

Check OpenSearch cluster health:

curl -XGET 'http://127.0.0.1:9200/_cluster/health?pretty'

List cluster nodes:

curl -XGET 'http://127.0.0.1:9200/_cat/nodes?v'

Test Magento store search functionality:

  • Perform a search on the frontend to ensure results are returned correctly.

Monitor logs for errors:

sudo tail -f /var/log/opensearch/opensearch.log

By following these steps, we have successfully installed and configured OpenSearch with Magento 2.4.7 on Ubuntu, including an optional cluster setup for high availability and scalability. Using OpenSearch enhances search functionality and improves the overall user experience on the Magento store. We recommend keeping systems updated and secure, especially in production environments.

Need help with this?

Our team handles this kind of work daily. Let us take care of your infrastructure.