Popular blog tags

How To Install and uninstall reinstall Elasticsearch 8.x on Ubuntu 22.04(vultr)

Published

Welcome to Ubuntu 22.04.5 LTS (GNU/Linux 5.15.0-124-generic x86_64)

Table of Contents

Install

 

wget -q https://artifacts.elastic.co/GPG-KEY-elasticsearch -O- | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list

sudo apt update

sudo apt install elasticsearch

output

Preparing to unpack .../elasticsearch_8.15.3_amd64.deb ...
Creating elasticsearch group... OK
Creating elasticsearch user... OK
Unpacking elasticsearch (8.15.3) ...
Setting up elasticsearch (8.15.3) ...

                                                                                                                    

--------------------------- Security autoconfiguration information ------------------------------

Authentication and authorization are enabled.
TLS for the transport and HTTP layers is enabled and configured.

The generated password for the elastic built-in superuser is : Ik4xlwup8ajTP_dPFQXx
账号初始默认为elastic,密码在启动日志(或者启动控制台)中直接搜索password,就能找到。Ik4xlwup8ajTP_dPFQXx

If this node should join an existing cluster, you can reconfigure this with
'/usr/share/elasticsearch/bin/elasticsearch-reconfigure-node --enrollment-token <token-here>'
after creating an enrollment token on your existing cluster.

You can complete the following actions at any time:

Reset the password of the elastic built-in superuser with 
'/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic'.
可以通过在bin中使用elasticsearch-reset-password -u elastic命令进行密码的修改。

Generate an enrollment token for Kibana instances with 
 '/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana'.

Generate an enrollment token for Elasticsearch nodes with 
'/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node'.

-------------------------------------------------------------------------------------------------

Run

### NOT starting on installation, please execute the following statements to configure elasticsearch

service to start automatically using systemd
 sudo systemctl daemon-reload
 sudo systemctl enable elasticsearch.service


### You can start elasticsearch service by executing
 sudo systemctl start elasticsearch.service
Scanning processes...                                                                                                                                       
Scanning linux images...                                                                                                                                    

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.


root@vultr:~# sudo systemctl start elasticsearch.service
root@vultr:~# systemctl status elasticsearch

● elasticsearch.service - Elasticsearch
     Loaded: loaded (/lib/systemd/system/elasticsearch.service; disabled; vendor preset: enabled)
     Active: active (running) since Thu 2024-10-24 14:02:40 UTC; 27s ago
       Docs: https://www.elastic.co
   Main PID: 59236 (java)
      Tasks: 81 (limit: 2212)
     Memory: 1.3G
        CPU: 48.390s
     CGroup: /system.slice/elasticsearch.service
             ├─59236 /usr/share/elasticsearch/jdk/bin/java -Xms4m -Xmx64m -XX:+UseSerialGC -Dcli.name=server -Dcli.script=/usr/share/elasticsearch/bin/elas>
             ├─59295 /usr/share/elasticsearch/jdk/bin/java -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -Djava.security.manag>
             └─59317 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller

Oct 24 14:01:56 vultr systemd[1]: Starting Elasticsearch...
Oct 24 14:02:03 vultr systemd-entrypoint[59236]: Oct 24, 2024 2:02:03 PM sun.util.locale.provider.LocaleProviderAdapter <clinit>
Oct 24 14:02:03 vultr systemd-entrypoint[59236]: WARNING: COMPAT locale provider will be removed in a future release
Oct 24 14:02:40 vultr systemd[1]: Started Elasticsearch.

Test

the Elasticsearch 8.x server can only be accessed via an internal network, so we don't use HTTPS or domain resolution.

Run my application in localhost, should connect to elastic server correctly

Are you attempting to connect via a secure connection?No

step 1.Elasticsearch 8 启动成功后,无法直接通过 http://localhost:9200 访问

wget http://localhost:9200
--2024-10-27 07:46:43--  http://localhost:9200/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:9200... connected.
HTTP request sent, awaiting response... No data received.
Retrying.

So that indicates that the client and server can successfully communicate at least.

 

 Can you check whether both your client and server agree on that?No

Exception: Invalid Elasticsearch response built from a unsuccessful () low level call on PUT: /wwwiaspnetcoreindex
Exception: Failed to ping the specified node. Call: Status code unknown from: HEAD /

# Audit trail of this API call:
- [1] AllNodesDead: Took: 00:00:00.0000007
- [2] Resurrection: Node: http://localhost:9200/ Took: 00:00:00.0000001
- [3] PingFailure: Node: http://localhost:9200/ Exception: PipelineException Took: 00:00:00.0059298
# OriginalException: Elastic.Transport.TransportException: Failed to ping the specified node. Call: Status code unknown from: HEAD /
---> Elastic.Transport.PipelineException: Failed to ping the specified node.

原因:ES8在初次启动时会自动进行安全配置,默认开启SSL认证

解决办法:

方法1:在config/elasticsearch.yml配置文件中找到xpack.security.http.ssl.enable,将其设置为false,然后重启服务端,再通过http://localhost:9200访问

edit /etc/elasticsearch/elasticsearch.yml

# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
  enabled: false
  keystore.path: certs/http.p12



                        
原文链接:https://blog.csdn.net/cw2467407676/article/details/140322124

step 2.401 Unauthorized

 

wget http://localhost:9200
--2024-10-27 13:46:59--  http://localhost:9200/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:9200... connected.
HTTP request sent, awaiting response... 401 Unauthorized

Username/Password Authentication Failed.

step 3.

edit /etc/elasticsearch/elasticsearch.yml

# Enable security features
xpack.security.enabled: false  # change from true to false 202410 by iaspnetcore
wget http://localhost:9200
--2024-10-27 13:46:59--  http://localhost:9200/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:9200... connected.
HTTP request sent, awaiting response... 401 Unauthorized

Username/Password Authentication Failed.
root@vultr:~# sudo systemctl restart elasticsearch.service
root@vultr:~# wget http://localhost:9200
--2024-10-27 14:16:53--  http://localhost:9200/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:9200... connected.
HTTP request sent, awaiting response... 200 OK
Length: 530 [application/json]
Saving to: ‘index.html.1’

run ok

useful links

How to Install Elasticsearch 8 on Ubuntu 22.04