無(wú)密碼的其他配置項(xiàng)在:https://blog.csdn.net/Xeon_CC/article/details/132064295
elasticsearch.yml配置文件:
xpack.security.enabled: true
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.keystore.path: /path/to/elastic-certificates.p12
xpack.security.transport.ssl:
enabled: true
verification_mode: certificate
client_authentication: required
keystore.path: /path/to/elastic-certificates.p12
truststore.path: /path/to/elastic-certificates.p12
證書(shū)的密碼:
abcd1234
所有用戶(hù)的密碼:
bcda1234
生成證書(shū)
elasticsearch-certutil ca --out /path/to/elastic-stack-ca.p12 --pass abcd1234
如果你不想生成單獨(dú)的證書(shū),也就是三個(gè)節(jié)點(diǎn)共用一個(gè)證書(shū),請(qǐng)不要執(zhí)行這行命令,這行命令將被下文所提到的證書(shū)生成方式代替。
elasticsearch-certutil cert --ca /path/to/elastic-stack-ca.p12
輸入指定路徑
/path/to/elastic-certificates.p12
注意:設(shè)置密碼這一步,三個(gè)節(jié)點(diǎn)都要執(zhí)行。
設(shè)置密碼
elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password
elasticsearch-keystore add xpack.security.http.ssl.truststore.secure_password
elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
查看密碼
elasticsearch-keystore show xpack.security.http.ssl.keystore.secure_password
elasticsearch-keystore show xpack.security.http.ssl.truststore.secure_password
elasticsearch-keystore show xpack.security.transport.ssl.truststore.secure_password
elasticsearch-keystore show xpack.security.transport.ssl.keystore.secure_password
如果你希望集群共享一個(gè)整數(shù),那么三個(gè)節(jié)點(diǎn),確保elastic-certificates.p12證書(shū)文件是復(fù)制到每個(gè)節(jié)點(diǎn)的。
設(shè)置為false
xpack.security.http.ssl.enabled: false
修改密碼
elasticsearch-setup-passwords interactive
最后,配置文件改回去
xpack.security.http.ssl.enabled: true
最后在elasticsearch-head訪(fǎng)問(wèn):https://192.168.0.111:9200/?auth_user=xxx&auth_password=xxx
查看證書(shū)過(guò)期時(shí)間:
#生成pem文件
openssl pkcs12 -in /path/to/your/elastic-certificates.p12 -clcerts -nokeys -out extracted_certificate.pem
#通過(guò)pem文件查看證書(shū)過(guò)期時(shí)間:
openssl x509 -in /path/to/your/extracted_certificate.pem -noout -enddate
在上面的“生成證書(shū)”這個(gè)步驟中的第二行命令,可以換為以下的步驟,安全性會(huì)更高,注意,確保存在elastic-stack-ca.p12文件,也就上述“生成證書(shū)”步驟中的第一行命令生成的文件。
首先隨便選擇一個(gè)節(jié)點(diǎn):在任何目錄下創(chuàng)建instances.yml,并鍵入如下內(nèi)容:
instances:
- name: "node-1"
dns:
- "localhost"
ip:
- "192.168.1.105"
- name: "node-2"
dns:
- "localhost"
ip:
- "192.168.1.105"
- name: "node-3"
dns:
- "localhost"
ip:
- "192.168.1.105"
如果要配置公網(wǎng)域名:
instances:
- name: "node-1"
dns: ["abc.cde.com", "localhost"]
ip: ["192.168.1.123"]
- name: "node-2"
dns: ["abc.cde.com", "localhost"]
ip: ["192.168.1.123"]
- name: "node-3"
dns: ["abc.cde.com", "localhost"]
ip: ["192.168.1.123"]
比如我放在config目錄下
elasticsearch-certutil cert --in config/instances.yml --out config/certs/certificates.zip --ca config/certs/elastic-stack-ca.p12 --pass abcd1234
然后,解壓certificates.zip文件,會(huì)得到node-1、node-2、node-3文件夾
把node-1.p12、node-2.p12、node-3.p12復(fù)制到每個(gè)對(duì)應(yīng)es節(jié)點(diǎn)中的config/certs目錄下,certs目錄如果沒(méi)有則自己新建。
最后更改elasticsearch.yml配置文件
把這些證書(shū)文件替換為各自的證書(shū)文件。
這種配置方式的安全性要更高,推薦使用這種每個(gè)節(jié)點(diǎn)的證書(shū)都不同的方式。
如何用python通過(guò)SSL證書(shū)連接ES集群?
在每一個(gè)節(jié)點(diǎn)執(zhí)行一下命令:
使用openssl配置客戶(hù)端證書(shū)
openssl pkcs12 -in node-1.p12 -out node-1.crt -nokeys -nodes
openssl pkcs12 -in node-2.p12 -out node-2.crt -nokeys -nodes
openssl pkcs12 -in node-3.p12 -out node-3.crt -nokeys -nodes
然后,合并證書(shū);
type node-1.crt node-2.crt node-3.crt > combined_ca.crt
最后在python中使用combined_ca.crt文件,把服務(wù)器生成的這個(gè)文件拷貝到python項(xiàng)目的目錄中。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-623404.html
es = Elasticsearch(
['https://192.168.1.105:9201', 'https://192.168.1.105:9202', 'https://192.168.1.105:9203'], # 你可以指定一個(gè)或多個(gè)節(jié)點(diǎn)
http_auth=('elastic', 'your_password'),
scheme='https',
use_ssl=True,
ca_certs='combined_ca.crt', # 指定證書(shū)的路徑。
verify_certs=True # 設(shè)置為T(mén)rue意味著客戶(hù)端將驗(yàn)證服務(wù)器的證書(shū)
)
index_name='abccc_2023-08-09'
if not es.indices.exists(index=index_name):
body = {
"settings": {
"number_of_shards": 3,
},
"mappings": {
"properties": {
"location": {
"type": "geo_shape"
},
"geo_loctn": {
"type": "geo_point"
}
}
}
}
es.indices.create(index=index_name, body=body)
print('create es index ...')
如果能創(chuàng)建索引,說(shuō)明驗(yàn)證成功。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-623404.html
到了這里,關(guān)于elasticsearch 配置用戶(hù)名和密碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!