es集群安装及优化

es主节点
192.168.23.100
es节点
192.168.23.101
192.168.23.102

1.安装主节点

1.去官网下载es的yum包
官网下载地址 https://www.elastic.co/cn/downloads/elasticsearch
根据自己的需要下载对应的包
在这里插入图片描述

2.下载好之后把所有的包都传到从节点上,安装

[root@localhost ~]# ansible all -m copy -a 'src=/root/elasticsearch-8.11.3-x86_64.rpm dest=/root/elasticsearch-8.11.3-x86_64.rpm'
192.168.23.102 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "checksum": "64c9029f99fa4beeabae1a36d1a88b8bf44982cf", 
    "dest": "/root/elasticsearch-8.11.3-x86_64.rpm", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "d4b85a836646cd0b8c1d87848bf2e77c", 
    "mode": "0644", 
    "owner": "root", 
    "size": 630669510, 
    "src": "/root/.ansible/tmp/ansible-tmp-1704551077.26-16135-196050427416681/source", 
    "state": "file", 
    "uid": 0
}
192.168.23.101 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "checksum": "64c9029f99fa4beeabae1a36d1a88b8bf44982cf", 
    "dest": "/root/elasticsearch-8.11.3-x86_64.rpm", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "d4b85a836646cd0b8c1d87848bf2e77c", 
    "mode": "0644", 
    "owner": "root", 
    "size": 630669510, 
    "src": "/root/.ansible/tmp/ansible-tmp-1704551077.26-16133-148347610662829/source", 
    "state": "file", 
    "uid": 0
}
[root@localhost ~]# ansible all -m shell -a 'ls /root/'
192.168.23.102 | CHANGED | rc=0 >>
anaconda-ks.cfg
elasticsearch-8.11.3-x86_64.rpm
192.168.23.101 | CHANGED | rc=0 >>
anaconda-ks.cfg
elasticsearch-8.11.3-x86_64.rpm


[root@localhost ~]# ansible all -m shell -a 'yum localinstall /root/elasticsearch-8.11.3-x86_64.rpm -y'
[WARNING]: Consider using the yum module rather than running 'yum'.  If you need to use command because yum is insufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in
ansible.cfg to get rid of this message.
192.168.23.101 | CHANGED | rc=0 >>
Loaded plugins: fastestmirror
Examining /root/elasticsearch-8.11.3-x86_64.rpm: elasticsearch-8.11.3-1.x86_64
Marking /root/elasticsearch-8.11.3-x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package elasticsearch.x86_64 0:8.11.3-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package          Arch      Version       Repository                       Size
================================================================================
Installing:
 elasticsearch    x86_64    8.11.3-1      /elasticsearch-8.11.3-x86_64    1.2 G

Transaction Summary
================================================================================
Install  1 Package

Total size: 1.2 G

3.更改主配置文件

[root@localhost ~]# grep -Ev "^#|^$" /etc/elasticsearch/elasticsearch.yml 
cluster.name: ELK cluster            #集群名字,每个节点一样    
node.name: {{ ansible_hostname }}    #每个机器的主机名
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 0.0.0.0              # 通讯地址,设置为本机ip或者0.0.0.0,让所有机器都可以访问
discovery.seed_hosts: ["192.168.23.100", "192.168.23.101","192.168.23.102"] #每个节点相同
cluster.initial_master_nodes: ["192.168.23.100"]  #此为选举主节点,如果写一个就默认那一个是主节点,如果写多个,让他们自己去竞争那个是节点
xpack.security.enabled: false   #关闭安全认证
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:
  enabled: true
  keystore.path: certs/http.p12
xpack.security.transport.ssl:
  enabled: true
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12
http.host: 0.0.0.0

4.写yml吧配置文件传送到 其他节点

[root@es ~]# cat 1.yml 
---
[root@es ~]# cat 1.yml 
[root@es ~]# cat 1.yml 
---
- name: copy es
  hosts: xp
  tasks:
    - name: copy es
      template:
        src: /etc/elasticsearch/elasticsearch.yml
        dest: /etc/elasticsearch/elasticsearch.yml
      notify: restart es
    - name: restart es
      service:
        name: elasticsearch
        enabled: yes
  handlers:
    - name: restart es
      service:
        name: elasticsearch
        state: restarted    

5.运行playbook

[root@es ~]# ansible-playbook 1.yml 

PLAY [copy es] ***************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************************************************************************************************
ok: [192.168.23.101]
ok: [192.168.23.102]

TASK [copy es] ***************************************************************************************************************************************************************************************************
ok: [192.168.23.102]
ok: [192.168.23.101]

TASK [restart es] ************************************************************************************************************************************************************************************************
changed: [192.168.23.102]
changed: [192.168.23.101]

PLAY RECAP *******************************************************************************************************************************************************************************************************
192.168.23.101             : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
192.168.23.102             : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

此时在访问主节点上的9200端口

在这里插入图片描述

内存优化

[root@es ~]# egrep '## -Xm' /etc/elasticsearch/jvm.options
## -Xms4g
## -Xmx4g

#推荐使用物理机的一半,es的heap最大内存不超过30g,26g是最安全的

范例
[root@es ~]# egrep '-Xm' /etc/elasticsearch/jvm.options
-Xms30g
-Xmx30g
  • 6
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于Elasticsearch 8.8.1版本的集群安装,你需要按照以下步骤进行操作: 1. 下载Elasticsearch 8.8.1版本的安装包: 你可以从Elasticsearch的官方网站(https://www.elastic.co/downloads/elasticsearch)上下载适合你系统的安装包。选择与你操作系统兼容的版本并下载。 2. 解压安装包: 将下载的安装包解压到你想要安装的目录。 3. 配置Elasticsearch: 进入解压后的目录,找到`config`文件夹,然后编辑`elasticsearch.yml`文件。在其中配置以下参数: - `cluster.name`:设置集群的名称,确保不同集群使用不同的名称。 - `node.name`:设置节点的名称,确保每个节点都有唯一的名称。 - `network.host`:设置节点绑定的IP地址。 - `discovery.seed_hosts`:设置用于节点发现的主机列表。 - `cluster.initial_master_nodes`:设置初始主节点的名称。 配置完成后保存文件。 4. 启动Elasticsearch节点: 运行以下命令启动Elasticsearch节点: ``` ./bin/elasticsearch ``` 你可以在终端中看到节点启动的输出日志。 5. 添加更多节点: 如果你想要创建一个集群,可以在其他节点上重复步骤3和步骤4,确保所有节点的配置文件中的`cluster.name`和`discovery.seed_hosts`参数相同。 6. 验证集群状态: 运行以下命令来验证集群的状态: ``` curl -XGET http://localhost:9200/_cluster/health?pretty ``` 如果返回的响应中显示集群的状态为`green`,则表示集群安装成功。 请注意,以上步骤仅适用于简单的本地集群安装。如果你需要在生产环境中部署Elasticsearch集群,你可能需要进一步配置和优化。你可以参考Elasticsearch的官方文档(https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)获取更多详细信息。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值