Elasticsearch 安装与部署

Elasticsearch 安装与部署

1. 安装Java环境

转至 https://www.bedebug.com/archives/jdkinstall

2. 下载Elasticsearch安装包

- http://www.elastic.org.cn/download/Elasticsearch/7.13/ (使用迅雷下载)
- https://www.elastic.co/cn/downloads/past-releases#elasticsearch

3. 创建启动账号

3.1 创建账号

useradd elastic

3.2 设置密码

passwd elastic

3.3 为账号赋予目录权限

chown -R elastic:elastic Elasticsesarch安装目录

4. 启动Elasticsearch

4.1 修改配置文件

注意: 这里配置事比较多的 目前贴出乞丐版
详细配置请参考 Elastc 官方文档
生产与测试环境 注意要开启集群密码校验

# 配置cors跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
# 集群名称
cluster.name: dsl-cluster
# 节点名称
node.name: node-1
# 当前主机ip
network.host: 10.0.0.180
# http端口
http.port: 9200
# 服务通信端口
transport.port: 9300
# 默认初始化主节点
cluster.initial_master_nodes: ["node-1"]

4.2 启动Elasticsearch

第一次启动的 可能无法启动成功,请参考下方的新手常见问题

./bin/elasticsearch -d -p pid

// -d 为 后台启动
// -p 为 输出pid 到启动目录

5. 新手常见问题

5.1 文件描述符

问题描述:引导检查报错:未开启内存锁
问题解释:Elasticsearch 使用了很多文件描述符或文件句柄。耗尽文件描述符可能是灾难性的,并且很可能会导致数据丢失。确保将运行 Elasticsearch 的用户的打开文件描述符数量限制增加到 65,536 或更高
解决办法:

vim /etc/security/limits.conf
# 添加以下内容
* soft nofile 65536
* hard nofile 65536
* soft nproc 32000
* hard nproc 32000
* hard memlock unlimited
* soft memlock unlimited

vim /etc/systemd/system.conf ,分别修改以下内容。
DefaultLimitNOFILE=65536
DefaultLimitNPROC=32000
DefaultLimitMEMLOCK=infinity

ulimit -n 65535(需使用root账号)

5.2 虚拟内存

问题描述:引导检查报错 max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
问题解释:5.0版本以后ES使用mmapfs作为默认的文件系统存储类型。可以通过配置index.store.type来设置ES默认的文件系统存储类型。ES mmapfs默认使用一个目录来存储它的索引。操作系统对 mmap 计数的默认限制可能太低,这可能会导致内存不足异常
解决办法:

  1. 修改文件系统
Niofs(非阻塞文件系统)	mmapfs(内存映射文件系统)
配置:index.store.type: niofs
  1. 使用root运行以下命令:
sysctl -w vm.max_map_count=262144
  1. 永久生效
vi /etc/sysctl.conf
vm.max_map_count=262144

grep vm.max_map_count /etc/sysctl.conf

5.3 线程数

问题描述:max number of threads [1024] for user [elasticsearch] is too low, increase to at least [2048]
问题解释:ES 使用多个线程池来进行不同类型的操作。重要的是它能够在需要时创建新线程。确保 Elasticsearch 用户可以创建的线程数至少为 4096。
解决办法:

在启动es服务之前使用root账户执行
ulimit -u 4096

vim /etc/security/limits.conf
设置nproc为4096

vim /etc/security/limits.d/90-nproc.conf 
修改如下内容(注意星号):
* soft nproc 1024  =>  * soft nproc 4096

5.4 IPv4 forwarding

问题描述:WARNING: IPv4 forwarding is disabled. Networking will not work.
问题解释:IPv4 转发已禁用,网络将不起作用
解决办法:

vi /etc/sysctl.conf
net.ipv4.ip_forward=1
restart network && systemctl restart docker
sysctl net.ipv4.ip_forward

5.5 内存不足

问题描述:error='Cannot allocate memory'Networking will not work.
问题解释:ES 5.x+堆内存大小默认配置为2G ES 7.x+默认4G
解决办法:

//JVM一般为物理内存一半
-e "ES_JAVA_OPTS=-Xms512m -Xmx512m"

本文由 在码圈 创作,如果您觉得本文不错,请随意赞赏
采用 知识共享署名4.0 国际许可协议进行许可
您可以自由的转载和修改,但请务必注明文章来源并且不可用于商业目的。
本站部分内容收集于互联网,如果有侵权内容、不妥之处,请联系我们删除。敬请谅解!
原文链接:https://www.bedebug.com/archives/elasticsearch-install
最后更新于:2022-05-10 15:00:56

请博主喝咖啡 ☕.