首页 > 代码库 > Elasticsearch学习笔记-02安装
Elasticsearch学习笔记-02安装
本文系本人根据官方文档的翻译,能力有限、水平一般,如果对想学习Elasticsearch的朋友有帮助,将是本人的莫大荣幸。
原文出处:https://www.elastic.co/guide/en/elasticsearch/reference/current/_installation.html
Elasticsearch要求Java最低版本为8. 截止本文撰写的时间,推荐您使用Oracle JDK 1.8.0_73版本。JAVA的安装会因为系统环境的不同而有很大差异,所以我们在这里不会涉及太多细节。Oracle推荐的安装文档可以在其网站上找到。我只想说,安装Elasticsearch之前,请使用下面的命令检查你本机的Java JDK版本(并且安装或者升级如果需要):
Java -version
Echo $JAVA_HOME
我们设置好了JAVA,我们就可以下载并安装Elasticsearch了。二进制及以前的版本可以在这里下载: www.elastic.co/downloads。针对每一版本,你都可以在zip, tar, DEB或者RPM中选择。简单企业,我们使用tar文件。
让我们下载Elasticsearch 5.3.1 tar 如下所示(Windows用户可以下载zip包):
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.3.1.tar.gz
解压:
tar -xvf elasticsearch-5.3.1.tar.gz
上面的命令会在你的当前目录下生成一堆文件和文件夹。 进入bin目录:
cd elasticsearch-5.3.1/bin
现在我们可以启动我们的节点(服务器)和单集群(Windows用户需要执行elasticsearch.bat文件):
./elasticsearch
如果一切正常的话,你应该可以看到类似下面的一堆信息:
[2017-04-26T15:25:00,076][INFO ][o.e.n.Node ] [] initializing ... [2017-04-26T15:25:00,231][INFO ][o.e.e.NodeEnvironment ] [dfE-L1w] using [1]data paths, mounts [[(D:)]], net usable_space [42.9gb], net total_space [138.1gb], spins? [unknown], types [NTFS] [2017-04-26T15:25:00,232][INFO ][o.e.e.NodeEnvironment ] [dfE-L1w] heap size[1.9gb], compressed ordinary object pointers [true] [2017-04-26T15:25:00,235][INFO ][o.e.n.Node ] node name [dfE-L1w]derived from node ID [dfE-L1wqT-WDF6ueaHSfag]; set [node.name] to override [2017-04-26T15:25:00,235][INFO ][o.e.n.Node ] version[5.3.1], pid[5656], build[5f9cf58/2017-04-17T15:52:53.846Z], OS[Windows 8.1/6.3/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_77/25.77-b03] [2017-04-26T15:25:02,140][INFO ][o.e.p.PluginsService ] [dfE-L1w] loaded module [aggs-matrix-stats] [2017-04-26T15:25:02,141][INFO ][o.e.p.PluginsService ] [dfE-L1w] loaded module [ingest-common] [2017-04-26T15:25:02,142][INFO ][o.e.p.PluginsService ] [dfE-L1w] loaded module [lang-expression] [2017-04-26T15:25:02,142][INFO ][o.e.p.PluginsService ] [dfE-L1w] loaded module [lang-groovy] [2017-04-26T15:25:02,143][INFO ][o.e.p.PluginsService ] [dfE-L1w] loaded module [lang-mustache] [2017-04-26T15:25:02,143][INFO ][o.e.p.PluginsService ] [dfE-L1w] loaded module [lang-painless] [2017-04-26T15:25:02,144][INFO ][o.e.p.PluginsService ] [dfE-L1w] loaded module [percolator] [2017-04-26T15:25:02,145][INFO ][o.e.p.PluginsService ] [dfE-L1w] loaded module [reindex] [2017-04-26T15:25:02,146][INFO ][o.e.p.PluginsService ] [dfE-L1w] loaded module [transport-netty3] [2017-04-26T15:25:02,147][INFO ][o.e.p.PluginsService ] [dfE-L1w] loaded module [transport-netty4] [2017-04-26T15:25:02,149][INFO ][o.e.p.PluginsService ] [dfE-L1w] no plugins loaded [2017-04-26T15:25:04,757][INFO ][o.e.n.Node ] initialized [2017-04-26T15:25:04,758][INFO ][o.e.n.Node ] [dfE-L1w] starting ... [2017-04-26T15:25:05,252][INFO ][o.e.t.TransportService ] [dfE-L1w] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}, {[::1]:9300} [2017-04-26T15:25:08,336][INFO ][o.e.c.s.ClusterService ] [dfE-L1w] new_master {dfE-L1w}{dfE-L1wqT-WDF6ueaHSfag}{Q3ApvFDXRgC1vNk_WVD_AA}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined) [2017-04-26T15:25:08,475][INFO ][o.e.g.GatewayService ] [dfE-L1w] recovered[0] indices into cluster_state [2017-04-26T15:25:08,939][INFO ][o.e.h.n.Netty4HttpServerTransport] [dfE-L1w] publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200}, {[::1]:9200} [2017-04-26T15:25:08,949][INFO ][o.e.n.Node ] [dfE-L1w] started
太细节的咱就不说了,我们可以看到名为“dfE-L1w”的节点(在你的环境下改名称会所有不同)已经启动并且将其自己选举为主节点。甭着急追究“主节点”是什么意思。现在最主要的事情是我们已经启动了一个带有一个节点的集群。
正如之前提到过,我们可以改写集群或者节点的名称。可以使用下面的命令实现这一目的:
./elasticsearch -Ecluster.name=my_cluster_name -Enode.name=my_node_name
同样请留意一下控制台中HttpServer那一行的IP和端口号,标识了可以访问我们的节点的地址。默认情况下,Elasticsearch使用9200作为其restful api的端口号。
如果有必要,改端口号是可配置的。
Elasticsearch学习笔记-02安装