ElasticSearch6.x.下载安装与配置教程
(1)下载并解压缩
[root@node1 ~]# tar -zxvf jdk-8u112-linux-x64.tar.gz -C /opt
(2)编辑环境变量
vi /etc/profile.d/custom.sh
[root@node1 ~]# vi /etc/profile.d/custom.sh [root@node1 ~]# cat /etc/profile.d/custom.sh #!/bin/bash #java path export JAVA_HOME=/opt/jdk1.8.0_112 export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib
(3)生效
[root@node1 ~]# source /etc/profile.d/custom.sh
(4)查看JDK版本
[root@node1 ~]# java -version java version "1.8.0_112" Java(TM) SE Runtime Environment (build 1.8.0_112-b15) Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode) [root@node1 ~]#2. ElasticSearch 6.x 软件包下载
(1)ElasticSearch 相关软件下载官网
https://www.elastic.co/cn/downloads
(2)下载ElasticSearch
https://www.elastic.co/downloads/elasticsearch
[root@node1 ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.0.tar.gz --2017-12-18 07:54:45-- https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.0.tar.gz Resolving artifacts.elastic.co (artifacts.elastic.co)... 184.73.156.41, 54.225.188.6, 54.235.82.130, ... Connecting to artifacts.elastic.co (artifacts.elastic.co)|184.73.156.41|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 28535876 (27M) [application/x-gzip] Saving to: ‘elasticsearch-6.1.0.tar.gz’ 100%[==============================================================================================>] 28,535,876 33.8KB/s in 10m 53s 2017-12-18 08:05:39 (42.7 KB/s) - ‘elasticsearch-6.1.0.tar.gz’ saved [28535876/28535876] [root@node1 ~]#
(2)解压缩
tar -zxvf elasticsearch-6.1.0.tar.gz
[root@node1 ~]# tar -zxvf elasticsearch-6.1.0.tar.gz -C /opt elasticsearch-6.1.0/ elasticsearch-6.1.0/lib/ .... .... elasticsearch-6.1.0/modules/lang-painless/antlr4-runtime-4.5.3.jar elasticsearch-6.1.0/plugins/ [root@node1 ~]#3. 创建用户
从5.0开始,ElasticSearch 安全级别提高了,不允许采用root帐号启动,所以我们要添加一个用户。
(1)创建es用户组
[root@node1 ~]# groupadd es
(2)创建用户es
useradd es(用户名) -g es(组名) -p es(密码)
[root@node1 ~]# useradd es -g es -p es
(3)修改权限
更改elasticsearch-6.1.0文件夹以及内部文件的所属用户以及组为es,-R表示逐级(N层目录)
[root@node1 ~]# chown -R es:es /opt/elasticsearch-6.1.04. 启动
(1)切换用户
[root@node1 ~]# su es
(2)启动ElasticSearch
[es@node1 root]$ cd /opt/elasticsearch-6.1.0/ [es@node1 elasticsearch-6.1.0]$ bin/elasticsearch [2017-12-18T09:23:57,668][INFO ][o.e.n.Node ] [] initializing ... [2017-12-18T09:23:57,883][INFO ][o.e.e.NodeEnvironment ] [MD1gu0h] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [15.4gb], net total_space [21.9gb], types [rootfs] [2017-12-18T09:23:57,884][INFO ][o.e.e.NodeEnvironment ] [MD1gu0h] heap size [1007.3mb], compressed ordinary object pointers [true] [2017-12-18T09:23:57,887][INFO ][o.e.n.Node ] node name [MD1gu0h] derived from node ID [MD1gu0heRDeWuoFvGaygqg]; set [node.name] to override [2017-12-18T09:23:57,888][INFO ][o.e.n.Node ] version[6.1.0], pid[2172], build[c0c1ba0/2017-12-12T12:32:54.550Z], OS[Linux/3.10.0-514.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_112/25.112-b15] [2017-12-18T09:23:57,888][INFO ][o.e.n.Node ] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/opt/elasticsearch-6.1.0, -Des.path.conf=/opt/elasticsearch-6.1.0/config] [2017-12-18T09:24:00,157][INFO ][o.e.p.PluginsService ] [MD1gu0h] loaded module [aggs-matrix-stats] [2017-12-18T09:24:00,157][INFO ][o.e.p.PluginsService ] [MD1gu0h] loaded module [analysis-common] [2017-12-18T09:24:00,158][INFO ][o.e.p.PluginsService ] [MD1gu0h] loaded module [ingest-common] [2017-12-18T09:24:00,158][INFO ][o.e.p.PluginsService ] [MD1gu0h] loaded module [lang-expression] [2017-12-18T09:24:00,158][INFO ][o.e.p.PluginsService ] [MD1gu0h] loaded module [lang-mustache] [2017-12-18T09:24:00,158][INFO ][o.e.p.PluginsService ] [MD1gu0h] loaded module [lang-painless] [2017-12-18T09:24:00,158][INFO ][o.e.p.PluginsService ] [MD1gu0h] loaded module [mapper-extras] [2017-12-18T09:24:00,159][INFO ][o.e.p.PluginsService ] [MD1gu0h] loaded module [parent-join] [2017-12-18T09:24:00,159][INFO ][o.e.p.PluginsService ] [MD1gu0h] loaded module [percolator] [2017-12-18T09:24:00,159][INFO ][o.e.p.PluginsService ] [MD1gu0h] loaded module [reindex] [2017-12-18T09:24:00,159][INFO ][o.e.p.PluginsService ] [MD1gu0h] loaded module [repository-url] [2017-12-18T09:24:00,159][INFO ][o.e.p.PluginsService ] [MD1gu0h] loaded module [transport-netty4] [2017-12-18T09:24:00,160][INFO ][o.e.p.PluginsService ] [MD1gu0h] loaded module [tribe] [2017-12-18T09:24:00,160][INFO ][o.e.p.PluginsService ] [MD1gu0h] no plugins loaded [2017-12-18T09:24:03,471][INFO ][o.e.d.DiscoveryModule ] [MD1gu0h] using discovery type [zen] [2017-12-18T09:24:04,371][INFO ][o.e.n.Node ] initialized [2017-12-18T09:24:04,371][INFO ][o.e.n.Node ] [MD1gu0h] starting ... [2017-12-18T09:24:04,637][INFO ][o.e.t.TransportService ] [MD1gu0h] publish_address {192.168.80.131:9300}, bound_addresses {192.168.80.131:9300} [2017-12-18T09:24:04,672][INFO ][o.e.b.BootstrapChecks ] [MD1gu0h] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks [2017-12-18T09:24:07,765][INFO ][o.e.c.s.MasterService ] [MD1gu0h] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {MD1gu0h}{MD1gu0heRDeWuoFvGaygqg}{AXDov8dlRNGpubGAks8ODA}{192.168.80.131}{192.168.80.131:9300} [2017-12-18T09:24:07,773][INFO ][o.e.c.s.ClusterApplierService] [MD1gu0h] new_master {MD1gu0h}{MD1gu0heRDeWuoFvGaygqg}{AXDov8dlRNGpubGAks8ODA}{192.168.80.131}{192.168.80.131:9300}, reason: apply cluster state (from master [master {MD1gu0h}{MD1gu0heRDeWuoFvGaygqg}{AXDov8dlRNGpubGAks8ODA}{192.168.80.131}{192.168.80.131:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]]) [2017-12-18T09:24:07,835][INFO ][o.e.h.n.Netty4HttpServerTransport] [MD1gu0h] publish_address {192.168.80.131:9200}, bound_addresses {192.168.80.131:9200} [2017-12-18T09:24:07,835][INFO ][o.e.n.Node ] [MD1gu0h] started [2017-12-18T09:24:07,851][INFO ][o.e.g.GatewayService ] [MD1gu0h] recovered [0] indices into cluster_state
ctrl+c停止。
(3)后台运行
可以通过参数-d后台运行
[es@node1 elasticsearch-6.1.0]$ bin/elasticsearch -d
(4)查询进程
[es@node1 elasticsearch-6.1.0]$ jps 2327 Elasticsearch 2344 Jps [es@node1 elasticsearch-6.1.0]$5. 验证
使用curl验证
[es@node1 elasticsearch-6.1.0]$ curl localhost:9200 { "name" : "MD1gu0h", "cluster_name" : "elasticsearch", "cluster_uuid" : "MRAhTG8pR1mAif_tGg9qYg", "version" : { "number" : "6.1.0", "build_hash" : "c0c1ba0", "build_date" : "2017-12-12T12:32:54.550Z", "build_snapshot" : false, "lucene_version" : "7.1.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" } [es@node1 elasticsearch-6.1.0]$6.异常闪退解决办法
可能出现elasticsearch启动后,闪退现象。
[es@node1 elasticsearch-6.1.0]$ bin/elasticsearch -d [es@node1 elasticsearch-6.1.0]$ jps 2933 Jps 2918 Elasticsearch [es@node1 elasticsearch-6.1.0]$ jps 2947 Jps 2918 Elasticsearch [es@node1 elasticsearch-6.1.0]$ jps 3023 Jps [es@node1 elasticsearch-6.1.0]$
查看日志
[es@node1 elasticsearch-6.1.0]$ vi logs/elasticsearch.log
发现异常信息
[2017-12-18T08:57:49,869][INFO ][o.e.n.Node ] initialized [2017-12-18T08:57:49,870][INFO ][o.e.n.Node ] [MD1gu0h] starting ... [2017-12-18T08:57:50,145][INFO ][o.e.t.TransportService ] [MD1gu0h] publish_address {192.168.80.131:9300}, bound_addresses {192.168.80.131:9300} [2017-12-18T08:57:50,163][INFO ][o.e.b.BootstrapChecks ] [MD1gu0h] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks [2017-12-18T08:57:50,169][ERROR][o.e.b.Bootstrap ] [MD1gu0h] node validation exception [2] bootstrap checks failed [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] [2017-12-18T08:57:50,245][INFO ][o.e.n.Node ] [MD1gu0h] stopping ... [2017-12-18T08:57:50,289][INFO ][o.e.n.Node ] [MD1gu0h] stopped [2017-12-18T08:57:50,290][INFO ][o.e.n.Node ] [MD1gu0h] closing ... [2017-12-18T08:57:50,311][INFO ][o.e.n.Node ] [MD1gu0h] closed
[2] bootstrap checks failed [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
切换到root用户,
[root@node1 elasticsearch-6.1.0]# vi /etc/sysctl.conf
添加内容如下:
vm.max_map_count=262144
修改文件/etc/security/limits.conf
[root@node1 logs]# vi /etc/security/limits.conf
添加如下内容
* hard nofile 65536 * soft nofile 65536 * soft nproc 2048 * hard nproc 4096 # End of file
然后重启即可。
7.修改配置文件[es@node1 elasticsearch-6.1.0]$ vi config/elasticsearch.yml
修改network.host和http.port
# Set the bind address to a specific IP (IPv4 or IPv6): # network.host: 192.168.80.131 # # Set a custom port for HTTP: # http.port: 9200
保存退出。
8.再次启动(1)curl
[root@node1 ~]# curl 192.168.80.131:9200 { "name" : "MD1gu0h", "cluster_name" : "elasticsearch", "cluster_uuid" : "MRAhTG8pR1mAif_tGg9qYg", "version" : { "number" : "6.1.0", "build_hash" : "c0c1ba0", "build_date" : "2017-12-12T12:32:54.550Z", "build_snapshot" : false, "lucene_version" : "7.1.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" } [root@node1 ~]#
(2)使用浏览器打开
如果在Windows平台通过浏览器打开,需要配置hosts。编辑C:\Windows\System32\drivers\etc\hosts
添加
192.168.80.131 node1
下一篇: Linux进入单用户模式进行修复
推荐阅读