Elasitcsearch 带密码及ssl集群部署

首先批量部署基础服务,可参照ansible-playbook脚本 install_es.yml

---
- name: install elasticsearch
  hosts: "{{ ip }}"
  user: root
  vars:
    - elasticsearch_version: 7.8.1
    - hostip: "{{ansible_default_ipv4['address']}}"
  tasks:
    - name: create dir
      file: path={{ item }} state=directory
      with_items:
        - /opt/elasticsearch
    - name: copy file
      copy: src={{ item.src }} dest={{ item.dest }} mode='0755'
      with_items:
      - {src: "elasticsearch-{{ elasticsearch_version }}-linux-x86_64.tar.gz",
         dest: "/opt/elasticsearch/"}
    - name: unarchinve the tar package
      unarchive: src=/opt/elasticsearch/elasticsearch-{{ elasticsearch_version }}-linux-x86_64.tar.gz dest=/usr/local/ copy=no

    - name: modify config
      lineinfile:
        path: /usr/local/elasticsearch-{{ elasticsearch_version }}/config/elasticsearch.yml
        regexp: "{{ item.old }}"
        line: "{{ item.new }}"
      with_items:
        - {old: '#node.name',new: 'node.name: node-1' }
        - {old: '#bootstrap.memory_lock',new: 'bootstrap.memory_lock: false' }
        - {old: '#bootstrap.system_call_filter',new: 'bootstrap.system_call_filter: false' }
        - {old: '#cluster.initial_master_nodes',new: 'cluster.initial_master_nodes: ["node-1"]' }
        - {old: '#http.cors.enabled',new: 'http.cors.enabled: true' }
        - {old: '#http.cors.allow-origin',new: 'http.cors.allow-origin: "*"' }
        - {old: '#network.host',new: 'network.host: 0.0.0.0' }
        - {old: '#http.port',new: 'http.port: 9200' }
        - {old: '#transport.host',new: 'transport.host: {{ hostip }}' }
        - {old: '#transport.tcp.port',new: 'transport.tcp.port: 9300' }
        - {old: '#xpack.security.enabled',new: 'xpack.security.enabled: true' }
        - {old: '#xpack.security.transport.ssl.enabled',new: 'xpack.security.transport.ssl.enabled: true' }
        - {old: '#xpack.security.transport.ssl.verification_mode',new: 'xpack.security.transport.ssl.verification_mode: certificate' }
        - {old: '#xpack.security.transport.ssl.keystore.path',new: 'xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12' }
        - {old: '#xpack.security.transport.ssl.truststore.path',new: 'xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12' }
        - {old: '#discovery.zen.ping.unicast.hosts',new: 'discovery.zen.ping.unicast.hosts: [{{ ip }}]' }
        - {old: '#discovery.zen.minimum_master_nodes',new: 'discovery.zen.minimum_master_nodes: 2' }
        - {old: '#node.master',new: 'node.master: true' }
        - {old: '#node.data',new: 'node.data: false' }
        - {old: '#node.ingest',new: 'node.ingest: false' }
    - name: modify jvm
      lineinfile:
        path: /usr/local/elasticsearch-{{ elasticsearch_version }}/config/jvm.options
        regexp: "{{ item.old1 }}"
        line: "{{ item.new1 }}"
      with_items:
        - {old1: '-Xms1g',new1: '-Xms16g' }
        - {old1: '-Xmx1g',new1: '-Xmx16g' }
    - name: create dir for certs
      file: path={{ item }} state=directory
      with_items:
        - /usr/local/elasticsearch-{{ elasticsearch_version }}/config/certs
    - name: create user es
      user:
        name: es
        state: present
    - name: update the dir user onwer
      shell: chown -R es:es /usr/local/elasticsearch-{{ elasticsearch_version }}

然后通过命令,批量部署至相关服务器

ansible-playbook install_es.yml -e "ip"="192.168.0.100,192.168.0.101,192.168.0.102"

通过以上操作,仅完成基础部分部署,还需要做小部分的微调修改

第一部:进入master主机 192.168.0.100 部署路径:/usr/local/elasticsearch-7.8.1

根目录生成CA证书

bin/elasticsearch-certutil ca

中间密码无需设置,直接回车下一步

第二步:使用第一步生成的证书,产生p12密钥

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

第三步:拷贝p12文件至certs目录 

cp *.p12  config/certs/

第四步:拷贝p12文件至其它子节点的服务器相同路径下

第五步: 所有子节点的配置为

node.name: node-2 #依次递增
node.master: false
node.data: true

第五步:启动master节点,然后再启动各子节点

bin/elasticsearch -d

第六步:在master服务器设置密码,子节点无需设置,会自动同步

bin/elasticsearch-setup-passwords interactive

注:根据提示,依次输入密码,即可完成密码设置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hu_wenjie

您的鼓励将是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值