elasticsearch 6.3.2 集群配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wanglei_storage/article/details/82218940

一、约定俗成

elasticsearch 所有关于数据的路径都位于 /data/elasticsearch 下面,因此,除了主程序以外,所有的es相关的数据都应该位于该路径下面,包括但不限于:

es 数据                      # /data/elasticsearch/es_data
es 程序日志                   # /data/elasticsearch/es_logs/elasticsearch.log
es gc 日志                   # /data/elasticsearch/es_logs/gc.log
es heap dump 路径            # /data/elasticsearch/es_heap_dump
es java io 临时路径           # /data/elasticsearch/es_java_io

一、jvm.options 参数配置

1、内存配置

-Xms4g
-Xmx4g

2、java.io.tmpdir

-Djava.io.tmpdir=/data/elasticsearch/es_java_io

引用说明:

最近客户现场的技术支持接连反馈了一个问题:导入数据的时候,上传的excel会在服务器上生成一个临时文件,而这个临时文件都在 tomcat 的安装目录下,如果上传次数比较多的话,就会导致tomcat安装目录下有多个临时的excel文件,很不合理也不美观。
接到这个问题,第一反应是 java.io.tmpdir 这个系统配置没指定好,因为做上传的时候,是通过: System.getProperty(“java.io.tmpdir”);
这种方式来获取临时目录,然后把文件放到临时目录里去的,按说这些临时文件都应该在 tomcat 安装目录下的 temp 文件夹里,因为这个是tomcat的临时目录,但现在却没有,所以怀疑是 java.io.tmpdir 这个系统变量没指定好。

3、jvm heap dump path

-XX:HeapDumpPath=/data/elasticsearch/es_heap_dump

3、gc log path

8:-Xloggc:/data/elasticsearch/es_logs/gc.log
9-:-Xlog:gc*,gc+age=trace,safepoint:file=/data/elasticsearch/es_logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m

二、log4j2.properties 参数配置

https://www.elastic.co/guide/en/elasticsearch/reference/6.3/logging.html


三、elasticsearch.yml 参数配置

path.data: /data/elasticsearch/es_data           # elasticsearch 存放数据的路径
path.logs: /data/elasticsearch/es_logs           # elasticsearch 存放日志的路径

cluster.name: es_online_cluster                  # elasticsearch 集群名称

node.name: ${HOSTNAME}                           # elasticsearch 节点名称,也可以是变量 ${HOSTNAME}
node.attr.rack: r1                               # 节点服务器所在的机柜信息,此配置可不设
node.master: true                                # 定义该节点是否有资格被选举成主节点,默认是true,es是默认集群中的第一台机器为master,如果这台机器挂了就会重新选举master
node.data: true                                  # 允许该节点存储数据(默认开启)

network.host: ip_addr                            # elasticsearch 监听地址(默认为0.0.0.0)

discovery.zen.ping.unicast.hosts:["host1:port", "host2:port", "host3:port"]    # elasticsearch 默认实现单播,在单播配置下,节点向指定的主机发送单播请求
discovery.zen.minimum_master_nodes: 2            # 此设置应该始终被配置为 master 候选节点的法定个数(大多数个)。法定个数就是 ( master 候选节点个数 / 2) + 1 。

bootstrap.memory_lock: true                      # 设置为true来锁住内存。因为内存交换到磁盘对服务器性能来说是致命的,当jvm开始swapping时es的效率会降低,所以要保证它不swap

script.groovy.sandbox.enabled: false             # 该配置只有在安装 groovy 的插件之后才可以生效。否则es会报错

action.auto_create_index: false                  # 如果你想禁止自动创建索引,你可以通过在 elasticsearch.yml 的每个节点下添加下面的配置(注:logstash 会使用事件中的时间戳来生成索引名,自动生成)
action.destructive_requires_name: true           # 这个设置使删除只限于特定名称指向的数据,而不允许通过指定 _all 或通配符来删除指定索引库。你同样可以通过 Cluster State API 动态的更新这个设置

关于Discovery settings

discovery.zen.ping.unicast.hosts:[“host1:port”, “host2:port”, “host3:port”] # elasticsearch 默认实现单播,在单播配置下,节点向指定的主机发送单播请求

