Magento 2.4.7 is a powerful e-commerce platform that 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
Commands:
sudo apt update
sudo apt upgrade -y
Explanation: Ensure all system packages are up-to-date to avoid compatibility issues.
Step 2: Install Java
Commands:
sudo apt install openjdk-11-jdk -y
Verification:
java -version
Explanation: OpenSearch requires Java; installing OpenJDK 11 satisfies this dependency.
Step 3: Install OpenSearch
Add OpenSearch Repository:
Import GPG key:
wget -qO - https://artifacts.opensearch.org/publickeys/opensearch.pgp | sudo apt-key add -
Add repository to sources list:
echo "deb https://artifacts.opensearch.org/releases/bundle/opensearch/1.x/apt stable main" | sudo tee /etc/apt/sources.list.d/opensearch.list
Install OpenSearch:
sudo apt update
sudo apt install opensearch -y
Explanation: Adding the official OpenSearch repository ensures you get the latest version compatible with Magento 2.4.7.
Step 4: Configure OpenSearch
Single-Node Configuration
Edit Configuration File:
sudo nano /etc/opensearch/opensearch.yml
Key Settings to Update:
cluster.name: magento-cluster
node.name: node-1
network.host: 127.0.0.1
plugins.security.disabled: true # Disable security for development only
Explanation: Configuring OpenSearch to communicate with Magento on the local machine. Note: Disabling security is not recommended for production environments.
Optional: Configuring an OpenSearch Cluster
If you need a clustered setup for high availability and scalability, follow these steps to 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 Steps 1-3.
Java Installation on All Nodes:
sudo apt install openjdk-11-jdk -y
Step 4.2: Configure OpenSearch on Each Node
Edit Configuration File on Each Node:
sudo nano /etc/opensearch/opensearch.yml
Update the Following Settings:
cluster.name: magento-cluster # Same on all nodes
node.name: node-1 # Replace with node-2, node-3, etc., on other nodes
network.host: 0.0.0.0
discovery.seed_hosts: ["node1_ip", "node2_ip", "node3_ip"]
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
plugins.security.disabled: false # Enable security for production
Explanation:
- cluster.name: Ensures all nodes belong to the same cluster.
- node.name: Unique identifier for each node.
- network.host: Set to
0.0.0.0
to listen on all interfaces. - discovery.seed_hosts: IP addresses or hostnames of all nodes in the cluster.
- cluster.initial_master_nodes: Helps in forming the initial cluster.
- plugins.security.disabled: Enable security for production environments.
Step 4.3: Configure Firewall and Network Settings
Allow OpenSearch Ports on All Nodes:
sudo ufw allow 9200/tcp
sudo ufw allow 9300/tcp
Explanation:
- 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 OpenSearch Directory:
cd /usr/share/opensearch/
Generate Certificates Using OpenSearch Security Plugin:
sudo plugins/opensearch-security/tools/securityadmin.sh -cd plugins/opensearch-security/securityconfig/ -ca -cert
Distribute Certificates to All Nodes:
- Copy the generated certificates to the corresponding directories on each node.
- Ensure the certificates are properly secured and permissions are set.
Explanation: Secure communication between nodes is crucial in a cluster setup. Certificates ensure encrypted communication and authentication.
Step 4.5: Start OpenSearch Service on All Nodes
Commands:
sudo systemctl enable opensearch
sudo systemctl start opensearch
Verify Cluster Health:
curl -XGET 'http://localhost:9200/_cluster/health?pretty'
Explanation: Starting the service on all nodes brings the cluster online. Checking the cluster health ensures all nodes are connected.
Step 4.6: Update Magento Configuration for Cluster
In Magento Configuration (Covered in Step 7):
- When specifying the Hostname, use the load balancer IP or domain name if one is set up.
- Alternatively, you can configure Magento to communicate with any node in the cluster.
Explanation: Magento can communicate with any node in the OpenSearch cluster. For high availability, consider using a load balancer in front of the OpenSearch cluster.
Step 5: Start and Enable OpenSearch Service
Commands:
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 Web Server and PHP Extensions:
- Install Apache/Nginx, PHP 8.x, and required PHP extensions.
Create Magento Project:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.7
Set File Permissions and Ownership.
Set Up Database:
- Create a MySQL/MariaDB database and user for Magento.
Run 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
Explanation: Provides a complete Magento installation for integration with OpenSearch.
Step 7: Configure Magento to Use OpenSearch
Update Magento Configuration:
- Open Magento admin panel.
- Navigate to Stores > Configuration > Catalog > Catalog > Catalog Search.
- Set Search Engine to OpenSearch.
Specify OpenSearch Server Details:
- Hostname:
127.0.0.1
(or the IP of your OpenSearch node or load balancer) - Port:
9200
Test Connection:
- Use the Test Connection button to verify Magento can communicate with OpenSearch.
Save Configuration and Reindex:
bin/magento indexer:reindex
Explanation: Configuring Magento to use OpenSearch enhances search capabilities and performance.
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
Explanation: Ensures both OpenSearch cluster and Magento are functioning together without issues.
Conclusion
By following these steps, you've 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 your Magento store. Remember to keep your systems updated and secure, especially in production environments.
Additional Tips
Security Considerations:
- For production, enable security features in OpenSearch.
- Use SSL/TLS certificates for secure communication between nodes and with Magento.
- Implement proper authentication and authorization.
Performance Tuning:
- Allocate appropriate system resources to OpenSearch.
- Optimize OpenSearch and Magento configurations for better performance.
- Consider using dedicated master, data, and coordinating nodes in the cluster.
Regular Maintenance:
- Monitor OpenSearch cluster health and performance.
- Keep backups of configurations and data.
- Regularly update OpenSearch and Magento to the latest versions.
References
- Official Magento Documentation
- OpenSearch Installation Guide
- OpenSearch Cluster Setup
- Ubuntu System Administration Resources
By following this guide, you should have a fully functional Magento store with OpenSearch configured, providing enhanced search capabilities to your users. The optional cluster setup ensures your search infrastructure is scalable and highly available, catering to growing demands and providing a seamless user experience.