说明
- CentOS下安装ElasticSearch
- ElasticSearch常用配置参数、单节点配置、配置远程访问
- 官方文档:https://www.elastic.co/cn/
- 下载解压即可(本案例版本7.9.3)
- 依赖的环境
- Java
- ElasticSearch7.*已经内置了Java环境,不必单独安装了
- ElasticSearch7.*之前的版本需要手动安装Java环境
- Java
常用配置说明
-
elasticsearch.yml
# 集群名称(ES默认就是分布式集群,单节点也是按集群) cluster.name: my-application # 节点名称 node.name: node-1 # host名称(可以是IP,也可以是hostname) #network.host: 192.168.3.201 network.host: 0.0.0.0 # http端口 http.port: 9200 # 初始化主节点列表 cluster.initial_master_nodes: ["node-1"]
-
jvm.options
# 初始化内存占用 -Xms128m # 最大内存占用 -Xmx128m
- 说明
- 建议初始化内存和最大内存设置为一样,有利于提高ES性能
- 不要超过物理内存的50%
- 最好不要超过32G
- 说明
操作步骤
》下载
-
下载地址:https://www.elastic.co/cn/downloads/elasticsearch
-
下载包列表如下
[root@192 ES]# ll total 311360 -rw-r--r--. 1 501 games 306436527 Jan 17 12:03 elasticsearch-7.9.3-linux-x86_64.tar.gz
》准备环境e
- 安装Java环境(可选)
- ElasticSearch7.*已经内置了Java环境,不必单独安装了
- 自行安装,可以参照我的相关文章:”Linux-CentOS7下离线安装Java环境(JDK8)“
》安装ES
- 将下载的压缩包解压当相关目录即可,本案例目录:
/usr/local/es/7.9.3/
》启动测试
-
因为安全问题,ES不允许root用户启动,需要另外增加用户,本案例用户:es
[root@192 es]# useradd es [root@192 es]# passwd es Changing password for user es. New password: BAD PASSWORD: The password is shorter than 8 characters Retype new password: passwd: all authentication tokens updated successfully. [root@192 es]# chown -R es:es /usr/local/es
-
启动
[es@192 7.9.3]$ pwd /usr/local/es/7.9.3 [es@192 7.9.3]$ ./bin/elasticsearch ... [2099-01-17T17:30:33,242][INFO ][o.e.c.s.ClusterApplierService] [192.168.3.201] master node changed {previous [], current [{192.168.3.201}{SSQxPH6FRMKKP5dvo6AlOg}{L_tWA3SbSC6wy6QGHMoA2A}{127.0.0.1}{127.0.0.1:9300}{dilmrt}{ml.machine_memory=1019015168, xpack.installed=true, transform.node=true, ml.max_open_jobs=20}]}, term: 2, version: 36, reason: Publication{term=2, version=36} [2099-01-17T17:30:33,332][INFO ][o.e.h.AbstractHttpServerTransport] [192.168.3.201] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200} [2099-01-17T17:30:33,333][INFO ][o.e.n.Node ] [192.168.3.201] started ...
- 9300端口:集群服务通信端口
- 9200端口:HTTP服务端口
- started:说明启动成功
-
本机访问测试
[es@192 ~]$ curl 127.0.0.1:9200 { "name" : "192.168.3.201", "cluster_name" : "elasticsearch", "cluster_uuid" : "lXlYyx_GTdyPZgxDHtdxzg", "version" : { "number" : "7.9.3", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "c4138e51121ef06a6404866cddc601906fe5c868", "build_date" : "2020-10-16T10:36:16.141335Z", "build_snapshot" : false, "lucene_version" : "8.6.2", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }
-
默认配置启动后,只能本机访问,无法远程访问
》配置节点以及远程访问
-
打开ES相关配置文件,参考以下内容添加到文件相应位置
-
elasticsearch.yml
[es@192 config]$ vi elasticsearch.yml # add by YASIN----------------------- cluster.name: my-application node.name: node-1 network.host: 0.0.0.0 http.port: 9200 cluster.initial_master_nodes: ["node-1"]
-
jvm.options
[es@192 config]# vi jvm.options -Xms128m -Xmx128m
-
-
再次尝试启动发现报错
ERROR: [3] bootstrap checks failed [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535] [2]: max number of threads [3694] for user [es] is too low, increase to at least [4096] [3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
-
修改系统配置,参照如下配置添加到相关文件的末尾
[root@192 ~]$ vi /etc/security/limits.conf # add by YASIN----------------- es soft nofile 65535 es hard nofile 65535 es soft nproc 4096 es hard nproc 4096 [root@192 ~]# vi /etc/sysctl.conf # add by YASIN ------------------ vm.max_map_count=262144
- 配置说明:
- nofile:允许用户或组打开文件数量限制,这里的es是用户
- nproc:允许用户或组打开最大线程数量限制,这里的es是用户
- 注意:
- 修改完"limits.conf"需要重启服务器生效。
- 修改完“sysctl.conf”可以使用命令
sysctl -p
直接生效。
- 配置说明:
-
再次尝试重新启动成功
-
尝试远程连接:http://192.168.3.201:9200/
{ "name" : "node-1", "cluster_name" : "my-application", "cluster_uuid" : "Q-Ijj9WeRjOWELcznZ-5Kw", "version" : { "number" : "7.9.3", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "c4138e51121ef06a6404866cddc601906fe5c868", "build_date" : "2020-10-16T10:36:16.141335Z", "build_snapshot" : false, "lucene_version" : "8.6.2", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }