Skip to content

Instantly share code, notes, and snippets.

@devops-school
Created September 21, 2022 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save devops-school/75496d673034c538cd5e4ef0bd7cb220 to your computer and use it in GitHub Desktop.
Save devops-school/75496d673034c538cd5e4ef0bd7cb220 to your computer and use it in GitHub Desktop.
Elasticsearch 8.X in Centos 7
Elasticsearch 8.X in Centos 7
-------------------------------
192.168.1.8
https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html
$ yum install wget unzip -y
$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.4.2-linux-x86_64.tar.gz
$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.4.2-linux-x86_64.tar.gz.sha512
$ shasum -a 512 -c elasticsearch-8.4.2-linux-x86_64.tar.gz.sha512
$ tar -xzf elasticsearch-8.4.2-linux-x86_64.tar.gz
$ cd elasticsearch-8.4.2/
----------------------------------------
elasticsearch can not with user called "root"
$ useradd elastic
$ passwd elastic
$ su elastic
Elasticsearch security features have been automatically configured!
Authentication is enabled and cluster connections are encrypted.
Password for the elastic user
===========================================
Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
YrfJHfoQtniJqzyD4pM3
HTTP CA certificate SHA-256 fingerprint:
===========================================
dc31d8f9d6d6f6223743e13a04fc0c107c1c253a37ef25d2a99b2733235b1e5e
Configure Kibana to use this cluster:
===========================================
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjQuMiIsImFkciI6WyIxOTIuMTY4LjEuODo5MjAwIl0sImZnciI6ImRjMzFkOGY5ZDZkNmY2MjIzNzQzZTEzYTA0ZmMwYzEwN2MxYzI1M2EzN2VmMjVkMmE5OWIyNzMzMjM1YjFlNWUiLCJrZXkiOiJxMTlyWG9NQnNQMjdDeDNIUEFIZDp5bVJ4S1ZPWFM0ZWt4SS1RNzFicjJRIn0=
Configure other nodes to join this cluster:
===========================================
• On this node:
⁃ Create an enrollment token with `bin/elasticsearch-create-enrollment-token -s node`.
⁃ Uncomment the transport.host setting at the end of config/elasticsearch.yml.
⁃ Restart Elasticsearch.
• On other nodes:
⁃ Start Elasticsearch with `bin/elasticsearch --enrollment-token <token>`, using the enrollment token that you generated.
=======================================
curl http://localhost:9200
curl --cacert /home/elastic/elasticsearch-8.4.2/config/certs/http_ca.crt -u elastic https://localhost:9200
Enter host password for user 'elastic':
{
"name" : "localhost.localdomain",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "DwtXLUGKSB2Oy5piLMeArw",
"version" : {
"number" : "8.4.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "89f8c6d8429db93b816403ee75e5c270b43a940a",
"build_date" : "2022-09-14T16:26:04.382547801Z",
"build_snapshot" : false,
"lucene_version" : "9.3.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
curl --cacert /home/elastic/elasticsearch-8.4.2/config/certs/http_ca.crt -u elastic:YrfJHfoQtniJqzyD4pM3 https://localhost:9200
curl -XPUT --cacert /home/elastic/elasticsearch-8.4.2/config/certs/http_ca.crt -u elastic:YrfJHfoQtniJqzyD4pM3 'https://localhost:9200/products?&pretty'
curl -XGET --cacert /home/elastic/elasticsearch-8.4.2/config/certs/http_ca.crt -u elastic:YrfJHfoQtniJqzyD4pM3 'https://localhost:9200/_cat/indices?v&pretty'
------------ NOT WORKING FOR 8.X -------------------------
curl -XPUT --cacert /home/elastic/elasticsearch-8.4.2/config/certs/http_ca.crt -u elastic:YrfJHfoQtniJqzyD4pM3 'https://localhost:9200/products/mobiles/1?pretty' -H 'Content-Type: application/json' -d'
{
"name": "iPhone 7",
"camera": "12MP",
"storage": "256GB",
"display": "4.7inch",
"battery": "1,960mAh",
"reviews": ["Incredibly happy after having used it for one week", "Best iPhone so far", "Very expensive, stick to Android"]
}
'
------------ WORKING FOR 8.X -------------------------
curl -XPUT --cacert /home/elastic/elasticsearch-8.4.2/config/certs/http_ca.crt -u elastic:YrfJHfoQtniJqzyD4pM3 'https://localhost:9200/products/_doc/1' -H 'Content-Type: application/json' -d'
{
"name": "iPhone 7",
"camera": "12MP",
"storage": "256GB",
"display": "4.7inch",
"battery": "1,960mAh",
"reviews": ["Incredibly happy after having used it for one week", "Best iPhone so far", "Very expensive, stick to Android"]
}
'
curl -XPUT --cacert /home/elastic/elasticsearch-8.4.2/config/certs/http_ca.crt -u elastic:YrfJHfoQtniJqzyD4pM3 'https://localhost:9200/products/_doc/3' -H 'Content-Type: application/json' -d'
{
"name": "iPhone 7",
"camera": "12MP",
"storage": "256GB",
"display": "4.7inch",
"battery": "1,960mAh",
"reviews": ["Incredibly happy after having used it for one week", "Best iPhone so far", "Very expensive, stick to Android"]
}
'
curl -XPUT --cacert /home/elastic/elasticsearch-8.4.2/config/certs/http_ca.crt -u elastic:YrfJHfoQtniJqzyD4pM3 'https://localhost:9200/products/_doc/4' -H 'Content-Type: application/json' -d'
{
"name": "iPhone 7",
"camera": "12MP",
"storage": "256GB",
"display": "4.7inch",
"battery": "1,960mAh",
"reviews": ["Incredibly happy after having used it for one week", "Best iPhone so far", "Very expensive, stick to Android"]
}
'
curl -XPOST --cacert /home/elastic/elasticsearch-8.4.2/config/certs/http_ca.crt -u elastic:YrfJHfoQtniJqzyD4pM3 'https://localhost:9200/products/_doc' -H 'Content-Type: application/json' -d'
{
"name": "iPhone 7",
"camera": "12MP",
"storage": "256GB",
"display": "4.7inch",
"battery": "1,960mAh",
"reviews": ["Incredibly happy after having used it for one week", "Best iPhone so far", "Very expensive, stick to Android"]
}
'
curl -XGET --cacert /home/elastic/elasticsearch-8.4.2/config/certs/http_ca.crt -u elastic:YrfJHfoQtniJqzyD4pM3 'https://localhost:9200/products'
curl -XGET --cacert /home/elastic/elasticsearch-8.4.2/config/certs/http_ca.crt -u elastic:YrfJHfoQtniJqzyD4pM3 'https://localhost:9200/products/_search?pretty=true&q=*:*'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment