一、es7新变化:
1、索引结构,es7.0后去掉了索引
在 5.X 版本和之前版本,一个 index 下可以创建多个 type;
在 6.X 版本中,一个 index 下只能存在一个 type;
在 7.X 版本中,直接去除了 type 的概念,就是说 index 不再会有 type。
es6 时,官方就提到了 es7 会删除 type,并且 es6 时已经规定每一个 index 只能有一个 type。在 es7 中使用默认的 _doc 作为 type,官方说在 8.x 版本会彻底移除 type。
2、7.0自带java环境,所以我们在安装es时不再需要单独下载和配置java_home。
3、7.0将不会再有OOM的情况,JVM引入了新的circuit breaker(熔断)机制,当查询或聚合的数据量超出单机处理的最大内存限制时会被截断,并抛出异常(有点类似clickhouse)
4、默认配置变化:默认节点名称为主机名,默认分片数改为 1,不再是 5。
5、在新版7.0的es中,对es的集群发现系统做了调整,不再有discovery.zen.minimum_master_nodes这个控制集群脑裂的配置,转而由集群自主控制,并且新版在启动一个新的集群的时候需要有cluster.initial_master_nodes初始化集群列表。
二、es7.5安装
1、检查selinux和firewalld是否关闭。
2、yum安装,或者下载rpm包安装。
3、配置文件修改:
es的角色分为:master,data,client,不同的节点,配置不一样,以下是master的节点配置,建议master角色和data角色不重复,client节点中将node.master和node.data置为false。
3.1 elasticsearch.yml的配置:尤其是角色、数据目录,日志目录,主节点选举的配置:
cluster.name: test-es
node.name: test-es-server-0-master
node.master: true
node.data: false
#配置master节点列表,多个节点格式:["node-1", "node-2"],或者使用yaml格式配置。只在master节点配置,date和client节点不配置。
cluster.initial_master_nodes: test-es-server-0-master
node.ingest: true
path.data: /data/es-master
path.logs: /data/es-master
transport.port: 19200
http.port: 9200
bootstrap.memory_lock: true
network.host: 192.168.1.1
indices.memory.index_buffer_size: 20%
indices.recovery.max_bytes_per_sec: 2g
node.attr.rack_id: 192.168.1.1
cluster.routing.allocation.awareness.attributes: rack_id
cluster.routing.allocation.same_shard.host: true
thread_pool.search.max_queue_size: 2000
action.destructive_requires_name: true
discovery.seed_hosts: ["192.168.1.1:19200","192.168.1.2:19201","192.168.1.3:19202"]
#举行选举的最小主节点个数:主节点数/2+1.es7以后此参数不再生效,选举过程由集群自主控制。
#discovery.zen.minimum_master_nodes: 1
#开启xpack认证。
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /etc/es-master/cert/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /etc/es-master/cert/elastic-certificates.p12
xpack.security.http.ssl.enabled: false
xpack.security.http.ssl.keystore.path: /etc/es-master/cert/elastic-certificates.p12
xpack.security.http.ssl.truststore.path: /etc/es-master/cert/elastic-certificates.p12
xpack.security.http.ssl.client_authentication: optional
3.2 jvm.options的配置:
初始堆内存和最大堆内存的配置,一般两者配置为相同,且不超过为主机内存的一半,且最大不超过32G。
4、systemd文件配置修改与启动:
Environment=ES_PATH_CONF=/etc/es-master,要在ExecStart之前。
环境变量配置后,修改文件/usr/share/elasticsearch/bin/elasticsearch-env,注释掉#source /etc/sysconfig/elasticsearch,不然会去读取/etc/elasticsearch;
文件末尾添加ES_TMPDIR=/tmp,设置其临时目录。
5、验证:
curl ip:9200/_cat -u user:password
三、es添加角色和用户。
查看角色:
curl es_ip:port/_xpack/security/role -u 用户名:密码
添加角色:
read_only:只读某些索引。
curl -H "Content-Type:application/json" -XPOST 'es_ip:port/_xpack/security/role/read_only' -d '{"cluster":["monitor","manage_ilm"],"indices":[{"names":["索引名1*","索引名2*","索引名3*"],"privileges":["read","read_cross_cluster","monitor","view_index_metadata"],"allow_restricted_indices":false}],"applications":[],"run_as":[],"metadata":{},"transient_metadata":{"enabled":true}}' -u 用户名:密码
logstash_write:配置logstash可以发送数据到es并建索引。
curl -H "Content-Type:application/json" -XPOST 'es_ip:port/_xpack/security/role/logstash_write' -d '{"cluster":["monitor","manage_index_templates"],"indices":[{"names":["logstash*","索引名1*","索引名2*","索引名3*"],"privileges":["write","create_index","read","manage_ilm","manage"],"field_security":{"grant":["*"]},"allow_restricted_indices":false}],"applications":[],"run_as":[],"metadata":{},"transient_metadata":{"enabled":true}}' -u 用户名:密码
查看所有用户:
curl es_ip:port/_xpack/security/user -u 用户名:密码
添加用户:
java_app:
curl -H "Content-Type:application/json" -XPOST 'es_ip:port/_xpack/security/user/java_app' -d '{"password":"java_app","roles":["kibana_user","read_only"]}' -u 用户名:密码
jdbc_logstash
curl -H "Content-Type:application/json" -XPOST 'es_ip:port/_xpack/security/user/jdbc_logstash' -d '{"password":"logstash","roles":["logstash_write","logstash_system","kibana_user","read_only"]}' -u 用户名:密码
查看全部索引:
curl es_ip:port/_cat/indices -u 用户名:密码
删除某个索引:
curl -XDELETE es_ip:port/索引名 -u 用户名:密码