gpt4 book ai didi

elasticsearch - 如何以非交互方式在 Elasticsearch 中启用 TLS?

转载 作者:行者123 更新时间:2023-12-02 22:47:44 25 4
gpt4 key购买 nike

根据TLS configuration docs ,要为 Elasticsearch 7.1 生成 TLS 证书,请运行:

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

相关:Enabling TLS in Elasticsearch

需要证书才能通过 REST API 启用 TLS。

但是,上述命令需要人工交互(按 Enter)。

如何以非交互方式生成上述证书?

最佳答案

以下是对我有用的命令:

cd /usr/share/elasticsearch
sudo mkdir -v certs
sudo ./bin/elasticsearch-certutil ca --out certs/elastic-stack-ca.p12 --pass ""
sudo ./bin/elasticsearch-certutil cert --ca certs/elastic-stack-ca.p12 --ca-pass "" --out certs/elastic-certificates.p12 --pass ""

还有 Ansible 的剧本:

---
- name: Create a certificate directory
file:
owner: root
group: '{{ elasticsearch_user_group }}'
mode: u=rwx,g+rx,o-rwx
path: '{{ elasticsearch_path_etc }}/{{ elasticsearch_tls_cert_dir }}'
state: directory
when: elasticsearch_tls_cert_dir is defined
- name: Check a certificate of authority
stat:
path: "{{ elasticsearch_path_etc }}/{{ elasticsearch_tls_cert_dir }}/elastic-stack-ca.p12"
register: elastic_stack_ca_file
- name: Generate a certificate of authority
args:
chdir: '{{ elasticsearch_path_etc }}'
become: yes
command: "'{{ elasticsearch_path_home }}'/bin/elasticsearch-certutil ca --out '{{ elasticsearch_path_etc }}/{{ elasticsearch_tls_cert_dir }}'/elastic-stack-ca.p12 --pass '{{ elasticsearch_tls_cert_pass }}'"
when: not elastic_stack_ca_file.stat.exists
- name: Check a certificate and private key for a node
stat:
path: "{{ elasticsearch_path_etc }}/{{ elasticsearch_tls_cert_dir }}/elastic-certificates.p12"
register: elastic_certificates_file
- name: Generate a certificate and private key for a node
args:
chdir: '{{ elasticsearch_path_etc }}'
become: yes
command: "'{{ elasticsearch_path_home }}'/bin/elasticsearch-certutil cert --ca '{{ elasticsearch_path_etc }}/{{ elasticsearch_tls_cert_dir }}'/elastic-stack-ca.p12 --ca-pass '{{ elasticsearch_tls_cert_pass }}' --out '{{ elasticsearch_path_etc }}/{{ elasticsearch_tls_cert_dir }}'/elastic-certificates.p12 --pass '{{ elasticsearch_tls_cert_ca_pass }}'"
when: elastic_stack_ca_file.stat.exists and not elastic_certificates_file.stat.exists

默认变量可以定义为:

elasticsearch_http_port: 9200
elasticsearch_path_home: "/usr/share/elasticsearch"
elasticsearch_path_etc: "/etc/elasticsearch"
elasticsearch_tls_cert_ca_pass: ""
elasticsearch_tls_cert_pass: ""
elasticsearch_tls_cert_dir: "certs"
elasticsearch_user: "elasticsearch"
elasticsearch_user_group: "elasticsearch"

进一步说明:

关于elasticsearch - 如何以非交互方式在 Elasticsearch 中启用 TLS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57495282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com