elasticsearch head插件安装 (elasticsearch安装和使用)

一.软件准备

可以先去官方网站(https://www.elastic.co/cn/downloads/past-releases)*载下**需要的版本7.17.9。同时,为了比较不同的安装方式,这里,我们选择【LINUX X86_64】与【RPM X86_64】分别进行*载下**,并在本文后续查看其是如何安装,并运行的。

elasticsearch-7.17.9-linux-x86_64.tar.gz

elasticsearch-7.17.9-x86_64.rpm

二.Tar包安装及其运行

1. 解压包到/home/下:

tar -xzf elasticsearch-7.17.9-linux-x86_64.tar.gz

  1. 创建用户组,及其新用户

因ElasticSearch默认不允许我们使用root用户启动,否则会报告如下错误:

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

故此,我们需要新建用户及其用户组,如下:

#创建es用户组

groupadd es

#创建es用户并加入到es用户组

useradd es -g es

#给elasticsearch-7.17.9文件夹赋予读写权限,如果服务启动遇到日志等文件权限不足的情况,需要再次执行以下命令进行赋予权限。

chmod -R 777 /home/elasticsearch-7.17.9

  1. ES_JAVA_HOME配置

因ElasticSearch从7.0开始默认安装了java运行环境,以便在没有安装java运行环境的机器上运行,安装包已经包含了一个相匹配的 JAVA 版本在里面。但是,需要配置ES_JAVA_HOME,否则会报告如下错误:

could not find java in bundled JDK at /home/elasticsearch-7.17.9/jdk/bin/java

vi /home/elasticsearch-7.17.9/bin/elasticsearch-env

增加配置如下:

ES_JAVA_HOME="$ES_HOME/jdk"

  1. elasticsearch.yml配置

编辑:vi /home/elasticsearch-7.17.9/config/elasticsearch.yml

在最后,追加如下配置:

xpack.ml.enabled: false # 注意“:”号存在空格!

否则直接启动,会报告如下错误:

uncaught exception in thread [main] org.elasticsearch.bootstrap.StartupException: ElasticsearchException[Failure running machine learning native code. This could be due to running on an unsupported OS or distribution, missing OS libraries, or a problem with the temp directory. To bypass this problem by running Elasticsearch without machine learning functionality set [xpack.ml.enabled: false].

  1. elasticsearch.yml配置

编辑:vi /home/elasticsearch-7.17.9/config/elasticsearch.yml

在最后,追加如下配置,暂时不做更新地图:

ingest.geoip.downloader.enabled: false # 注意“:”号存在空格!

否则再次启动,会报告如下错误:

not all primary shards of [.geoip_databases] index are active

  1. 运行

在完成上面章节的一系列配置后,切换到用户es下,从命令行运行 ElasticSearch

[root@localhost home]# su - es

执行如下命令,启动ElasticSearch

/home/elasticsearch-7.17.9/bin/elasticsearch

也可以作为一个守护进程在后台运行,如下:

/home/elasticsearch-7.17.9/bin/elasticsearch -d

  1. 验证

7.1 进程确认

执行如下命令:

ps aux | grep elasticsearch

如果看到如下信息输出,证明elasticsearch的确已经正常启动

docker安装elasticsearch,elasticsearch安装和使用

7.2 Web确认

在等待一段时间后,执行如下命令:

curl "localhost:9200"

如果看到如下信息输出,证明elasticsearch的确已经正常启动

docker安装elasticsearch,elasticsearch安装和使用

{

"name" : "localhost.localdomain",

"cluster_name" : "elasticsearch",

"cluster_uuid" : "jQCjqc34TNeB-wCX5D8Drg",

"version" : {

"number" : " 7.17.9 ",

"build_flavor" : "default",

"build_type" : " tar ",

"build_hash" : "ef48222227ee6b9e70e502f0f0daa52435ee634d",

"build_date" : "2023-01-31T05:34:43.305517834Z",

"build_snapshot" : false,

"lucene_version" : "8.11.1",

"minimum_wire_compatibility_version" : "6.8.0",

"minimum_index_compatibility_version" : "6.0.0-beta1"

},

"tagline" : "You Know, for Search"

}

7.3 浏览器中访问

通过http://192.168.246.133:9200/,访问失败,需要做如下修改

修改elasticsearch.yml配置

编辑:vi /home/elasticsearch-7.17.9/config/elasticsearch.yml

增加或者修改配置如下:

network.host: 0.0.0.0

因修改此配置,可能在启动ES的时候,遇到以下错误,需要逐一进行修改配置如下:

A). max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]

