深圳网站建设q479185700強,网站建设服务网站,客户管理软件 crm,和田地seo目录前言一、Linux 安装1、下载安装包⑴、选择需要的安装包⑵、下载解压到安装目录2、查看解压后目录结构3、启动 Elasticsearch⑴、正常启动流程⑵、启动过程遇到的问题①、启动报错②、创建运行 Elasticsearch 的用户#xff0c;启动成功#xff0c;但无法访问③、停止Elas…
目录前言一、Linux 安装1、下载安装包⑴、选择需要的安装包⑵、下载解压到安装目录2、查看解压后目录结构3、启动 Elasticsearch⑴、正常启动流程⑵、启动过程遇到的问题①、启动报错②、创建运行 Elasticsearch 的用户启动成功但无法访问③、停止Elasticsearch修改配置文件重新启动④、JDK 问题二、Windows 安装1、下载安装包2、启动 Elasticsearch⑴、正常启动流程⑵、启动过程遇到的问题①、同Linux 默认开启安全认证启动后无法直接访问前言
上一篇简单了解了一下 Elasticsearch 的发展史特性和使用场景为了方便接下来的数据测试本篇内容先开始安装 Elasticsearch。
官网下载 一、Linux 安装
1、下载安装包
⑴、选择需要的安装包
进入 官网 选择自己需要版本我这里选择 Linux x86_64 登录服务器查看系 Linux 内核版本
a[rootVM-0-12-centos ~]# arch
x86_64
[rootVM-0-12-centos ~]# uname -a
Linux VM-0-12-centos 3.10.0-1160.71.1.el7.x86_64 #1 SMP Tue Jun 28 15:37:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux⑵、下载解压到安装目录
进入 /usr/local/ 目录这个目录是我的安装目录根据自己的习惯选择下载安装包并解压
[rootVM-0-12-centos ~]# cd /usr/local/
[rootVM-0-12-centos local]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.6.1-linux-x86_64.tar.gz
--2023-02-14 09:45:52-- https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.6.1-linux-x86_64.tar.gz
Resolving artifacts.elastic.co (artifacts.elastic.co)... 34.120.127.130, 2600:1901:0:1d7::
Connecting to artifacts.elastic.co (artifacts.elastic.co)|34.120.127.130|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 581763080 (555M) [application/x-gzip]
Saving to: ‘elasticsearch-8.6.1-linux-x86_64.tar.gz’100%[] 581,763,080 12.2MB/s in 46s 2023-02-14 09:46:38 (12.2 MB/s) - ‘elasticsearch-8.6.1-linux-x86_64.tar.gz’ saved [581763080/581763080][rootVM-0-12-centos local]# tar -zvxf elasticsearch-8.6.1-linux-x86_64.tar.gz
[rootVM-0-12-centos local]# rm -f elasticsearch-8.6.1-linux-x86_64.tar.gz
[rootVM-0-12-centos local]# ll -a
total 80
drwxr-xr-x. 20 root root 4096 Feb 14 14:11 .
drwxr-xr-x. 13 root root 4096 Aug 8 2018 ..
drwxr-xr-x. 2 root root 4096 Dec 21 16:33 bin
drwxr-xr-x 9 root root 4096 Jan 25 05:47 elasticsearch-8.6.1
drwxr-xr-x. 2 root root 4096 Apr 11 2018 etc
drwxr-xr-x 6 root root 4096 Dec 21 16:21 freetype
drwxr-xr-x. 2 root root 4096 Apr 11 2018 games
drwxr-xr-x. 3 root root 4096 Dec 21 16:23 include
drwxr-xr-x. 4 root root 4096 Dec 21 16:23 lib
drwxr-xr-x. 2 root root 4096 Apr 11 2018 lib64
drwxr-xr-x. 2 root root 4096 Apr 11 2018 libexec
drwxr-xr-x 3 root root 4096 Dec 21 16:20 man
drwxr-xr-x 10 mysql mysql 4096 Dec 21 16:22 mysql
drwxr-xr-x 11 root root 4096 Dec 22 10:40 mysql-master-slave
drwxr-xr-x 11 root root 4096 Dec 21 16:37 nginx
drwxr-xr-x 10 root root 4096 Dec 21 16:33 php
drwxr-xr-x 17 root root 4096 Dec 21 16:07 qcloud
drwxr-xr-x. 2 root root 4096 Apr 11 2018 sbin
drwxr-xr-x. 8 root root 4096 Dec 21 16:20 share
drwxr-xr-x. 2 root root 4096 Apr 11 2018 src
[rootVM-0-12-centos local]# 2、查看解压后目录结构
[rootVM-0-12-centos local]# cd elasticsearch-8.6.1/
[rootVM-0-12-centos elasticsearch-8.6.1]# ll -X
total 2224
drwxr-xr-x 2 root root 4096 Jan 25 05:47 bin
drwxr-xr-x 3 root root 4096 Feb 14 14:06 config
drwxr-xr-x 8 root root 4096 Jan 25 05:47 jdk
drwxr-xr-x 5 root root 4096 Jan 25 05:47 lib
drwxr-xr-x 2 root root 4096 Jan 25 05:43 logs
drwxr-xr-x 69 root root 4096 Jan 25 05:47 modules
drwxr-xr-x 2 root root 4096 Jan 25 05:43 plugins
-rw-r--r-- 1 root root 8106 Jan 25 05:34 README.asciidoc
-rw-r--r-- 1 root root 3860 Jan 25 05:34 LICENSE.txt
-rw-r--r-- 1 root root 2235851 Jan 25 05:43 NOTICE.txt以下为 Elasticsearch 目录及主要配置文件介绍
目录|文件描述bin/二进制脚本包含启动节点的elasticsearch |-- elasticsearchelasticsearch的启动命令Linux下加”-d”参数以服务的形式后台运行。 |-- …config/配置文件目录elasticsearch、log、jvm、role、user |-- elasticsearch.yml配置文件中可进行端口、是否允许外部访问、端口等的设置。 |-- jvm.optionsjvm 配置文件 |-- log4j2.properties日志配置文件 |-- …data/在节点上申请的每个index/shard的数据文件的位置可容纳多个位置jdk/jdk包7.0版本以后自带jdk环境如果已经配置了jdk会优先使用外部 jdk 环境lib/引用的相关类库的存放目录elasticsearch.jar本身也放于该目录logs/日志文件位置modules/功能模块的存放目录如aggs、reindex、geoip、xpack、eval。。。plugins/插件文件位置。每个插件将包含在一个子目录中README.asciidocreadme文档LICENSE.txt证书NOTICE.txt通知注意事项 es依赖jdk环境现在7.0以后的es压缩包中自带有jdk。若已提前安装了jdk环境则es启动时会优先找linux中的jdk。若此时jdk的版本不一致就会造成jdk不能正常运行。所以若Linux服务本来没有配置jdk则会直接使用es目录下默认的jdk反而不会报错。 3、启动 Elasticsearch
⑴、正常启动流程
1、创建用户 elastic专门用于管理 Elasticsearch。[rootVM-0-12-centos elasticsearch-8.6.1]# useradd elastic
[rootVM-0-12-centos elasticsearch-8.6.1]# chown -R elastic:elastic /usr/local/elasticsearch-8.6.1/2、修改配置文件 elasticsearch.yml这里为了验证是否安装成功关闭安全认证xpack.security.enabled和xpack.security.http.ssl: enabled 都改为 false否则无法直接通过浏览器访问 9200端口后正式应用的时候在启用。# Enable security features
xpack.security.enabled: false# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:enabled: falsekeystore.path: certs/http.p123、切换到 elastic 用户后台启动 Elasticsearch浏览器访问 9200端口http://你的IP:9200/Linux 记得在安全组配置9200端口允许访问。[rootVM-0-12-centos elasticsearch-8.6.1]# su elastic
[elasticVM-0-12-centos elasticsearch-8.6.1]$ ./bin/elasticsearch -d⑵、启动过程遇到的问题
①、启动报错
运行 bin/ 目录下的 elasticsearch 脚本启动 elasticsearch
[rootVM-0-12-centos elasticsearch-8.6.1]# ./bin/elasticsearch
[2023-02-14T17:44:22,531][ERROR][o.e.b.Elasticsearch ] [VM-0-12-centos] fatal exception while booting Elasticsearchjava.lang.RuntimeException: can not run elasticsearch as rootat org.elasticsearch.server8.6.1/org.elasticsearch.bootstrap.Elasticsearch.initializeNatives(Elasticsearch.java:260)at org.elasticsearch.server8.6.1/org.elasticsearch.bootstrap.Elasticsearch.initPhase2(Elasticsearch.java:166)at org.elasticsearch.server8.6.1/org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:66)See logs for more details.ERROR: Elasticsearch did not exit normally - check the logs at /usr/local/elasticsearch-8.6.1/logs/elasticsearch.logERROR: Elasticsearch exited unexpectedly
[rootVM-0-12-centos elasticsearch-8.6.1]# 报错了提示 can not run elasticsearch as root不能使用root用户启动会报错。
②、创建运行 Elasticsearch 的用户启动成功但无法访问
[rootVM-0-12-centos elasticsearch-8.6.1]# useradd elastic
[rootVM-0-12-centos elasticsearch-8.6.1]# chown -R elastic:elastic /usr/local/elasticsearch-8.6.1/
[rootVM-0-12-centos elasticsearch-8.6.1]# su elastic
[elasticVM-0-12-centos elasticsearch-8.6.1]$ ./bin/elasticsearch启动成功这时候我们试着访问你的 9200端口 http://你的IP:9200/ 失败。
并且启动台那边也报错了 http client did not trust this servers certificate如下
[2023-02-14T18:04:06,931][WARN ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [VM-0-12-centos] received plaintext http traffic on an https channel, closing connection Netty4HttpChannel{localAddress/172.17.0.12:9200, remoteAddress/218.81.82.139:2348}
[2023-02-14T18:06:25,213][WARN ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [VM-0-12-centos] http client did not trust this servers certificate, closing connection Netty4HttpChannel{localAddress/172.17.0.12:9200, remoteAddress/218.81.82.139:2349}
[2023-02-14T18:06:25,214][WARN ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [VM-0-12-centos] http client did not trust this servers certificate, closing connection Netty4HttpChannel{localAddress/172.17.0.12:9200, remoteAddress/218.81.82.139:2350}原因是因为 Elasticsearch 默认开启了安全认证虽然启动台启动成功但访问 9200 端口失败。
解决办法找到config/目录下面的elasticsearch.yml配置文件把安全认证开关从原先的true都改成false实现免密登录访问即可修改这两处都为false后重新启动
③、停止Elasticsearch修改配置文件重新启动
新开一个SSH连接停止Elasticsearch
[rootVM-0-12-centos ~]# ps -ef | grep elastic
root 26132 24103 0 18:23 pts/4 00:00:00 su elastic
elastic 26133 26132 0 18:23 pts/4 00:00:00 bash
elastic 26178 26133 2 18:23 pts/4 00:00:02 /usr/local/elasticsearch-8.6.1/jdk/bin/java -Xms4m -Xmx64m -XX:UseSerialGC -Dcli.nameserver -Dcli.script./bin/elasticsearch -Dcli.libslib/tools/server-cli -Des.path.home/usr/local/elasticsearch-8.6.1 -Des.path.conf/usr/local/elasticsearch-8.6.1/config -Des.distribution.typetar -cp /usr/local/elasticsearch-8.6.1/lib/ *:/usr/local/elasticsearch-8.6.1/lib/cli-launcher/ * org.elasticsearch.launcher.CliToolLauncher
elastic 26246 26178 31 18:23 pts/4 00:00:31 /usr/local/elasticsearch-8.6.1/jdk/bin/java -Des.networkaddress.cache.ttl60 -Des.networkaddress.cache.negative.ttl10 -Djava.security.managerallow -XX:AlwaysPreTouch -Xss1m -Djava.awt.headlesstrue -Dfile.encodingUTF-8 -Djna.nosystrue -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafetrue -Dio.netty.noKeySetOptimizationtrue -Dio.netty.recycler.maxCapacityPerThread0 -Dlog4j.shutdownHookEnabledfalse -Dlog4j2.disable.jmxtrue -Dlog4j2.formatMsgNoLookupstrue -Djava.locale.providersSPI,COMPAT --add-opensjava.base/java.ioALL-UNNAMED -XX:UseG1GC -Djava.io.tmpdir/tmp/elasticsearch-2471405775610397709 -XX:HeapDumpOnOutOfMemoryError -XX:ExitOnOutOfMemoryError -XX:HeapDumpPathdata -XX:ErrorFilelogs/hs_err_pid%p.log -Xlog:gc*,gcagetrace,safepoint:filelogs/gc.log:utctime,pid,tags:filecount32,filesize64m -Xms999m -Xmx999m -XX:MaxDirectMemorySize524288000 -XX:G1HeapRegionSize4m -XX:InitiatingHeapOccupancyPercent30 -XX:G1ReservePercent15 -Des.distribution.typetar --module-path /usr/local/elasticsearch-8.6.1/lib --add-modulesjdk.net -m org.elasticsearch.server/org.elasticsearch.bootstrap.Elasticsearch
elastic 26275 26246 0 18:23 pts/4 00:00:00 /usr/local/elasticsearch-8.6.1/modules/x-pack-ml/platform/linux-x86_64/bin/controller
root 26681 26605 0 18:24 pts/5 00:00:00 grep --colorauto elastic
[rootVM-0-12-centos ~]# kill -9 26133
[rootVM-0-12-centos ~]# kill -9 26178修改配置文件 elasticsearch.yml把这两处改为 false
# Enable security features
xpack.security.enabled: falsexpack.security.enrollment.enabled: true# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:enabled: falsekeystore.path: certs/http.p12重新启动 Elasticsearch访问 9200 端口成功。 或者curl 访问
[rootVM-0-12-centos ~]# curl localhost:9200/
{name : VM-0-12-centos,cluster_name : elasticsearch,cluster_uuid : 3e6bNn6dS_G7bEfl7YhXcA,version : {number : 8.6.1,build_flavor : default,build_type : tar,build_hash : 180c9830da956993e59e2cd70eb32b5e383ea42c,build_date : 2023-01-24T21:35:11.506992272Z,build_snapshot : false,lucene_version : 9.4.2,minimum_wire_compatibility_version : 7.17.0,minimum_index_compatibility_version : 7.0.0},tagline : You Know, for Search
}
[rootVM-0-12-centos ~]# ④、JDK 问题
这里安装了一下 JDK但是 Elasticsearch8.6 仍会自动选择自己内置的JDK。如果其他版本优先选择系统环境变量中的JDK可以参考这篇博客 Elasticsearch JDK选择。
[elasticVM-0-12-centos elasticsearch-8.6.1]$ ps -ef | grep elastic
root 20695 17356 0 13:40 pts/3 00:00:00 su elastic
elastic 20697 20695 0 13:40 pts/3 00:00:00 bash
elastic 21252 1 93 13:41 pts/3 00:00:30 /usr/local/elasticsearch-8.6.1/jdk/bin/java -Des.networkaddress.cache.ttl60 -Des.networkaddress.cache.negative.ttl10 -Djava.security.managerallow -XX:AlwaysPreTouch -Xss1m -Djava.awt.headlesstrue -Dfile.encodingUTF-8 -Djna.nosystrue -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafetrue -Dio.netty.noKeySetOptimizationtrue -Dio.netty.recycler.maxCapacityPerThread0 -Dlog4j.shutdownHookEnabledfalse -Dlog4j2.disable.jmxtrue -Dlog4j2.formatMsgNoLookupstrue -Djava.locale.providersSPI,COMPAT --add-opensjava.base/java.ioALL-UNNAMED -XX:UseG1GC -Djava.io.tmpdir/tmp/elasticsearch-16881426132015000451 -XX:HeapDumpOnOutOfMemoryError -XX:ExitOnOutOfMemoryError -XX:HeapDumpPathdata -XX:ErrorFilelogs/hs_err_pid%p.log -Xlog:gc*,gcagetrace,safepoint:filelogs/gc.log:utctime,pid,tags:filecount32,filesize64m -Xms999m -Xmx999m -XX:MaxDirectMemorySize524288000 -XX:G1HeapRegionSize4m -XX:InitiatingHeapOccupancyPercent30 -XX:G1ReservePercent15 -Des.distribution.typetar --module-path /usr/local/elasticsearch-8.6.1/lib --add-modulesjdk.net -m org.elasticsearch.server/org.elasticsearch.bootstrap.Elasticsearch
elastic 21280 21252 0 13:41 pts/3 00:00:00 /usr/local/elasticsearch-8.6.1/modules/x-pack-ml/platform/linux-x86_64/bin/controller
elastic 21434 20697 0 13:42 pts/3 00:00:00 ps -ef
elastic 21435 20697 0 13:42 pts/3 00:00:00 grep --colorauto elastic
[elasticVM-0-12-centos elasticsearch-8.6.1]$ java -version
java version 17.0.6 2023-01-17 LTS
Java(TM) SE Runtime Environment (build 17.0.69-LTS-190)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.69-LTS-190, mixed mode, sharing)
[elasticVM-0-12-centos elasticsearch-8.6.1]$ 二、Windows 安装
1、下载安装包 下载后解压
2、启动 Elasticsearch
⑴、正常启动流程
由于 Elasticsearch 默认开启安全认证所以无法直接通过端口访问成功先修改 config 目录下的配置文件elasticsearch.yml把这两处改为 false。
进入 bin 目录下双击 elasticsearch.bat 文件启动 ES访问 http://localhost:9200/
⑵、启动过程遇到的问题
①、同Linux 默认开启安全认证启动后无法直接访问
和Linux 一样启动后无法访问进入logs/ 查看 elasticsearch.log 日志文件信息看到提示 received plaintext http traffic on an https channel所以找到原因了同上默认开启了安全认证不允许直接访问。 解决办法修改配置文件 elasticsearch.yml把这两处改为 false。 再次启动访问9200端口成功