概述
April 11, 2019 ,ES 发布了7.0.0 版本。 ES是一个搜索引擎,基于Lucene,提供了基于RESTful 的web接口,能够达到实时,稳定,可靠,快速的搜索引擎。
Github: https://github.com/elastic/elasticsearch
中文论坛:https://elasticsearch.cn/
英文论坛: https://discuss.elastic.co/
铭毅天下的ES专栏写的很全面丰富,可以学习一下:https://blog.csdn.net/wojiushiwo987/column/info/deep-elasticsearch
ES版本
1.x —> 2.x —> 5.x —>6.x —>7.x
说下这个从2.x到5.x版本变更,ES属于ELK技术栈中的一员,ELK中的版本比较混乱,为了统一版本号,所以直接跳到了5.x的版本 。
ES单实例安装
April 11, 2019 ,ES 发布了7.0.0 版本。跟不上趟了快。。。。
先用5.6.16版本来折腾下吧
https://www.elastic.co/guide/en/elasticsearch/reference/current/setup.html
防火墙检查
关闭防火墙或者开放指定的端口
JDK版本
JDK对应版本JDK8+
[root@localhost ~]# java -version openjdk version "1.8.0_201" OpenJDK Runtime Environment (build 1.8.0_201-b09) OpenJDK 64-Bit Server VM (build 25.201-b09, mixed mode) [root@localhost ~]#
ES下载
进入官网,右上角Download ,点击进入 ,往下拉找到 past releases
选择 ElasticSearch 5.x
https://www.elastic.co/downloads/past-releases/elasticsearch-5-6-16
[root@localhost /]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.16.tar.gz
root用户修改系统参数
#!/bin/bash echo "* soft nproc 2048" >> /etc/security/limits.conf echo "* hard nproc 4096" >> /etc/security/limits.conf echo "* soft nofile 65536" >> /etc/security/limits.conf echo "* hard nofile 65536" >> /etc/security/limits.conf echo "* soft memlock unlimited" >> /etc/security/limits.conf echo "* hard memlock unlimited" >> /etc/security/limits.conf echo "vm.max_map_count = 262144" >> /etc/sysctl.conf sysctl -p ulimit -l unlimited
- soft nproc: 单个用户可用的最大进程数量(软限制)
- hard nproc: 单个用户可用的最大进程数量(硬限制)
- soft nofile:单个用户可打开的最大文件描述符数量(软限制)
- hard nofile:单个用户可打开的最大文件描述符数量(硬限制)
- max_map_count文件包含限制一个进程可以拥有的VMA(虚拟内存区域)的数量。 默认65536
新建普通用户elastic 安装es
elasticsearch出于安全考虑,只能用非root用户启动 .
所以新建用户elastic ,把刚才下载的elasticsearch-5.6.16.tar.gz 放到 /home/elastic 下解压
es设置 elasticsearch.yml
/home/elastic/elasticsearch-5.6.16/config/elasticsearch.yml
其他参数见官网: https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html
JVM设置 jvm.options
/home/elastic/elasticsearch-5.6.16/config/elasticsearch.yml
ES默认是2G堆内存,当内存不足时,调整elasticsearch的内存
-Xms4g -Xmx4g
其他参数见官网:https://www.elastic.co/guide/en/elasticsearch/reference/current/jvm-options.html
问题一: 浏览器中无法通过 http://ip:9200 访问
ElasticSearch默认的对外服务的HTTP端口是9200,节点间交互的TCP端口是9300
http://192.168.91.128:9200/ 访问不了时,elasticsearch.yml中network.host指定为服务器本身的ip 或者 0.0.0.0 即可。
重启es ,访问 http://192.168.91.128:9200/
-bash-4.2$ ./elasticsearch [2019-04-18T05:18:06,141][INFO ][o.e.n.Node ] [] initializing ... [2019-04-18T05:18:07,143][INFO ][o.e.e.NodeEnvironment ] [rMTKRxD] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [12.8gb], net total_space [17.6gb], spins? [unknown], types [rootfs] [2019-04-18T05:18:07,144][INFO ][o.e.e.NodeEnvironment ] [rMTKRxD] heap size [1.9gb], compressed ordinary object pointers [true] [2019-04-18T05:18:07,147][INFO ][o.e.n.Node ] node name [rMTKRxD] derived from node ID [rMTKRxDTTQCznZ476RGYEg]; set [node.name] to override [2019-04-18T05:18:07,148][INFO ][o.e.n.Node ] version[5.6.16], pid[42265], build[3a740d1/2019-03-13T15:33:36.565Z], OS[Linux/3.10.0-123.el7.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_201/25.201-b09] [2019-04-18T05:18:07,148][INFO ][o.e.n.Node ] JVM arguments [-Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -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=/home/elastic/elasticsearch-5.6.16] [2019-04-18T05:18:16,186][INFO ][o.e.p.PluginsService ] [rMTKRxD] loaded module [aggs-matrix-stats] [2019-04-18T05:18:16,199][INFO ][o.e.p.PluginsService ] [rMTKRxD] loaded module [ingest-common] [2019-04-18T05:18:16,199][INFO ][o.e.p.PluginsService ] [rMTKRxD] loaded module [lang-expression] [2019-04-18T05:18:16,200][INFO ][o.e.p.PluginsService ] [rMTKRxD] loaded module [lang-groovy] [2019-04-18T05:18:16,200][INFO ][o.e.p.PluginsService ] [rMTKRxD] loaded module [lang-mustache] [2019-04-18T05:18:16,200][INFO ][o.e.p.PluginsService ] [rMTKRxD] loaded module [lang-painless] [2019-04-18T05:18:16,201][INFO ][o.e.p.PluginsService ] [rMTKRxD] loaded module [parent-join] [2019-04-18T05:18:16,201][INFO ][o.e.p.PluginsService ] [rMTKRxD] loaded module [percolator] [2019-04-18T05:18:16,201][INFO ][o.e.p.PluginsService ] [rMTKRxD] loaded module [reindex] [2019-04-18T05:18:16,201][INFO ][o.e.p.PluginsService ] [rMTKRxD] loaded module [transport-netty3] [2019-04-18T05:18:16,202][INFO ][o.e.p.PluginsService ] [rMTKRxD] loaded module [transport-netty4] [2019-04-18T05:18:16,203][INFO ][o.e.p.PluginsService ] [rMTKRxD] no plugins loaded [2019-04-18T05:18:24,465][INFO ][o.e.d.DiscoveryModule ] [rMTKRxD] using discovery type [zen] [2019-04-18T05:18:26,657][INFO ][o.e.n.Node ] initialized [2019-04-18T05:18:26,657][INFO ][o.e.n.Node ] [rMTKRxD] starting ... [2019-04-18T05:18:27,594][INFO ][o.e.t.TransportService ] [rMTKRxD] publish_address {192.168.91.128:9300}, bound_addresses {[::]:9300} [2019-04-18T05:18:27,621][INFO ][o.e.b.BootstrapChecks ] [rMTKRxD] bound or publishing to a non-loopback address, enforcing bootstrap checks [2019-04-18T05:18:29,492][INFO ][o.e.m.j.JvmGcMonitorService] [rMTKRxD] [gc][young][2][4] duration [933ms], collections [1]/[1.5s], total [933ms]/[3.4s], memory [130mb]->[49.6mb]/[1.9gb], all_pools {[young] [107.7mb]->[18.6mb]/[133.1mb]}{[survivor] [16.4mb]->[16.6mb]/[16.6mb]}{[old] [5.8mb]->[16.9mb]/[1.8gb]} [2019-04-18T05:18:29,501][WARN ][o.e.m.j.JvmGcMonitorService] [rMTKRxD] [gc][2] overhead, spent [933ms] collecting in the last [1.5s] [2019-04-18T05:18:31,594][INFO ][o.e.c.s.ClusterService ] [rMTKRxD] new_master {rMTKRxD}{rMTKRxDTTQCznZ476RGYEg}{8hR6L-tHTV6W8R5eRxnQNQ}{192.168.91.128}{192.168.91.128:9300}, reason: zen-disco-elected-as-master ([0] nodes joined) [2019-04-18T05:18:32,328][INFO ][o.e.g.GatewayService ] [rMTKRxD] recovered [0] indices into cluster_state [2019-04-18T05:18:32,629][INFO ][o.e.h.n.Netty4HttpServerTransport] [rMTKRxD] publish_address {192.168.91.128:9200}, bound_addresses {[::]:9200} [2019-04-18T05:18:32,630][INFO ][o.e.n.Node ] [rMTKRxD] started
问题二 : max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
无法创建本地文件问题,用户最大可创建文件数太小
执行 root用户修改系统参数中的脚本即可
问题三: max number of threads [1024] for user [elastic] is too low, increase to at least [4096]
无法创建本地线程问题,用户最大可创建线程数太小
执行 root用户修改系统参数中的脚本即可
问题四 :max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
最大虚拟内存太小
执行 root用户修改系统参数中的脚本即可
问题五: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
如果是Centos6的话,CentOS 6内核不支持SecComp,而ES 5x默认是要执行检测命,把这个环境检测禁掉即可 ,elasticsearch.yml中追加如下配置.
bootstrap.system_call_filter: false
es 后台运行
后台以守护进程模式运行, 添加 -d 参数
-bash-4.2$ /home/elastic/elasticsearch-5.6.16/bin/elasticsearch -d -bash-4.2$ -bash-4.2$ netstat -anp|grep 9200 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp6 0 0 :::9200 :::* LISTEN 42443/java -bash-4.2$ ps -ef|grep 42443 elastic 42443 1 15 05:22 pts/0 00:00:43 /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=/home/elastic/elasticsearch-5.6.16 -cp /home/elastic/elasticsearch-5.6.16/lib/* org.elasticsearch.bootstrap.Elasticsearch -d elastic 42547 11339 0 05:26 pts/0 00:00:00 grep --color=auto 42443 -bash-4.2$ netstat -anp|grep 9300 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp6 0 0 :::9300 :::* LISTEN 42443/java -bash-4.2$
Install Elasticsearch with Docker
https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html