Elasticsearch将绑定到可用的环回地址,并将扫描端口9300到9305以尝试连接到运行在同一台服务器上的其他节点。 #这提供了自动集群体验,而无需进行任何配置。数组设置或逗号分隔的设置。每个值的形式应该是host:port或host #(如果没有设置,port默认设置会transport.profiles.default.port 回落到transport.tcp.port)

补充:多播配置下,节点向集群发送多播请求,其他节点收到请求后会做出响应,但是组播会将所有当前网络中启动的节点都加入到集群中,强烈不推荐
discovery.zen.ping.multicast.group:224.2.2.4 组地址
discovery.zen.ping.multicast.port:54328 端口
discovery.zen.ping.multicast.ttl:3 广播消息ttl
discovery.zen.ping.multicast.address:null绑定的地址,null表示绑定所有可用的网络接口
discovery.zen.ping.multicast.enabled:true 多播自动发现禁用开关

关于内存错误

memory locking requested for elasticsearch process but memory is not locked 这个报错说 elasticsearch 内存锁定失败

如果要开启该参数,则配置:
vim /etc/security/limit.conf

tracker soft memlock unlimited
tracker hard memlock unlimited

关于 groovy 脚本

通过设置集群中的所有节点的 elasticsearch.yml 文件来禁用动态 Groovy 脚本,防止动态 Groovy 脚本作为请求的一部分接受,或者从特殊的 .scripts 索引中被检索。当然,你仍然可以使用存储在每个节点的 config/scripts/ 目录下的 Groovy 脚本。


四、三台es集群配置

elasticsearch-1

cluster.name: es_online_cluster
node.name: ${HOSTNAME}
node.data: true
node.master: true
path.data: /data/elasticsearch/es_data
path.logs: /data/elasticsearch/es_logs
bootstrap.memory_lock: true
network.host: 10.81.90.235
discovery.zen.ping.unicast.hosts: ["10.81.90.235:9300", "10.81.160.31:9300", "10.81.71.23:9300"]
discovery.zen.minimum_master_nodes: 2
action.destructive_requires_name: true

elasticsearch-2

cluster.name: es_online_cluster
node.name: ${HOSTNAME}
node.data: true
node.master: true
path.data: /data/elasticsearch/es_data
path.logs: /data/elasticsearch/es_logs
bootstrap.memory_lock: true
network.host: 10.81.160.31
discovery.zen.ping.unicast.hosts: ["10.81.90.235:9300", "10.81.160.31:9300", "10.81.71.23:9300"]
discovery.zen.minimum_master_nodes: 2
action.destructive_requires_name: true

elasticsearch-3

cluster.name: es_online_cluster
node.name: ${HOSTNAME}
node.data: true
node.master: true
path.data: /data/elasticsearch/es_data
path.logs: /data/elasticsearch/es_logs
bootstrap.memory_lock: true
network.host: 10.81.71.23
discovery.zen.ping.unicast.hosts: ["10.81.90.235:9300", "10.81.160.31:9300", "10.81.71.23:9300"]
discovery.zen.minimum_master_nodes: 2
action.destructive_requires_name: true

五、启动 elasticsearch 节点

node1: /usr/local/elasticsearch-6.3.2/bin/elasticsearch -d
node2: /usr/local/elasticsearch-6.3.2/bin/elasticsearch -d
node3: /usr/local/elasticsearch-6.3.2/bin/elasticsearch -d

六、查看集群状态

1、查看集群启动日志
观察三台服务器的 /data/elasticsearch/es_logs/es_online_cluster.log 日志,看是否有报错

2、查看集群状态
下面是es默认自带的命令

=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates

例如:查看节点状态
curl http://xxx.xxx.com/_cat/nodes?v

ip           heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
10.81.90.235            6          68   0    0.00    0.01     0.05 mdi       -      es-online-1
10.81.160.31            6          65   0    0.00    0.01     0.05 mdi       -      es-online-2
10.81.71.23             8          65   0    0.00    0.01     0.03 mdi       *      es-online-3

例如:查看集群状态
curl http://xxx.xxx.com/_cluster/health?pretty

{
  "cluster_name" : "es_online_cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 3,
  "number_of_data_nodes" : 3,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}

猜你喜欢

转载自blog.csdn.net/wanglei_storage/article/details/82218940