本片文章記錄的大概是18年ELK的搭建過程砂碉,現(xiàn)在找個時間記錄下來。由于當(dāng)時業(yè)務(wù)沒有涉及到Logstash組件的應(yīng)用肾请,下文介紹不包括Logstash的搭建枉阵。
1:JDK1.8
基礎(chǔ)環(huán)境 配置
JDK配置
Java8或更高版本
export JAVA_HOME=/app/bi/public_script/app_data/decrypt_appmsg/java1.8
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
圖1
軟件包
下載es,kibana,head,node相關(guān)安裝包
1?. es下載
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.2.tar.gz
2?. kibana下載
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.2.2-linux-x86_64.tar.gz
3?. node下載
wget https://npm.taobao.org/mirrors/node/latest/node-v10.1.0-linux-x64.tar.gz
4?. head下載
https://github.com/mobz/elasticsearch-head
Elasticsearch配置
1?. elasticsearch.yml
cluster.name: youyu-es-cluster
node.name: es-master
node.master: true
node.data: true
path.data: /home/es/elasticsearch/elasticsearch-data/data/data
path.logs: /home/es/elasticsearch/elasticsearch-data/data/logs
network.host: 192.168.83.90
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content- Length,Content-Type
discovery.zen.ping.unicast.hosts: ["192.168.83.90","192.168.83.91","192.168.83.92"]
discovery.zen.minimum_master_nodes: 2
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
2?. jvm.options
修改JVM相關(guān)的配置,內(nèi)存大小等等
vim /home/es/elasticsearch/elasticsearch-6.2.2/config/jvm.options
-Xms4g
-Xmx4g
圖2
node配置
1. node安裝包下載:
wget https://npm.taobao.org/mirrors/node/latest/node-v10.1.0-linux-x64.tar.gz
配置環(huán)境變量(在es用戶下配置的環(huán)境) 如圖1:
2?. node配置
export NODE_HOME=/app/service/elasticsearch/node/node-v10.1.0-linux-x64
export PATH=$NODE_HOME/bin:$PATH
3?. 使node生效
source ~/.bash_profile
4?. 查看node是否安裝成功
node -v
npm -v
head配置
1?. ead安裝包下載:
2?. head安裝文檔:
注意:安裝node需要在root用戶下安裝
3?. node.js 安裝
安裝head 前要安裝node.js技掏,只需要解壓安裝配置環(huán)境變量就OK
node地址:
1> [https://npm.taobao.org/mirrors/node/](https://npm.taobao.org/mirrors/node/)
2> wget https://npm.taobao.org/mirrors/node/latest/node-v10.1.0-linux-x64.tar.gz
4?. 啟動head需要grunt命令執(zhí)行:
安裝grunt需要進入head目錄下安裝铃将,root用戶下安裝
sudo npm install -g grunt-cli
5?. 在head的目錄下面執(zhí)行,安裝head 需要grunt命令啟動
npm install grunt --save-dev
npm install
6?. 修改Gruntfile.js文件,增加hostname屬性哑梳,設(shè)置為*
修改 vim _site/app.js 文件:修改head的連接地址
注意:head訪問要加上用戶名和密碼
kibana配置
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: "http://192.168.83.90:9200"
注意kibana.yml解決啟動警告的現(xiàn)象
xpack.reporting.encryptionKey: "a_random_string"
xpack.security.encryptionKey: "something_at_least_32_characters"
解決啟動請求es超時的現(xiàn)象
elasticsearch.requestTimeout: 50000
遇到問題相關(guān)文檔問題
解決6.2版本權(quán)限認證問題
創(chuàng)建用戶
bin/x-pack/users useradd admin -p 123456 -r superuser
elasticsearch忘記用戶名密碼劲阎,重置三步走:
1??創(chuàng)建超級用戶admin 密碼123456
> bin/x-pack/users useradd admin -p 123456 -r superuser
2??用超級用戶給elastic創(chuàng)建密碼
curl -u admin -XPUT 'http://192.168.83.91:9200/_xpack/security/user/elastic/_password?pretty' -H 'Content-Type: application/json' -d' { "password" : "123456" }'
3??驗證
curl -u elastic 'http://192.168.83.92:9200/_xpack/security/_authenticate?pretty'
注意
線上環(huán)境各個節(jié)點的es的用戶名 密碼都是elastic:123456
http://192.168.83.91:9100/?auth_user=elastic&auth_password=123456
破解x-pack證書
參考博客?
將elasticsearch 6.2.2安裝包的/plugins/x-pack/x-pack-core/x-pack-core-6.2.2.jar 這個x-pack-core-6.2.2.jar進行解壓
1?. 重新編譯XPackBuild和LicenseVerifier文件
-
將博客相應(yīng)內(nèi)容拷貝到下面的文件中
vim XPackBuild.java
-
編譯XPackBuild.java
javac -cp "/app/service/elasticsearch/elastic/elasticsearch-6.2.2/lib/elasticsearch-6.2.2.jar:/app/service/elasticsearch/elastic/elasticsearch-6.2.2/lib/lucene-core-7.2.1.jar:/app/service/elasticsearch/elastic/elasticsearch-6.2.2/lib/elasticsearch-core-6.2.2.jar:app/service/elasticsearch/elastic/elasticsearch-6.2.2/plugins/x-pack/x-pack-core/x-pack-core-6.2.2.jar" XPackBuild.java
-
將博客相應(yīng)內(nèi)容拷貝到下面的文件中
vim LicenseVerifier.java
-
編譯LicenseVerifier.java
javac -cp "/app/service/elasticsearch/elastic/elasticsearch-6.2.2/lib/elasticsearch-6.2.2.jar:/app/service/elasticsearch/elastic/elasticsearch-6.2.2/lib/lucene-core-7.2.1.jar:/app/service/elasticsearch/elastic/elasticsearch-6.2.2/plugins/x-pack/x-pack-core/x-pack-core-6.2.2.jar" LicenseVerifier.java
2?. 創(chuàng)建一個臨時文件夾mytest解壓jar
-
解壓
jar -xvf x-pack-core-6.2.2.jar
-
解壓后刪除
rm -rf x-pack-core-6.2.2.jar
-
將原先包內(nèi)的老.class文件用新的替換掉
XPackBuild.class路徑:/app/service/elasticsearch/elastic/mytest/org/elasticsearch/xpack/core
mv XPackBuild.class /app/service/elasticsearch/elastic/mytest/org/elasticsearch/xpack/core/.
LicenseVerifier.class路徑:/app/service/elasticsearch/elastic/mytest/org/elasticsearch/license
mv LicenseVerifier.class /app/service/elasticsearch/elastic/mytest/org/elasticsearch/license/.
3?. 重新打包x-pack-core-6.2.2.jar
jar -cvf x-pack-core-6.2.2.jar ./*
4?. 將新打的x-pack-core-6.2.2.jar包,拷貝到其他節(jié)點的es中相應(yīng)的位置
-
拷貝到91節(jié)點:
scp /app/service/elasticsearch/elastic/elasticsearch-6.2.2/plugins/x-pack/x-pack-core/x-pack-core-6.2.2.jar es@192.168.83.91:/app/service/elasticsearch/elastic/elasticsearch-6.2.2/plugins/x-pack/x-pack-core/.
-
拷貝到92節(jié)點:
scp /app/service/elasticsearch/elastic/elasticsearch-6.2.2/plugins/x-pack/x-pack-core/x-pack-core-6.2.2.jar es@192.168.83.92:/app/service/elasticsearch/elastic/elasticsearch-6.2.2/plugins/x-pack/x-pack-core/.
-
激活x-pack:
curl -XPUT -u admin:123456 'http://192.168.83.90:9200/_xpack/license?acknowledge=true' -H "Content-Type: application/json" -d @license.json
安全認證
注意:在es和x-pack安裝完成啟動正常的前提下涧衙,需要使用者繼續(xù)按照如下操作進行
第一步:在es集群的每個節(jié)點的配置文件elasticsearch.yml中添加下面配置使得x-pack認證機制生效
xpack.security.audit.enabled: true
第二步:開啟 xpack的 安全機制哪工。 需要在 kibana.yml中同樣加入
xpack.security.enabled: true
xpack.graph.enabled: true
xpack.watcher.enabled: true
xpack.monitoring.enabled: true
第三步:因為我們導(dǎo)入的不是試用版的license 所以如果我們要開啟安全驗證 必須要配置集群內(nèi)部通訊的TLS/SSL,實現(xiàn)過程如下:
1?. 為es集群的每個節(jié)點創(chuàng)建證書頒發(fā)機構(gòu)弧哎,執(zhí)行bin/x-pack/certutil ca 會產(chǎn)生一個文件elastic-stack-ca.p12雁比,默認的名稱是elastic-stack-ca.p12,也可以自己指定撤嫩,執(zhí)行的過程中偎捎,需要的密碼為:es123456
bin/x-pack/certutil ca
2?. 為集群中的每個節(jié)點生成證書和私鑰,執(zhí)行下面命令序攘,會生成一個elastic-certificates.p12茴她,在生成的過程中需要輸入生成的文件名和需要的密碼,密碼為:es123456
bin/x-pack/certutil cert --ca elastic-stack-ca.p12
3?. 在config目錄下面創(chuàng)建一個文件夾certs程奠,將生成的elastic-certificates.p12拷貝進去,并且要將步驟2??產(chǎn)生的證書要拷貝到其他節(jié)點的相應(yīng)位置上丈牢;
4?. 啟用TLS并指定訪問節(jié)點證書所需的信息,下面的配置在所有節(jié)點的elasticsearch.yml下都要加上
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
5?. 如果使用密碼保護節(jié)點的證書,將密碼添加到elasticsearch秘鑰庫瞄沙;密碼為:es123456
bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
6?. 最后可以初始化es kibana logstach的密碼己沛,執(zhí)行如下命令:
./bin/x-pack/setup-passwords interactive(6.2版本)
./bin/elasticsearch-setup-passwords interactive(6.3版本)
注意執(zhí)行上面的命令后,數(shù)據(jù)相關(guān)組件的密碼后距境,記住es的密碼和用戶名申尼,因為這個賬號和密碼需要配置到kibana文件中去
安全驗證相關(guān)文章