Part1:安装单机/集群版ES
-
环境 版本 Redhat/Centos 7.0 Elasticsearch 7.13.2 Kibana 7.13.2 jdk 11 - 下载
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.2-linux-x86_64.tar.gz
- 解压
tar -xzvf elasticsearch-7.13.2-linux-x86_64.tar.gz
- 修改配置文件
#进入配置目录
cd elasticsearch-7.13.2/config
#修改配置文件
vim elasticsearch.yml
#修改端口绑定
#====start====
#集群名称 同一集群的机器配置相同的名称
cluster.name: my-application
#节点名称 同一集群的机器配置不同的名称
node.name: node-1
#所有ip可访问,默认非本机不能访问
network.host: 0.0.0.0
#需要发现的集群节点(也可以只配置已在ES集群中的一个节点,该配置主要用于加入集群时的通信) 单节点可以不配置
discovery.seed_hosts: ["192.168.137.127:9300", "192.168.137.128:9300", "192.168.137.129:9300"]
#初始化时候选主节点
cluster.initial_master_nodes: ["node-1"]
#开启跨域访问用于后续的监控组件使用
http.cors.enabled: true
http.cors.allow-origin: "*"
#====end====
- 修改系统环境变量 此操作需要root权限
启动es报错:
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
#使配置永久生效
#修改/etc/sysctl.conf
vim /etc/sysctl.conf
#This file contains the maximum number of memory map areas a process may have. Memory map areas are used as a side-effect of calling malloc, directly by mmap and mprotect, and also when loading shared libraries.While most applications need less than a thousand maps, certain programs, particularly malloc debuggers, may consume lots of them, e.g., up to one or two maps per allocation.The default value is 65536.
#max_map_count文件包含限制一个进程可以拥有的VMA(虚拟内存区域)的数量。虚拟内存区域是一个连续的虚拟地址空间区域。在进程的生命周期中,每当程序尝试在内存中映射文件,链接到共享内存段,或者分配堆空间的时候,这些区域将被创建。调优这个值将限制进程可拥有VMA的数量。限制一个进程拥有VMA的总数可能导致应用程序出错,因为当进程达到了VMA上线但又只能释放少量的内存给其他的内核进程使用时,操作系统会抛出内存不足的错误。如果你的操作系统在NORMAL区域仅占用少量的内存,那么调低这个值可以帮助释放内存给内核用。
#====start====
vm.max_map_count=262144
#====end====
#使配置临时生效
sysctl -w vm.max_map_count=262144
#查看结果:
sysctl -a | grep vm.max_map_count
- 修改jvm参数
机器内存不够,启动es报错:
Exception in thread "main" java.nio.file.AccessDeniedException: /opt/soft/elasticsearch-7.13.2/config/jvm.options
#根据机器配置,配置合适的参数
vim config/jvm.options
#====start====
-Xms512m
-Xmx512m
#====end====
- 修改最大文件描述符和最大用户线程数
启动es报错:
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max number of threads [1786] for user [lck] is too low, increase to at least [4096]
vim /etc/security/limits.conf
#====start====
#*代表对所有用户生效 设置后不生效可以重启机器试试
* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
#====end====
#修改后**重新登陆**,查看修改结果。设置不生效可以重启机器试试
ulimit -Hn
ulimit -Sn
-
启动Es
-
添加用户 es启动不能使用root用户
#adduser useradd elk #update password echo "password" | passwd elk --stdin #change file owner chown -R elk:elk elk安装目录 #设置elk角色具有sudo权限 vim /etc/sudoers #====start==== elk ALL=(ALL) ALL #====end====
-
如果是复制的文件夹创建的集群记得把data目录删除,该目录记录了es实例的唯一标识信息,该标识集群中不能重复
#切换到非root用户启动
#前台启动
bin/elasticsearch
#后台启动
bin/elasticsearch -d
- 验证启动是否成功
#验证启动成功
http://192.168.137.127:9200/
#查看集群状态
http://192.168.137.127:9200/_cat/health?v