ElasticSearch7.10的單機https訪問

山沉發表於2020-12-18

ElasticSearch7.10的單機https訪問

1.設定Elastic密碼

這個首先是對ElasticSearch設定使用者密碼。在bin目錄下啟動ES例項

[~#bin]su choleen
[~#bin]./elasticsearch

啟動成功,在開啟一個頁面,進入bin目錄,手動設定密碼。不然auto 自動生成密碼

[~#bin]./ elasticsearch-setup-passwords interactive

接下來提示:
Please confirm thta you would like to continue [y/N] y

然後後要為4個使用者分別設定密碼:elastic, kibana, logstash_system,beats_system

我都是設定 admin123

2. 生成證照

  1. 生成p12金鑰
    進入bin目錄,前提是ES例項啟動著
[~#bin]./elasticsearch-certutil ca
[~#bin]./elasticsearch-certutil cert --ca /home/software/elasticsearch-7.10.0/elastic-stack-ca.p12
[~#bin]vim ../config/elasticsearch.yml
  1. 生成證照
    根據金鑰去生成證照,會產生新的檔案:elastic-certifiscates.p12,系統會提示輸入密碼。
  • 當輸入證照和金鑰的密碼
    在建立正書時輸入了密碼,完成後,啟動報錯。在bin目錄下可以這樣,輸入amdin123:
[~#bin]./elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password0
[~#bin]./elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
[~#bin]./elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password
[~#bin]elasticsearch-keystore add xpack.security.http.ssl.truststore.secure_password
  • enter鍵按下,沒有輸入密碼,留空
    這樣生成了沒有主機名資訊的證照,意味著可以用於叢集中的每一個點,注意,關閉主機名驗證。
  1. 放certificates證照到config目錄下
[~#config]mkdir certs
[~#config]mv elastic-certificates.p12 config/certs/

3. 配置elasticsearch.yml

http.cors.allow-origin: "*"
http.cors.enabled: true
http.cors.allow-headers: Authorization

#https to access way
xpack.security.enabled: true
xpack.security.http.ssl.keystore.path: certs/elastic-certificate.p12
xpack.security.http.ssl.truststore.path:  certs/elastic-certificate.p12

xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: certs/elastic-certificate.p12
xpack.security.transport.ssl.truststore.path:  certs/elastic-certificate.p12

4. 重啟ES例項

當看到這個,說明證照啟動成功,有效。

5. Kibana的證照

在elasticsearch7.10的根目錄,有elastic-stack-ca.p12 金鑰。我們可以生成es所屬產品可用的證照

[~#elasticsearch-7.10.0] openssl pkcs12 -in elastic-stack-ca.p12 -out newfile.crt.pem -clcerts -nokeys

這裡都有描述,生成的newfiel.crt.pem檔案,可以給kibnana、filebeat使用,複製到對應的config目錄。

根據圖片,還需要再kibana的配置檔案中,寫入使用者和密碼

elasticsearch.hosts: ["https://127.0.0.0:9200"] # 注意https
elasticsearch.ssl.verificationMode: none
elasticsearch.ssl.certificateAuthorities: ["/usr/local/kibana-7.10.0-linux-x86_64/config/newfile.crt.pem"]

elasticsearch.username: "kibana"
elasticsearch.password: "admin123"

這樣先啟動es,再啟動kibana,就可以登入,輸入使用者名稱,密碼,就可以了。

6. URL登入

輸入elastic,admin123

7. linux上訪問node1

參看部落格:https://www.cnblogs.com/ssqq5200936/p/10815200.html

  1. 查詢索引
curl -k -u elastic:admin123 'https://192.168.246.130:9200/_cat/indices?v'
  1. 查詢對映
 curl -k -u elastic:admin123 -XGET -H "Content-Type:application/json" 'https://192.168.246.130:9200/test?pretty'

pretty,格式化

對映查詢

curl -k -u elastic:admin123 -XGET -H "Content-Type:application/json" 'https://192.168.246.130:9200/test/_mapping?pretty'

相關文章