從之前的部署來看 ElasticSearch、Kibana以及ElasticHQ或者是Head,這些都沒有進行身份驗證,ELK官方提供了XPACK可以用來做驗證機制。
XPACK從6的版本開始就已經集成無需單獨部署,此外XPACK是有商業License的,提供了更豐富的制表,繪圖,安全、監控、報警等擴展。
修改ES Master的配置文件
vim /etc/elasticsearch/elasticsearch.yml
#追加下列行
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
xpack.security.enabled: true
xpack.security.audit.enabled: true #用於集群審計 追蹤
service elasticsearch restart #保險起見,將master和其他節點一起重啟ES服務
/usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive #設置密碼,為了方便我就全部設置成一樣的了
修改Kibana配置文件
vim /etc/kibana/kibana.yml
elasticsearch.username: "elastic"
elasticsearch.password: "******"
service kibana restart
修改logstash配置文件
output {
stdout { codec => rubydebug }
elasticsearch {
hosts => ["192.168.2.130:9200","192.168.2.131:9200"]
index => "nginx-test-%{+YYYY.MM.dd}"
user => "elastic"
password => "******"
}
}
相關beat也需要修改,當然我這里之前沒有裝過beat
API帶密碼的查詢方法
curl -XGET --user elastic:****** "192.168.2.130:9200/_cat/health?v"
ElastcHQ: 不需要修改配置文件,在打開頁面后的集群地址輸入http://elstic:******@localhost:9200 方式訪問
ES節點提供SSL
生成證書
/usr/share/elasticsearch/bin/elasticsearch-certgen
#文件名
#集群名
#直接回車
#節點IP 逗號隔開
#節點名稱 逗號隔開
cp /usr/share/elasticsearch/elk.zip /root/ && cd && mkdir elkca && cd elkca && cp ../elk.zip ./ && unzip elk.zip
#為es集群創建證書頒發機構
/usr/share/elasticsearch/bin/elasticsearch-certutil ca #全部回車
/usr/share/elasticsearch/bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 #全部回車
mkdir /etc/elasticsearch/cert
cp /usr/share/elasticsearch/*.p12 /etc/elasticsearch/cert/
cp -r /root/elkca/ !$
scp -r !$ 192.168.2.202:/etc/elasticsearch/
下列操作兩台ES都要做
chown -R elasticsearch:elasticsearch /etc/elasticsearch/cert/ #*** 需要把屬主改了
vim /etc/elasticsearch/elasticsearch.yml
#加上
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
#xpack.http.ssl.key: /etc/elasticsearch/cert/elkca/austyn-elk/austyn-elk.key #不行
#xpack.http.ssl.certificate: /etc/elasticsearch/cert/elkca/austyn-elk/austyn-elk.crt
#xpack.http.ssl.certificate_authorities: /etc/elasticsearch/cert/elkca/ca/ca.crt
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /etc/elasticsearch/cert/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /etc/elasticsearch/cert/elastic-certificates.p12
下面的3行實際上是為了配置XPACK,內部加密通訊
如果希望9200也是https的需要其他配置,但是我上面的配並沒有成功
瀏覽器打開Kibana、HQ 查看效果