编辑 /etc/security/limits.conf

增加:

es soft nofile 65536

es hard nofile 65536

说明: soft nofile表示软限制,hard nofile表示硬限制。

ulimit -H -n

修改前,输出:4096

修改后,重新登录,输出:65536

B). max number of threads [3833] for user [es] is too low, increase to at least [4096]

编辑 /etc/security/limits.conf

增加:

es soft nproc 4096

es hard nproc 4096

ulimit -H -u

修改前,输出:3833

修改后,重新登录,输出:4096

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

Elasticsearch 默认使用 mmapfs 目录存储其索引。 默认的操作系统对 mmap 计数的限制可能太低,这可能会导致内存不足异常。

可以执行如下命令,临时调整:

sysctl -w vm.max_map_count=262144

或者编辑 /etc/sysctl.conf 做永久性调整:

增加或者修改如下配置:

vm.max_map_count=262144

执行:sysctl -p

配置之后验证是否生效,请执行如下命令:

sysctl vm.max_map_count

输出为262144

D). 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配置

编辑:vi /home/elasticsearch-7.17.9/config/elasticsearch.yml

增加或者修改配置如下:

cluster.initial_master_nodes: ["node-1"]

再重新启动ES后,便可以通过浏览器正常访问了。

docker安装elasticsearch,elasticsearch安装和使用

8.安装文件目录布局:

默认情况下,所有文件和目录都包含在 $ES_HOME 中,解压缩归档时创建的目录。

类型

描述

默认位置

设置

home

Elasticsearch 主目录或 $ES_HOME

通过解压缩归档创建的目录

bin

二进制脚本包括用于启动节点的 elasticsearch 和用于安装插件的 elasticsearch-plugin

$ES_HOME/bin

config

配置文件,包括

elasticsearch.yml

$ES_HOME/config

ES_PATH_CONF

data

节点上分配的每个索引/分片的数据文件的位置,可以容纳多个位置。

$ES_HOME/data

path.data

logs

log 文件位置

$ES_HOME/logs

path.logs

plugins

插件文件位置,每个插件都将包含在一个子目录中。

$ES_HOME/plugins

repo

共享文件系统存储库位置,可以容纳多个位置,文件系统存储库可以放在此处指定的任何目录的任何子目录中。

path.repo

script

脚本文件的位置

$ES_HOME/scripts

path.scripts

三.RPM包安装

  1. RPM安装

执行如下命令,进行安装

rpm -ivh elasticsearch-7.17.9-x86_64.rpm

docker安装elasticsearch,elasticsearch安装和使用

warning: elasticsearch-7.17.9-x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID d88e42b4: NOKEY

Preparing... ################################# [100%]

Creating elasticsearch group... OK

Creating elasticsearch user... OK

Updating / installing...

1:elasticsearch-0:7.17.9-1 ################################# [100%]

### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd

sudo systemctl daemon-reload

sudo systemctl enable elasticsearch.service

### You can start elasticsearch service by executing

sudo systemctl start elasticsearch.service

Created elasticsearch keystore in /etc/elasticsearch/elasticsearch.keystore

2.重载

执行如下命令,进行重载

sudo systemctl daemon-reload

3.开机启动

执行如下命令,使服务开机启动

sudo systemctl enable elasticsearch.service

[root@localhost installed_package]# sudo systemctl enable elasticsearch.service

Created symlink from /etc/systemd/system/multi-user.target.wants/elasticsearch.service to /usr/lib/systemd/system/elasticsearch.service.

  1. 启动服务

sudo systemctl start elasticsearch.service

服务无法启动,报告:

Job for elasticsearch.service failed because the control process exited with error code. See "systemctl status elasticsearch.service" and "journalctl -xe" for details.

这里,我们直接查看错误日志:

