Prerequisites
Install JRE / JDK
First, update the packages again
1 2 | sudo apt-get update |
Next, we will go to Java installation – Runtime Environment (JRE)
1 2 | sudo apt-get install default-jre |
You can install JDK with the following command:
1 2 | sudo apt-get install default-jdk |
Environment variable setting JAVA_HOME
Many Java server programs use the JAVA_HOME environment variable to locate Java settings. To install this environment variable, we will first need to find out where Java is installed.
You can check by executing the following command:
1 2 | sudo update-alternatives --config java |
And the result returns: (note the path in bold)
There is only one alternative in link group java (providing / usr / bin / java): / usr / lib / jvm / java-8-openjdk-amd64 / jre / bin / java
Once you have a java path, copy this path to the following file:
1 2 | sudo vi /etc/environment |
And add the following /etc/environment
to the end of the file:
1 2 | JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64" |
Save and reload:
1 2 | source /etc/environment |
You can now check the newly added environment variable with the following command:
1 2 | echo $JAVA_HOME |
Download and install Elasticsearch
Log in as root
1 2 3 | $ sudo -i $ apt-get update |
This step will perform the download Elasticsearch. Here I installed with version 6.5.4
1 2 3 4 5 | $ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.4.deb $ dpkg -i elasticsearch-6.5.4.deb $ systemctl enable elasticsearch.service $ systemctl restart elasticsearch |
To configure Elasticseach parameters you can find and edit the file /etc/elasticsearch/elasticsearch.yml
1 2 | vi /etc/elasticsearch/elasticsearch.yml |
After restarting you can use curl to test whether elasticsearch works or not
1 2 | curl -X GET 'http://localhost:9200' |
Increase RAM for Elasticsearch
After you have a large amount of data for your index. And running tests with a large number of requests (search or index) every day you will probably face the following errors that cause ES to stop running, even causing other services in the same server to be delayed and unable to run.
Expression:
When viewing the elasticsearch log. You will get one (or all) of the following error messages:
– rejected execution (queue capacity 1000)
– failed to reduce search
– java.lang.OutOfMemoryError: Java heap space
Reason:
ES needs more RAM than you are using for it. You need to increase RAM for ES (increase ES_HEAP_SIZE)
First, navigate to the file /etc/elasticsearch/jvm.options
and edit:
1 2 | vi /etc/elasticsearch/jvm.options |
Find the following 2 properties. Default ES to ESHEAPSIZE = 1G
1 2 3 | -Xms1g -Xmx1g |
And replace into
1 2 3 | -Xms6g -Xmx6g |
Here I only take the example is 6GB, depending on the data as well as the number of requests to increase or decrease accordingly.
And finally restart the service
1 2 3 | service elasticsearch stop service elasticsearch start |