Elasticsearch 安装以及遇到的问题

  1. 下载

  2. 启动服务、报错处理
  3. elasticsearch-head 插件

一、下载

官方下载地址:https://www.elastic.co/cn/downloads/elasticsearch 

个人选择版本:7.9.2

 将下载好的文件上传到服务器 【/opt】,解压,并将解压后的问题移动到 【/usr/local】

cd /opt

tar -zxvf elasticsearch-7.9.2-linux-x86_64.tar.gz

二、启动

尝试启动 Elasticsearch 

cd /usr/local/elasticsearch-7.9.2/

bin/elasticsearch

 原因:这个版本对应的 jdk 是11 ,而目前服务器安装 jdk 版本的8。其实新版本的 ES 是自带了JDK ,但是和环境变量冲突了

解决方案: 使用elasticsearch 自带的 jdk

 修改 /etc/profile 的 JAVA_HOME  

  vim /etc/profile

 刷新配置文件,重启

source /etc/profile

  ????? ,没有了jdk 报错,直接 killed? 继续找原因,看来很多博客说是内存设置的问题。

修改一、 vim bin/elasticsearch

 结果并没有效果,可能是别的配置影响

修改二、 vim config/jvm.options

 修改完重新启动:成功报错,无法用 root 启动(修改参数是有效果的)

 新增普通用户es ,并启动

useradd es

chown -R es:es /usr/local/elasticsearch-7.9.2/

su es

 正常输出日志,但是还没有授权远程访问。现在需要修改配置重新启动

 

 发现,远程端口开发后又出现报错。

1.initial heap size [134217728] not equal to maximum heap size [536870912]; this can cause resize pauses

堆内存初始化与最大不一致,可能会扩容。现在修改为一样的

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

切换到 root,执行命令

sysctl -w vm.max_map_count=262144

查看结果:

sysctl -a|grep vm.max_map_count

上述重启后就失效,永久生效的办法:

在   /etc/sysctl.conf文件最后添加一行

vm.max_map_count=262144

3.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

修改 elasticsearch.yml

 

解决完问题,重启启动:成功

 远程浏览器访问:成功

 三、安装Elasticsearch-head 插件

1.安装 head 插件首先安装 node,下载地址:https://nodejs.org/en/download/

 将下载好的 node 包上传到服务器,解压

tar -xJf  XXX.tar.xz

配置环境变量,增加如下配置

vi /etc/profile

export NODE_HOME=/usr/local/node-XXX
export PATH=$NODE_HOME/bin:$PATH

source /etc/profile

检查是否安装成功: node -v   /  npm -v

 2.安装 git 插件

yum install -y git

下载 elasticsearch-head ,并安装

git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head/
npm install

此处 npm install 可能会报错

问题 1. 日志写入没有权限

su  root 
chown -R es:es elasticsearch-7.xxx
npm install --unsafe-perm

安装好后,配置 elastic search 允许head 远程访问,在 elasticsearch.yml 末尾加如下配置

http.cors.enabled: true
http.cors.allow-origin: "*"

启动 elasticsearch 服务 

cd /usr/local/elasticsearch-7.9.2/
bin/elasticsearch

启动 elasticsearch-head 服务

cd /usr/local/elasticsearch-head/
npm run start

 后台方式启动 es:

bin/elasticsearch -d

后台启动 es-head:

nohup npm run start &

参考:https://www.cnblogs.com/sunny1009/p/11429775.html

原文地址:https://www.cnblogs.com/baizhuang/p/13801418.html