Elasticsearch安装最新版2019.12.26

1,453 阅读2分钟

安装

Elastic 需要 Java 8 环境

  1. 官网下载对应环境的安装包(不建议安装最新的小版本,否则使用一些非官方插件可能找不到对应的版本,比如IK分词器)
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.0-linux-x86_64.tar.gz
  1. 上传到服务器
scp -P elasticsearch-7.5.0-linux-x86_64.tar.gz root@xxx.xxx.xx.xx:/data/
  1. 解压缩
tar -zxf elasticsearch-7.5.0-linux-x86_64.tar.gz
  1. 修改配置
  • vi config/elasticsearch.yml
#允许外网访问,默认不允许
network.host: 0.0.0.0 
  1. 切换为非root用户
sudo su xx

# 或者新建一个用户
# groupadd es
# useradd es -g es -p es
# chown -R es:es ${elasticsearch_HOME}/
# sudo su es
  1. 启动
./bin/elasticsearch

#后台启动
./bin/elasticsearch -d
  1. 验证是否可以访问
curl -XGET 'xxx.xxx.xx.xx:9200/_cluster/health?pretty'

#如果访问超时,需要查看
#1. 配置文件中network.host是否配置正确,默认不允许外网访问,需要改为允许访问的ip或者0.0.0.0允许所有ip访问
#2. 如果是云的机器,检查是够是否设置了安全组规则允许访问端口9200

启动异常

os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error=‘Cannot allocate memory’

内存不足

Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error='Cannot allocate memory' (errno=12)

解决办法:调小启动内存

  • vi ${elasticsearch_HOME}/config/jvm.options
-Xms512m
-Xmx512m
RuntimeException: can not run elasticsearch as root

在 Linux 环境中,elasticsearch 不允许以 root 权限来运行

java.lang.RuntimeException: can not run elasticsearch as root

解决办法:切换非root用户

# groupadd es
# useradd es -g es -p es
# chown -R es:es ${elasticsearch_HOME}/
# sudo su es
Exception in thread “main” java.nio.file.AccessDeniedException

权限不足

Exception in thread "main" java.nio.file.AccessDeniedException: /data/elasticsearch-7.5.0/config/jvm.options

解决办法:增加权限

chown -R es:es ${elasticsearch_HOME}/
max virtual memory areas vm.max_map_count [65530] is too low

最大虚拟内存太低

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决办法:修改占用内存

#修改/etc/sysctl.conf文件,增加配置
vm.max_map_count=262144

#或
echo "vm.max_map_count=262144" >> /etc/sysctl.conf

#使修改立即生效
sysctl -p
at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

配置文件问题

the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

解决办法:修改配置文件

#vi config/elasticsearch.yml

#配置以下三者,最少其一
#[discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes]

#这里的node-1为node.name配置的值
cluster.initial_master_nodes: ["node-1"] 

安装插件

插件是一种以自定义方式增强核心Elasticsearch功能的方法 包括添加自定义映射类型,自定义分析器,本机脚本,自定义发现等

注意

插件必须安装在群集中的每个节点上 安装后,必须重新启动每个节点,插件才能显示 版本必须和Elasticsearch版本一致

  1. 安装插件
sudo bin/elasticsearch-plugin install xxx
  1. 查看已安装插件
bin/elasticsearch-plugin list 
  1. 删除插件
sudo bin/elasticsearch-plugin remove xxx
分词器插件
ik分词器

elasticsearch-analysis-ik

方法一:在线安装

  1. 执行命令

#版本需要改为和Elasticsearch一致的版本
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.5.0/elasticsearch-analysis-ik-7.5.0.zip

  1. 重启Elasticsearch

方法二:离线安装

  1. 找到对应版本(必须和Elasticsearch版本一致)
  2. 下载
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.5.0/elasticsearch-analysis-ik-7.5.0.zip
  1. 解压到plugins目录下
  2. 重启Elasticsearch
pinyin分词器

elasticsearch-analysis-pinyin

安装方法同上

安装 Kibana

  1. 下载
  2. 解压
  3. 修改配置文件
# vi config/kibana.yml

elasticsearch.hosts: ["http://xxx.xxx.xx.xx:9200/"]
  1. 启动kibana
./bin/kibana

#后台启动
./bin/kibana -d
  1. 浏览器访问 http://localhost:5601/

集群

  • 单机多实例安装
./bin/elasticsearch -E node.name=node-1 -E cluster.name=my-application -E path.data=node01_data -d

./bin/elasticsearch -E node.name=node-2 -E cluster.name=my-application -E path.data=node02_data -d

./bin/elasticsearch -E node.name=node-3 -E cluster.name=my-application -E path.data=node03_data -d

./bin/elasticsearch -E node.name=node-4 -E cluster.name=my-application -E path.data=node04_data -d

上一篇: Elasticsearch(一)——介绍

下一篇: