安装环境 CentOS release 7
节点1:192.168.1.16 节点2:192.168.1.17
1、因Elasticsearch是基于Java写的,所以它的运行环境中需要java的支持,在Linux下执行命令:java -version,检查Jar包是否安装
安装java版本至少是1.8以上
2、首先准备下载Elasticsearch5.5.2 安装包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.2.tar.gz
3、下载到/usr/local 目录下,解压
tar -zxvf elasticsearch-5.5.2.tar.gz
4、因为Elasticsearch5.0之后,不能使用root账户启动,我们先创建一个elasticsearch组和账户
useradd elasticsearch -g elasticsearch -p elasticsearch chown -R elasticsearch:elasticsearch elasticsearch-5.5.2
5、配置文件修改
#vim /usr/local/elasticsearch-5.5.0/config/elasticsearch.yml //集群名称 cluster.name: es-5-test //节点名称 node.name: node-1 //指定集群节点 discovery.zen.ping.unicast.hosts: ["192.168.1.16", "192.168.1.17"] //使用head等插件监控集群信息,需要打开以下配置项 http.cors.enabled: true http.cors.allow-origin: "*" http.cors.allow-credentials: true
6、启动elasticsearch
cd /usr/local/elasticsearch5.5.2/ su elasticsearch ./bin/elasticsearch
这时候我们看见下面的提示,说明就成功了
[elasticsearch@vmlnx-sma bin]$ ./elasticsearch [2017-03-02T21:43:21,185][INFO ][o.e.n.Node ] [] initializing ... [2017-03-02T21:43:21,264][INFO ][o.e.e.NodeEnvironment ] [uY3prpy] using [1] data paths, mounts [[/ (/dev/mapper/VolGroup-lv_root)]], net usable_space [43.5gb], net total_space [54.6gb], spins? [possibly], types [ext4] [2017-03-02T21:43:21,265][INFO ][o.e.e.NodeEnvironment ] [uY3prpy] heap size [1.9gb], compressed ordinary object pointers [true] [2017-03-02T21:43:21,268][INFO ][o.e.n.Node ] node name [uY3prpy] derived from node ID [uY3prpyqTHim5twauiVWhQ]; set [node.name] to override [2017-03-02T21:43:21,271][INFO ][o.e.n.Node ] version[5.2.2], pid[5602], build[f9d9b74/2017-02-24T17:26:45.835Z], OS[Linux/3.10.5-3.el6.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_121/25.121-b13] [2017-03-02T21:43:22,226][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [aggs-matrix-stats] [2017-03-02T21:43:22,226][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [ingest-common] [2017-03-02T21:43:22,226][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [lang-expression] [2017-03-02T21:43:22,227][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [lang-groovy] [2017-03-02T21:43:22,227][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [lang-mustache] [2017-03-02T21:43:22,227][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [lang-painless] [2017-03-02T21:43:22,228][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [percolator] [2017-03-02T21:43:22,228][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [reindex] [2017-03-02T21:43:22,228][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [transport-netty3] [2017-03-02T21:43:22,229][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [transport-netty4] [2017-03-02T21:43:22,230][INFO ][o.e.p.PluginsService ] [uY3prpy] no plugins loaded [2017-03-02T21:43:24,689][INFO ][o.e.n.Node ] initialized [2017-03-02T21:43:24,689][INFO ][o.e.n.Node ] [uY3prpy] starting ... [2017-03-02T21:43:24,929][INFO ][o.e.t.TransportService ] [uY3prpy] publish_address {10.245.250.65:9300}, bound_addresses {10.245.250.65:9300} [2017-03-02T21:43:24,948][INFO ][o.e.b.BootstrapChecks ] [uY3prpy] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks [2017-03-02T21:43:28,010][INFO ][o.e.c.s.ClusterService ] [uY3prpy] new_master {uY3prpy}{uY3prpyqTHim5twauiVWhQ}{AqALBH68RCucWcPmHCE6dw}{10.245.250.65}{10.245.250.65:9300}, reason: zen-disco-elected-as-master ([0] nodes joined) [2017-03-02T21:43:28,034][INFO ][o.e.h.HttpServer ] [uY3prpy] publish_address {10.245.250.65:9200}, bound_addresses {10.245.250.65:9200} [2017-03-02T21:43:28,034][INFO ][o.e.n.Node ] [uY3prpy] started [2017-03-02T21:43:28,061][INFO ][o.e.g.GatewayService ] [uY3prpy] recovered [0] indices into cluster_state
打开另一个终端进行测试:
#curl 'http://localhost:9200/?pretty' { "status": 200, "name": "Shrunken Bones", "version": { "number": "1.4.0", "lucene_version": "4.10" }, "tagline": "You Know, for Search" }
查看集群状态:
# curl -XGET 'http://192.168.1.16:9200/_cluster/health?pretty=true' { "cluster_name" : "che001-es", "status" : "green", "timed_out" : false, "number_of_nodes" : 3, "number_of_data_nodes" : 3, "active_primary_shards" : 0, "active_shards" : 0, "relocating_shards" : 0, "initializing_shards" : 0, "unassigned_shards" : 0, "delayed_unassigned_shards" : 0, "number_of_pending_tasks" : 0, "number_of_in_flight_fetch" : 0, "task_max_waiting_in_queue_millis" : 0, "active_shards_percent_as_number" : 100.0 }
开机自启动设置
#chmod +x /etc/rc.d/rc.local #vim /etc/rc.d/rc.local su - elasticsearch -c "/usr/local/elasticsearch-5.5.0/bin/elasticsearch -d"