How To Install Elasticsearch on Fedora 40
In this tutorial, we will show you how to install Elasticsearch on Fedora 40. Elasticsearch has become an indispensable tool in the world of data analysis and search capabilities. As a powerful, distributed search and analytics engine, it offers unparalleled performance for applications requiring fast and accurate data retrieval.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of the Elasticsearch on Fedora 40.
Prerequisites
Before we dive into the installation process, ensure that you have the following prerequisites in place:
- A server running one of the following operating systems: Fedora 40.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- Basic familiarity with the Linux command line.
- You will need access to the terminal to execute commands. Fedora provides the Terminal application for this purpose. It can be found in your Applications menu.
- At least 2 CPU cores.
- Sufficient disk space (at least 10GB free).
- A stable internet connection to download the necessary packages.
- A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.
Install Elasticsearch on Fedora 40
Step 1. Update the System.
To begin, it’s crucial to ensure your Fedora 40 system is up-to-date. This step helps prevent potential conflicts and ensures you have the latest security patches. Open your terminal and run:
sudo dnf clean all sudo dnf update
This command will fetch the latest package information and install any available updates for your Fedora 40 system.
Step 2. Installing Java.
Elasticsearch requires Java to run. While Elasticsearch now includes a bundled Java Runtime Environment (JRE), it’s still a good practice to have Java installed on your system. Let’s install OpenJDK:
sudo dnf install java-11-openjdk-devel
After installation, verify the Java version:
java -version
You should see an output indicating the installed Java version.
Step 3. Installing Elasticsearch.
To ensure we install the official and most up-to-date version of Elasticsearch, we’ll add the Elasticsearch repository to our system.
First, import the Elasticsearch GPG key:
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
Next, create a new repository file for Elasticsearch:
sudo tee /etc/yum.repos.d/elasticsearch.repo << EOF [elasticsearch] name=Elasticsearch repository for 8.x packages baseurl=https://artifacts.elastic.co/packages/8.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md EOF
This command creates a new file named elasticsearch.repo
in the /etc/yum.repos.d/
directory, containing the necessary repository information.
With the repository set up, we can now install Elasticsearch:
sudo dnf install elasticsearch
This command will download and install Elasticsearch along with its dependencies.
Step 4. Configuring Elasticsearch.
The main configuration file for Elasticsearch is located at /etc/elasticsearch/elasticsearch.yml
. Open this file with your preferred text editor:
sudo nano /etc/elasticsearch/elasticsearch.yml
While Elasticsearch works well with its default settings, you might want to adjust some parameters:
- Cluster Name: If you’re setting up a multi-node cluster, uncomment and modify the cluster.name setting:
cluster.name: my-fedora-cluster
- Node Name: Give your node a descriptive name:
text node.name: fedora40-node-1
- Network Host: By default, Elasticsearch binds to localhost. If you want it to be accessible from other machines, change this to:
network.host: 0.0.0.0
- Port Settings: The default port is 9200. You can change it if needed:
http.port: 9200
Elasticsearch is memory-intensive. You can configure heap size in the /etc/elasticsearch/jvm.options
file. As a general rule, set the heap size to 50% of your available RAM, but no more than 32GB. For example, on a system with 16GB RAM:
-Xms8g -Xmx8g
If you want to change the default paths for data and logs, modify these settings:
path.data: /var/lib/elasticsearch path.logs: /var/log/elasticsearch
Now that we’ve configured Elasticsearch, let’s start the service:
sudo systemctl start elasticsearch
To ensure Elasticsearch starts automatically on system boot:
sudo systemctl enable elasticsearch
Check the status of the Elasticsearch service:
sudo systemctl status elasticsearch
You should see an output indicating that the service is active and running.
Step 5. Securing Elasticsearch.
Security is paramount when deploying Elasticsearch, especially in production environments.
- Changing Default Passwords
Elasticsearch 8.x comes with security features enabled by default. When you first start Elasticsearch, it generates a password for the elastic superuser. You can find this password in the logs:
sudo journalctl -u elasticsearch
Look for a line that says “The generated password for the elastic built-in superuser is: [password]”
It’s crucial to change this password. Use the elasticsearch-reset-password
tool:
sudo /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
- Enabling X-Pack Security
X-Pack is included in the default distribution of Elasticsearch and provides additional security features. Ensure it’s enabled in your elasticsearch.yml
:
xpack.security.enabled: true
- Configuring Firewall Rules
If you’ve set network.host to allow external connections, you need to configure your firewall to allow traffic on the Elasticsearch port (default 9200):
sudo firewall-cmd --add-port=9200/tcp --permanent sudo firewall-cmd --reload
Step 6. Testing the Elasticsearch Installation.
To verify that Elasticsearch is running correctly, send a GET request to the localhost on port 9200:
curl -X GET "localhost:9200"
If Elasticsearch is running properly, you should receive a JSON response with information about your cluster.
Congratulations! You have successfully installed Elasticsearch. Thanks for using this tutorial for installing Elasticsearch on Fedora 40 system. For additional help or useful information, we recommend you check the official Elasticsearch website.