ElasticSearch 6.x 学习笔记:1.下载安装与配置

1. 安装配置JDK 8

(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.0

4. 启动

(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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏北京马哥教育

Tomcat的三种模式及并发优化

Tomcat的运行模式有3种 1、bio 默认的模式,性能非常低下,没有经过任何优化处理和支持. 2、nio 利用java的异步io护理技术,noblockin...

3136
来自专栏散尽浮华

Linux下Redis主从复制以及SSDB主主复制环境部署记录

前面的文章已经介绍了redis作为缓存数据库的说明,本文主要说下redis主从复制及集群管理配置的操作记录: Redis主从复制(目前redis仅支持主从复制模...

2167
来自专栏CaiRui

nginx的worker_processes优化

nginx的worker_processes参数 来源: http://bbs.linuxtone.org/thread-1062-1-1.html 分享一: ...

4127
来自专栏Netkiller

PHP高级编程之守护进程

PHP高级编程之守护进程 摘要 2014-09-01 发表 2015-08-31 更新 2015-10-20 更新,增加优雅重启 ---- 目录 1. 什么是守...

2874
来自专栏Jed的技术阶梯

Linux集群系统时间同步

要做到服务器集群的时间同步,集群中各台机器的时区必须相同的,我们在国内就使用中国时区,如果你的机器的时区不是"Asia/Shanghai",需要修改时区

1044
来自专栏Golang语言社区

完整的golang 多协程+信道 任务处理示例

有几个地方需要注意:for i + 协程时如果协程使用可 i ,那么需要增加 i:= 来防止多协程冲突;实际执行任务时需要用一个函数包起来,防止单个任务pani...

4175
来自专栏Golang语言社区

完整的golang 多协程+信道 任务处理示例

有几个地方需要注意:for i + 协程时如果协程使用可 i ,那么需要增加 i:= 来防止多协程冲突;实际执行任务时需要用一个函数包起来,防止单个任务pani...

2947
来自专栏派森公园

docker的reap问题

在使用docker容器的时候,应该了解“PID1僵尸进程reap”问题。如果使用的时候不加注意,可能会导致出现一些意想不到的问题。

883
来自专栏Netkiller

PHP高级编程之守护进程

PHP高级编程之守护进程 摘要 2014-09-01 发表 2015-08-31 更新 2015-10-20 更新,增加优雅重启 ---- 目录 1. 什么是守...

2777
来自专栏bboysoul

使用本地的docker客户端连接远程docker的守护进程

在这之前我们要知道docker是一个c/s架构的程序,也就是说我们输入的docker命令实际上是客户端用来发送指令给docker的守护进程的,所有的操作都是do...

542

扫码关注云+社区