How To Install OpenSearch on AlmaLinux 9
OpenSearch is a fork of Elasticsearch and Kibana, offering a feature-rich alternative for data analysis and visualization. It’s designed to be scalable, secure, and highly customizable, making it an excellent choice for businesses of all sizes. AlmaLinux 9, a stable and enterprise-ready Linux distribution, provides an ideal environment for running OpenSearch.
This tutorial will guide you through each step of the installation process, from preparing your system to configuring OpenSearch for optimal performance. Whether you’re a system administrator, developer, or data analyst, this guide will help you set up a powerful search and analytics platform on your AlmaLinux 9 server.
Prerequisites
Before we begin the installation process, ensure that your system meets the following requirements:
- A server running AlmaLinux 9 with root or sudo privileges
- Minimum 4GB RAM (8GB or more recommended for production environments)
- At least 2 CPU cores
- Sufficient disk space (at least 20GB free space)
- Internet connection for downloading packages
Additionally, make sure your system is up-to-date and you have basic familiarity with Linux command-line operations.
Step 1: Update Your System
Before installing OpenSearch, it’s crucial to ensure your AlmaLinux 9 system is up-to-date. This step helps prevent potential conflicts and ensures you have the latest security patches.
Open a terminal and run the following command:
sudo dnf update -y
This command will update all installed packages to their latest versions. The ‘-y’ flag automatically answers “yes” to any prompts, streamlining the update process.
Step 2: Install Java
OpenSearch requires Java to run. AlmaLinux 9 comes with OpenJDK, which is compatible with OpenSearch. Install Java by running:
sudo dnf install java-17-openjdk -y
After installation, verify the Java version:
java -version
You should see output indicating that Java 17 is installed.
Step 3: Add the OpenSearch Repository
To install OpenSearch, we need to add its official repository to our system. This ensures we can easily install and update OpenSearch using AlmaLinux’s package manager.
Run the following command to add the OpenSearch repository:
sudo curl -SL https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/opensearch-2.x.repo -o /etc/yum.repos.d/opensearch-2.x.repo
This command downloads the repository file and saves it in the appropriate directory.
To verify that the repository has been added successfully, run:
sudo dnf repolist
You should see “OpenSearch 2.x” listed in the output.
Step 4: Install OpenSearch
Now that we have added the repository, we can proceed with installing OpenSearch. Run the following command:
sudo dnf install opensearch -y
During the installation, you may be prompted to accept the GPG key for the OpenSearch repository. Type ‘y’ and press Enter to continue.
The installation process may take a few minutes, depending on your system’s speed and internet connection. Once completed, OpenSearch will be installed on your AlmaLinux 9 system.
Step 5: Configure OpenSearch
After installation, we need to configure OpenSearch to suit our needs. The main configuration file is located at `/etc/opensearch/opensearch.yml
`. Let’s make some important changes to this file.
Open the configuration file with your preferred text editor:
sudo nano /etc/opensearch/opensearch.yml
Here are some key configurations you should consider:
Cluster Name
Set a unique name for your cluster:
cluster.name: my-opensearch-cluster
Node Name
Assign a descriptive name to your node:
node.name: alma-node1
Network Settings
By default, OpenSearch binds to localhost. If you want to access it from other machines, you’ll need to change this. However, be cautious about exposing OpenSearch directly to the internet.
For a single-node setup or development environment, you can use:
network.host: 0.0.0.0
For production, it’s better to bind to a specific IP:
network.host: 192.168.1.100 # Replace with your server's IP
Discovery Settings
For a single-node setup, add:
discovery.type: single-node
This tells OpenSearch not to look for other nodes in the cluster.
After making these changes, save the file and exit the text editor.
Step 6: Configure JVM Options
OpenSearch runs on the Java Virtual Machine (JVM). Proper JVM configuration is crucial for optimal performance. The JVM options are set in the file `/etc/opensearch/jvm.options
`.
Open this file:
sudo nano /etc/opensearch/jvm.options
The most important setting here is the heap size. As a general rule, set the minimum and maximum heap size to 50% of your available RAM, but no more than 32GB. For example, if your server has 16GB of RAM, you could set:
-Xms8g
-Xmx8g
Save the file after making your changes.
Step 7: Start and Enable OpenSearch Service
Now that we’ve configured OpenSearch, it’s time to start the service and enable it to start automatically on boot.
Run the following commands:
sudo systemctl start opensearch
sudo systemctl enable opensearch
To verify that OpenSearch is running, check its status:
sudo systemctl status opensearch
You should see output indicating that the service is active and running.
Step 8: Test OpenSearch Installation
To ensure OpenSearch is working correctly, we can send a simple HTTP request to its REST API. By default, OpenSearch listens on port 9200.
Run the following command:
curl -X GET "localhost:9200/"
If OpenSearch is running correctly, you should receive a JSON response with information about your OpenSearch instance, including its name, cluster name, and version.
Step 9: Secure OpenSearch
Security is crucial when dealing with data. OpenSearch comes with built-in security features that you should enable in production environments.
Edit the OpenSearch configuration file again:
sudo nano /etc/opensearch/opensearch.yml
Add the following lines to enable security plugins:
plugins.security.ssl.http.enabled: true
plugins.security.ssl.transport.enabled: true
plugins.security.ssl.http.pemcert_filepath: esnode.pem
plugins.security.ssl.http.pemkey_filepath: esnode-key.pem
plugins.security.ssl.http.pemtrustedcas_filepath: root-ca.pem
plugins.security.ssl.transport.pemcert_filepath: esnode.pem
plugins.security.ssl.transport.pemkey_filepath: esnode-key.pem
plugins.security.ssl.transport.pemtrustedcas_filepath: root-ca.pem
plugins.security.allow_default_init_securityindex: true
plugins.security.authcz.admin_dn:
- "CN=kirk,OU=client,O=client,L=test, C=de"
plugins.security.nodes_dn:
- "CN=node1.example.com,OU=SSL,O=Test,L=Test,C=DE"
plugins.security.audit.type: internal_opensearch
plugins.security.enable_snapshot_restore_privilege: true
plugins.security.check_snapshot_restore_write_privileges: true
plugins.security.restapi.roles_enabled: ["all_access", "security_rest_api_access"]
Remember to replace the certificate and key file paths with your actual paths.
Step 10: Install OpenSearch Dashboards (Optional)
OpenSearch Dashboards is a powerful visualization tool that works seamlessly with OpenSearch. To install it, run:
sudo dnf install opensearch-dashboards -y
After installation, configure OpenSearch Dashboards by editing its configuration file:
sudo nano /etc/opensearch-dashboards/opensearch_dashboards.yml
Set the OpenSearch URL and other relevant settings:
server.host: "0.0.0.0"
opensearch.hosts: ["http://localhost:9200"]
opensearch.ssl.verificationMode: none
Start and enable the OpenSearch Dashboards service:
sudo systemctl start opensearch-dashboards
sudo systemctl enable opensearch-dashboards
You can now access OpenSearch Dashboards by navigating to `http://your-IP-address:5601
` in your web browser.
Troubleshooting Common Issues
Even with careful installation, you might encounter some issues. Here are solutions to common problems:
OpenSearch Fails to Start
If OpenSearch doesn’t start, check the logs:
sudo journalctl -u opensearch
Common issues include insufficient memory or incorrect file permissions.
Connection Refused Errors
If you can’t connect to OpenSearch, ensure that the `network.host` setting in `opensearch.yml` is correct and that your firewall allows connections on port 9200.
Java Heap Space Errors
If you see “Java heap space” errors in the logs, you may need to adjust the JVM heap size in the `jvm.options` file.
Congratulations! You have successfully installed OpenSearch. Thanks for using this tutorial to install the latest version of OpenSearch on AlmaLinux 9. For additional help or useful information, we recommend you check the official OpenSearch website.