cat /var/log/elasticsearch/elasticsearch.log

看到有如下错误信息:

[2023-03-07T10:57:26,651][ERROR][o.e.b.Bootstrap ] [localhost.localdomain] Exception

org.elasticsearch.ElasticsearchException: Failure running machine learning native code. This could be due to running on an unsupported OS or distribution, missing OS libraries, or a problem with the temp directory. To bypass this problem by running Elasticsearch without machine learning functionality set [xpack.ml.enabled: false].

同前面章节处理相同:

编辑:vi /etc/elasticsearch/elasticsearch.yml

在最后,追加如下配置:

xpack.ml.enabled: false # 注意“:”号存在空格!

再次启动服务

sudo systemctl start elasticsearch.service # 正常

sudo systemctl restart elasticsearch.service # 正常

sudo systemctl stop elasticsearch.service # 正常

5.验证

5.1 进程确认

执行如下命令:

ps aux | grep elasticsearch

如果看到如下信息输出,证明elasticsearch的确已经正常启动

docker安装elasticsearch,elasticsearch安装和使用

5.2 Web确认

在等待一段时间后,执行如下命令:

curl "localhost:9200"

如果看到如下信息输出,证明elasticsearch的确已经正常启动

docker安装elasticsearch,elasticsearch安装和使用

{

"name" : "localhost.localdomain",

"cluster_name" : "elasticsearch",

"cluster_uuid" : "EdyzPpp0S1GwrPRYIKoYtQ",

"version" : {

"number" : "7.17.9",

"build_flavor" : "default",

"build_type" : " rpm ",

"build_hash" : "ef48222227ee6b9e70e502f0f0daa52435ee634d",

"build_date" : "2023-01-31T05:34:43.305517834Z",

"build_snapshot" : false,

"lucene_version" : "8.11.1",

"minimum_wire_compatibility_version" : "6.8.0",

"minimum_index_compatibility_version" : "6.0.0-beta1"

},

"tagline" : "You Know, for Search"

}

注意: 与Tar包解压安装,可以看到build_type的值是不一样的。

5.3 浏览器中访问

通过http://192.168.246.134:9200/,同样也是访问失败,同时也一样需要做如下修改

修改elasticsearch.yml配置

编辑:vi /etc/elasticsearch/elasticsearch.yml

增加或者修改配置如下:

network.host: 0.0.0.0

但是与Tar包解压安装不同的是,在启动ES的时候,并不会同上面一样遇到那些错误,因为RPM安装,会帮助我们做一些参数设置。

下面,我们做一些简单的查看:

  1. vm.max_map_count检查

sysctl vm.max_map_count

docker安装elasticsearch,elasticsearch安装和使用

  1. 查看配置文件/usr/lib/systemd/system/elasticsearch.service

可以看到有如下配置:

docker安装elasticsearch,elasticsearch安装和使用

使用浏览器访问如下:

docker安装elasticsearch,elasticsearch安装和使用

5.安装文件目录布局:

类型

描述

默认位置

设置

home

Elasticsearch 主目录或 $ES_HOME

/usr/share/elasticsearch

bin

二进制脚本包括用于启动节点的 elasticsearch 和用于安装插件的 elasticsearch-plugin

/usr/share/elasticsearch/bin

config

配置文件,包括

elasticsearch.yml

/etc/elasticsearch

ES_PATH_CONF

config

环境变量

/etc/sysconfig/elasticsearch

data

节点上分配的每个索引/分片的数据文件的位置,可以容纳多个位置。

/var/lib/elasticsearch

path.data

jdk

用于运行Elasticsearch的*绑捆**Java开发工具包,可以通过在

/etc/sysconfig/elasticsearch中设置环境变量ES_JAVA_HOME来覆盖

/usr/share/elasticsearch/jdk

logs

log 文件位置

/var/log/elasticsearch

path.logs

plugins

插件文件位置,每个插件都将包含在一个子目录中。

/usr/share/elasticsearch/plugins

repo

共享文件系统存储库位置,可以容纳多个位置,文件系统存储库可以放在此处指定的任何目录的任何子目录中。

path.repo

以上就是基本安装部署过程,及其可能遇到的错误的基本解决方法说明。