Elasticsearch Xpack認證


說明

  ES(在本文中,ES即Elasticsearch簡稱)的xpack一直都是要收費的,然而在6.8版本開始,ES開放了部分xpack認證功能,但一些高級功能仍舊收費(如單點登錄以及對字段級和文檔級安全性的Active Directory / LDAP身份驗證仍然是付費功能)。

詳細可參看官方說明(這個版本主要也是對認證進行了調整)。

概述

  本文主要針對ES 6.8.0 安全認證部署

一、單機ES安全認證部署

(1)下載ES 6.8.0 linux 安裝包

(2)上傳至服務器並解壓

# 解壓
sudo tar -zxvf elasticsearch-6.8.0.tar.gz
# 將 es 目錄授予 elasticsearch 用戶,因為 es 不允許使用 root 用戶啟動
sudo chown -R elasticsearch elasticsearch-6.8

(3)修改 ES config/elasticsearch.yml 配置,添加如下配置

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

(4)啟動ES

# 切換用戶
su elasticsearch
# 啟動ES
./bin/elasticsrearch

(5)驗證

  頁面訪問 ${IP}:9200,會彈出輸入用戶名密碼的窗口。ES有一些默認的用戶名(elastic、kibana、logstash等),但是需要自己設置密碼,否則登錄不進去。

(6)給默認用戶設置密碼

./bin/elasticsearch-setup-passwords interactive

設置完成之后選擇其中一個用戶再去登錄即可訪問到ES節點信息

二、ES集群安全認證部署

 (1)基於單機拷貝兩份作為另外兩個ES節點。一個master,兩個worker

cp elasticsearch-6.8.0 elasticsearch-6.8.0-worker0
cp elasticsearch-6.8.0 elasticsearch-6.8.0-worker1

(2)三個節點ES配置文件

# 節點角色
node.name: master
node.master: true
node.data: false
# 數據以及日志目錄
path.data: /opt/elasticsearch-6.8.0/data
path.logs: /opt/elasticsearch-6.8.0/logs
# http以及tcp端口,http用於API訪問,tcp用於集群內部訪問
http.port: 9200
transport.tcp.port: 9300
# 集群節點
discovery.zen.ping.unicast.hosts: ["xxx:9300","xxx:9301","xxx:9302"]
# xpack 訪問認證
 xpack.security.audit.enabled: true
 xpack.security.enabled: true
 xpack.security.transport.ssl.enabled: true
# xpack 集群認證
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: certificates.p12
xpack.security.transport.ssl.truststore.path: certificates.p12
# 節點角色
node.name: worker0
node.master: false
node.data: true
# 數據以及日志目錄
path.data: /opt/elasticsearch-6.8.0-worker0/data
path.logs: /opt/elasticsearch-6.8.0-worker0/logs
# http以及tcp端口,http用於API訪問,tcp用於集群內部訪問
http.port: 9201
transport.tcp.port: 9301
# 集群節點
discovery.zen.ping.unicast.hosts: ["xxx:9300","xxx:9301","xxx:9302"]
# xpack 訪問認證
 xpack.security.audit.enabled: true
 xpack.security.enabled: true
 xpack.security.transport.ssl.enabled: true
# xpack 集群認證
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: certificates.p12
xpack.security.transport.ssl.truststore.path: certificates.p12
# 節點角色
node.name: worker1
node.master: false
node.data: true
# 數據以及日志目錄
path.data: /opt/elasticsearch-6.8.0-worker1/data
path.logs: /opt/elasticsearch-6.8.0-worker1/logs
# http以及tcp端口,http用於API訪問,tcp用於集群內部訪問
http.port: 9202
transport.tcp.port: 9302
# 集群節點
discovery.zen.ping.unicast.hosts: ["xxx:9300","xxx:9301","xxx:9302"]
# xpack 訪問認證
 xpack.security.audit.enabled: true
 xpack.security.enabled: true
 xpack.security.transport.ssl.enabled: true
# xpack 集群認證
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: certificates.p12
xpack.security.transport.ssl.truststore.path: certificates.p12

(3)配置秘鑰文件

  - 生成ca文件(在任何一個節點目錄下執行都行)

./bin/elasticsearch-certutil ca

  - 生成節點秘鑰文件

./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12

  - 復制秘鑰文件到各節點的指定目錄下(根據配置復制到具體目錄下,這里是復制到config目錄下)

  - 在各個節點執行以下命令設置密碼

./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
./bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password

(4)啟動各個節點並登陸驗證

三、kibana  ES

(1)下載kibana

(2)kibana 配置

server.name: "xxxx"
# 連接es master節點 elasticsearch.url: "http://${ip}:9200"
# 認證賬號密碼 elasticsearch.username: "kibana" elasticsearch.password: "xxxx" # kibana默認訪問端口
server.port: 5601 server.host: "0.0.0.0"
# 監控(此配置開啟的話,會造成cpu監控為N/A,改成false即可) xpack.monitoring.ui.container.elasticsearch.enabled: true
# 開啟認證 xpack.security.enabled: true

(3)啟動kibana

./bin/kibana

(4)訪問

 ${ip}:5601

四、logstash ES

(1)下載logstash安裝包

(2)logstash 的 logstash.yml 配置

# xpack 認證
xpack.monitoring.enabled: true xpack.monitoring.elasticsearch.username: "logstash" xpack.monitoring.elasticsearch.password: "xxx" xpack.monitoring.elasticsearch.url: ["${ip}:9200"]

(3)logstash 的 pipeline.yml 管道配置

- pipeline.id: xxx-pipeline
  path.config: "/usr/share/logstash/pipelines/xxx.conf"
  pipeline.workers: 10
  pipeline.batch.size: 500

(4)logstash 管道連接 ES

elasticsearch {
  action => "index"
  hosts => ["${ip}:9200"]
  index => "xxx"
 # 認證 user => "logstash" password => "xxx" document_type => "xxx" document_id => "xxx" template => "/usr/share/logstash/es-template/xxx.json" template_name => "xxx" template_overwrite => true }

(5)運行 logstash

# 無需指定配置文件,默認走pipelines.yml的配置
./bin/logstash

五、錯誤記錄

(1)錯誤:with the same id but is a different node instance
    原因:不同的ES節點使用了同一個data目錄
(2)Caused by: java.security.UnrecoverableKeyException: failed to decrypt safe contents entry: javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used during decryp
    原因:證書有問題,重新生成即可

六、參考文章

(1)es認證:https://blog.csdn.net/qq_37461349/article/details/103047795

(2)es認證:https://blog.csdn.net/shen12138/article/details/107016991/

(3)logstash連接認證ES:https://www.cnblogs.com/wueryuan/p/13523833.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM