I was facing the same problem on Ubuntu 22.04, but I purged the downloaded elasticsearch directory and then redownloaded so,
First Pipe the output to the gpg --dearmor command so that apt is able to utilise the key to verify downloaded packages
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elastic.gpg
Then, add the Elastic source list to the sources.list.d directory, where apt will search for new sources
echo "deb [signed-by=/usr/share/keyrings/elastic.gpg] https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
Afterwards update package lists and install elasticsearch again
sudo apt update
sudo apt install elasticsearch
When you finish the download, you need to modify main configuration file elasticsearch.yml where most of its configuration options are stored
sudo nano /etc/elasticsearch/elasticsearch.yml
And then navigate to the Netwok section something like
. . .
# ---------------------------------- Network -----------------------------------
#
network.host: Foo.foo.foo
. . .
Elasticsearch listens for traffic from everywhere on port 9200. You will want to restrict outside access to your Elasticsearch instance to prevent outsiders from reading your data or shutting down your Elasticsearch cluster through its [REST API]
So replace the Foo.foo.foo with
. . .
# ---------------------------------- Network -----------------------------------
#
network.host: localhost
. . .
I used localhost so that Elasticsearch listens on all interfaces and bound IPs.
Start elasticsearch and enable it each time the server starts
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch
With all that said you will have to configure the firewall to allow access to the default Elasticsearch HTTP API port (TCP 9200) for the trusted remote host, generally the server you are using in a single-server setup, such as198.51.100.0. To allow access, type the following command:
sudo ufw allow from 198.51.100.0 to any port 9200
sudo ufw enable
Use cURL to test your installation
curl -X GET 'http://localhost:9200'
Response
{
"name" : "elastic-22",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "DEKKt_95QL6HLaqS9OkPdQ",
"version" : {
"number" : "7.17.1",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "e5acb99f822233d62d6444ce45a4543dc1c8059a",
"build_date" : "2022-02-23T22:20:54.153567231Z",
"build_snapshot" : false,
"lucene_version" : "8.11.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
This is what worked for me.
curl -X GET "http://localhost:9200"
– Dingess