@
此部署过程以Elasticsearch-5.6.10版本为例, 后续的学习和演示也用此版本.
1 前提: 安装JDK学习使用ES的前提是成功安装JDK —— 很基础的一项步骤, 这里省略.
此处学习演示所用的JDK版本为:
[root@host-10-0-20-50 ~]# java -version java version "1.8.0_151" Java(TM) SE Runtime Environment (build 1.8.0_151-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode) 2 准备安装包根据自己的系统版本下载相应的安装包, 链接如下:
https://www.elastic.co/downloads/elasticsearch
这里下载MacOS/Linux系统下的版本 elasticsearch-5.6.10.tar.gz.
上传并解压:
# 工作路径 mkdir /data/elk # 上传安装包后解压 tar -zxf elasticsearch-5.6.10.tar.gz # 修改安装包文件名 mv elasticsearch-5.6.10.tar.gz es-node1 3 创建ES专用用户 # 创建用户 useradd elastic -s /bin/bash # 为该用户赋予相关操作权限 chown -R elastic:elastic /data/elk 4 启动ES服务 # 切换用户 su elastic # 启动服务, -d是指在后台启动, 若不用, 则Elasticsearch将 cd /data/elk/master ./bin/elasticsearch -d注意事项:
Elasticsearch必须以 非root用户启动, 否则将抛出如下错误:
[2018-11-05T04:24:50,035][ERROR][o.e.b.Bootstrap ] Exception java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.6.10.jar:5.6.10] at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:195) ~[elasticsearch-5.6.10.jar:5.6.10] at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:342) [elasticsearch-5.6.10.jar:5.6.10] at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:132) [elasticsearch-5.6.10.jar:5.6.10] at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:123) [elasticsearch-5.6.10.jar:5.6.10] at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:70) [elasticsearch-5.6.10.jar:5.6.10] at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134) [elasticsearch-5.6.10.jar:5.6.10] at org.elasticsearch.cli.Command.main(Command.java:90) [elasticsearch-5.6.10.jar:5.6.10] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) [elasticsearch-5.6.10.jar:5.6.10] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) [elasticsearch-5.6.10.jar:5.6.10] 5 验证ES服务是否可用
通过 jps 命令查看当前系统中运行的所有Java进程, 前提是JDK的环境变量设置OK:
[elastic@host-10-0-20-50 bin]$ jps 25810 Elasticsearch # Elasticsearch的进程号 25926 Jps
通过 ps -ef 或 ps aux 命令查看
[elastic@host-10-0-20-50 bin]$ ps aux | grep elasticsearch elastic 25810 23.0 28.6 5753680 2310200 pts/0 Sl 04:31 0:19 /server/jdk1.8.0_151/bin/java -Xms2g -Xmx2g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=http://www.likecs.com/data/elk/es-node1 -cp /data/elk/es-node1/lib/* org.elasticsearch.bootstrap.Elasticsearch -d elastic 27403 0.0 0.0 103260 852 pts/0 R+ 04:33 0:00 grep elasticsearch
在MacOS/Linux的终端(或Windows的命令行)下运行命令:
# MacOS/Linux下: curl :9200/ # Windows下: Invoke-RestMethod :9200
或在浏览器中访问 "http://localhost:9200/", 若能出现类似上述终端中的信息, 说明ES服务启动成功.
运行界面参数解释:
{ "name" : "Xa0PFJM", # 当前Node的名称 "cluster_name" : "elasticsearch", # 当前节点所属的集群名称(默认是elasticsearch) "cluster_uuid" : "Bk9p7xDhR8WM9HRx3pFEEA", "version" : { "number" : "5.6.10", # 当前运行的ES的版本号 "build_hash" : "b727a60", "build_date" : "2018-06-06T15:48:34.860Z", "build_snapshot" : false, # 当前运行版本是否是从源代码构建而来 "lucene_version" : "6.6.1" }, "tagline" : "You Know, for Search" # ES的第一个tabline } 6 关闭ES服务Elasticsearch没有直接关闭或重启服务的命令, 关闭只能通过kill命令杀掉进程的方式, 如下:
[elastic@host-10-0-20-50 bin]$ ps aux | grep elasticsearch # 查看ES进程的id [elastic@host-10-0-20-50 bin]$ kill -8 25810 # 通过进程id来杀掉服务 7 重启ES服务 [elastic@host-10-0-20-50 bin]$ sh elasticsearch -d当然可以编写一个服务脚本, 来方便快捷地启动或关闭Elasticsearch服务.
8 常见问题的解决