Install ElasticSearch (ES) and related configuration under Linux

Preface

Elasticsearch is a Lucene-based search server. It provides a full-text search engine with distributed multi-user capabilities, based on a RESTful web interface. Elasticsearch is developed in the Java language and released as an open source under the terms of the Apache license. It is a popular enterprise search engine. Elasticsearch is used in cloud computing to achieve real-time search, stable, reliable, fast, and easy to install and use. The official client is available in Java, .NET (C#), PHP, Python, Apache Groovy, Ruby and many other languages.

Official website: https://www.elastic.co/cn/elasticsearch/

 

premise

Install JDK  https://blog.csdn.net/javanbme/article/details/111573731

 

installation steps

1. Enter the installation directory

cd /usr/local

2. Download the source code

  Download from official website: https://www.elastic.co/guide/en/elasticsearch/reference/7.6/targz.html

  Method 1: Link: https://pan.baidu.com/s/1fSwBOKStOW9R38xEHnMXCA  Password: c9no After downloading, put it in the above directory

  Way two:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-linux-x86_64.tar.gz

3. Unzip the installation package

tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz

4. Rename

mv elasticsearch-7.6.2/ elasticsearch

5. Modify the configuration file

 cd elasticsearch/config/

  Go to the config folder under the es installation directory and modify the elasticsearch.yml file

 vi elasticsearch.yml 

  In English input state, press i to enter insert mode, modify the following configuration 

cluster.name: test-elastic
node.name: node-1
path.data: /usr/local/elasticsearch/data
path.logs: /usr/local/elasticsearch/logs
bootstrap.system_call_filter: false
network.host: 0.0.0.0
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
cluster.initial_master_nodes: ["node-1"]    

  Press esc to enter  : wq  save and exit

6. Complete the table of contents

mkdir -p /usr/local/elasticsearch/data

7. Because of security issues, elasticsearch does not allow the root user to run directly, so create a new user

useradd  elk
passwd   elk

  Enter the password twice (custom) elk

8. Assign permissions to users  

chown -R elk:elk /usr/local/elasticsearch

9. Open firewall port (9200)

10. Switch user to start ES (verify whether the initial installation is successful)

cd 
su elk
cd  /usr/local/elasticsearch
bin/elasticsearch  &

11. Set up x-park (password access)

  Execute in the server

curl -H "Content-Type:application/json" -XPOST  http://127.0.0.1:9200/_xpack/license/start_trial?acknowledge=true

12. Add configuration

  Go to the config folder under the es installation directory and modify the elasticsearch.yml file

cd /usr/local/elasticsearch/config/
vi elasticsearch.yml 

  Press i in English input state to enter insert mode, add the following configuration 

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

  Press esc to enter  : wq  save and exit

13. Restart es

  Find es process

 ps -ef|grep "elastic"

  Kill the process (find the PID, my process in the picture above is 27543)

kill -9 27543

  After killing the process, start the command to execute the 10th step above 

14. Set a series of passwords

cd /usr/local/elasticsearch/
bin/elasticsearch-setup-passwords interactive

Set the password to 2021admin, just copy and paste it  

15. If you want to change the password, execute the following command (can be ignored)

  Execute in the server

curl -H "Content-Type:application/json" -XPOST -u elastic 'http://127.0.0.1:9200/_xpack/security/user/elastic/_password' -d '{ "password" : "123456" }'

16. Generate CA Certificate

  Enter the es directory and run the following command. When you encounter [Y/N], enter y and press Enter   

  Enter the password directly when you encounter it!

  If prompted for insufficient permissions chmod 660 /usr/local/elasticsearch/config/certs/

bin/elasticsearch-certutil ca --ca-dn "CN=WolfBolin Elatic CA" --out /usr/local/elasticsearch/config/certs/wolfbolin-elastic-ca.p12
bin/elasticsearch-certutil cert -ca /usr/local/elasticsearch/config/certs/wolfbolin-elastic-ca.p12 --out /usr/local/elasticsearch/config/certs/wolfbolin-elastic-certificates.p12

17. Add CA configuration

cd /usr/local/elasticsearch/config/
vi elasticsearch.yml 

  Press i in English input state to enter insert mode, add the following configuration 

xpack.license.self_generated.type: basic    
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: certs/wolfbolin-elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: certs/wolfbolin-elastic-certificates.p12

  Press esc to enter  : wq  save and exit

18. Restart

Repeat step 13 above

19. Visit

url:9200    

Enter username and password elastic/2021admin

 

expand

Kibana: https://blog.csdn.net/javanbme/article/details/114888089 

 

Question Collection

1.  INFO: os::commit_memory(0x00000000ca660000, 899284992, 0) failed; error='Not enough space' (errno=12)   

  Insufficient memory, modify the configuration file ES directory /config/jvm.options to 512m 

cd /usr/local/elasticsearch/config/
vi jvm.options 

  Modify the following

-Xms512m
-Xmx512m

2. Likely root cause: java.nio.file.AccessDeniedException: /usr/local/elasticsearch/config/elasticsearch.keystore

  Switch root user to add permissions

chown -R elk:elk /usr/local/elasticsearch

3. max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

  Modify virtual memory

 vim /etc/sysctl.conf

   Add the following

vm.max_map_count = 262144

  Execute after saving

sysctl -p

  4. java.lang.RuntimeException: can not run elasticsearch as root

   Switch to es user to start  

su elk

 

Guess you like

Origin blog.csdn.net/javanbme/article/details/114002376