前提是:已經搭建起來集羣了,並且集羣可以正常運行。所有的節點都是健康的狀態。
另外我所有的操作都是直接使用啓動es集羣的用戶做的,如果不是這個用戶的話,對生成的證書還需要賦予可執行權限。
# # 生成證書,給集羣添加證書認證
生成證書不需關注集羣是否啓動。也就是不管集羣有沒有啓動,都可以生成證書。
先進到 bin 目錄下:
然後執行(執行這個的時候,全部回車就可以,不再對證書設置密碼,如果這裏再設置其他的密碼的話,需要在yml裏邊加其他的配置,我用沒有加的方式) : ./elasticsearch-certutil ca
這樣運行則會在:如下圖,生成一個
接着還在 bin 目錄下執行(還是一路直接回車,因爲上邊就沒有設置密碼):./elasticsearch-certutil cert --ca elastic-stack-ca.p12
會生成第二個證書文件:
接着把這個證書文件 cp 到 config 目錄下
如果你有多個節點的話,則每個節點的的config 下邊都需要放一份 證書文件,或者配置文件,直接指定這同一份證書文件。
# # 修改 config 裏邊的配置文件
添加如下的配置:
# 開啓安全認證
xpack.security.enabled: true
# 開啓ssl
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
# 生成ca證書
xpack.security.transport.ssl.keystore.path: /es/elasticsearch-7.5.0/config/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /es/elasticsearch-7.5.0/config/elastic-certificates.p12
然後這個時候就需要重新啓動集羣了,重啓集羣配置才能生效。
這個時候應該成功,自己去 logs 日誌文件裏邊查看一下集羣是否正常啓動
# # 添加用戶名和密碼
接下來還是到 bin下邊執行,需要分別設置幾個密碼,可以設置成相同的。
# 配置密碼
./elasticsearch-setup-passwords interactive
[angus@Server bin]#./elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y
Enter password for [elastic]:
Reenter password for [elastic]:
Passwords do not match.
Try again.
Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana]:
Reenter password for [kibana]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
# # 開啓 走https 請求(所有的請求必須走 https )
還是修改 config 下邊的 elasticsearch.yml 文件
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.keystore.path: /es/elasticsearch-7.5.0/config/elastic-certificates.p12
xpack.security.http.ssl.truststore.path: /es/elasticsearch-7.5.0/config/elastic-certificates.p12
# # 修改完上邊的,就會發現,kibana連不上了,需要修改kibana 的配置文件
到 存放我們生成的證書的目錄下去,也就是 config 下邊,然後執行命令 openssl pkcs12 -in elastic-certificates.p12 -cacerts -nokeys -out elastic-ca.pem 則會生成一個文件如下:
然後
pwd
看一下當前的路徑,然後修養kibana 的配置文件
vim kibana.yml
server.host: 0.0.0.0
// ip 替換成自己的ip
elasticsearch.hosts: ["https://10.10.10.10:9200"]
elasticsearch.username: kibana
// 密碼替換成自己在上邊生成的密碼
elasticsearch.password: 111
//path替換成 pwd 查看出來的路徑,也就是我們生成的 elastic-ca.pem 證書的路徑
elasticsearch.ssl.certificateAuthorities: ["path/elastic-ca.pem"]
elasticsearch.ssl.verificationMode: certificate
然後可以啓動 kibana了,去kibana 的bin目錄下執行,然後查看日誌的結果
./kibana > kibana.log &
如果之前已經啓動過kibana了:使用這個命令
lsof -i:5601
(5601 還是kibana 默認的端口號,如果沒有改過就是5601,如果自己改過,就用自己的)
可以查看出來 kibana的 進程號,然後
kill -9 進程號
進程號如下:
然後重啓kibana
./kibana > kibana.log &