ElasticSearch基本概念
Node:运行单个ES实例的服务器.
Cluster:一个或多个节点构成集群
Index:索引是多个文档的集合
Document:Index里每条记录称为Document,若干文档构建一个Index
Type:一个Index可以定义一种或多种类型,将Document逻辑分组
Field:ES存储的最小单元
Shards:ES将Index分为若干份,每一份就是一个分片
Replicas:Index的一份或多份副本。
环境配置
组件名称 | ip | 内存 | cpu |
elk-es1 | 10.10.0.252 | 8G | 2 |
elk-es2 | 10.10.0.253 | 8G | 2 |
elk-es3 | 10.10.0.254 | 8G | 2 |
官网下载
下载地址:https://www.elastic.co/cn/downloads
安装
- jdk安装
- 下载
[root@elk-es1 ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.0-linux-x86_64.tar.gz
- 解压
[root@elk-es1~]# tar zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz -C /opt/
- 查看配置文件
[root@elk-es1 ~]# cd /opt/ [root@elk-es1 opt]# ll elasticsearch-7.8.0/ total 584 drwxr-xr-x 2 root root 4096 Jun 15 03:38 bin drwxr-xr-x 3 root root 4096 Jul 2 15:32 config drwxr-xr-x 9 root root 4096 Jun 15 03:38 jdk drwxr-xr-x 3 root root 4096 Jun 15 03:38 lib -rw-r--r-- 1 root root 13675 Jun 15 03:34 LICENSE.txt drwxr-xr-x 2 root root 4096 Jun 15 03:37 logs drwxr-xr-x 47 root root 4096 Jun 15 03:39 modules -rw-r--r-- 1 root root 544318 Jun 15 03:37 NOTICE.txt drwxr-xr-x 2 root root 4096 Jun 15 03:37 plugins -rw-r--r-- 1 root root 8165 Jun 15 03:34 README.asciidoc
- Elasticsearch7.8目录结构
- bin :脚本文件,包括 ES 启动 & 安装插件等等
config : elasticsearch.yml(ES 配置文件)、jvm.options(JVM 配置文件)、日志配置文件等等
JDK : 内置的 JDK,JAVA_VERSION="12.0.1"
lib : 类库
logs : 日志文件
modules : ES 所有模块,包括 X-pack 等
plugins : ES 已经安装的插件。默认没有插件
data : ES 启动的时候,会有该目录,用来存储文档数据。该目录可以设置
- 具体看看关键的 jvm.options JVM 配置文件,默认配置如下
[root@elk-es1 elasticsearch-7.8.0]# cd config/ [root@elk-es1 config]# cat jvm.options -Xms1g -Xmx1g
ES 默认安装后设置的堆内存是 1 GB,对于任何业务来说这个设置肯定是少了。那设置多少?博主设置成2g了。
推荐:如果足够的内存,也尽量不要 超过 32 GB。即每个节点内存分配不超过 32 GB。 因为它浪费了内存,降低了 CPU 的性能,还要让 GC 应对大内存。如果你想保证其安全可靠,设置堆内存为 31 GB 是一个安全的选择。
- 配置集群
[root@elk-es1 config]# pwd /opt/elasticsearch-7.8.0/config [root@elk-es1 config]# vim elasticsearch.yml cluster.name: www.centoscn.vip node.name: node-1 path.data: /opt/path/to/data path.logs: /opt/path/to/logs network.host: 10.10.0.252 http.port: 9200 discovery.seed_hosts: ["10.10.0.252", "10.10.0.253","10.10.0.254"] cluster.initial_master_nodes: ["10.10.0.252", "10.10.0.253"]
- 创建存储数据和日志目录,三个节点都创建
[root@elk-es1 config]# mkdir -p /opt/path/to/data [root@elk-es1 config]# mkdir -p /opt/path/to/logs
- 分发到其他两个节点
[root@elk-es1 opt]# scp -r elasticsearch-7.8.0 root@10.10.0.253:/opt/ [root@elk-es1 opt]# scp -r elasticsearch-7.8.0 root@10.10.0.254:/opt/
- 第二个节点配置文件修改
[root@elk-es2 config]# pwd /opt/elasticsearch-7.8.0/config [root@elk-es2 config]# vim elasticsearch.yml node.name: node-2 network.host: 10.10.0.253 cluster.initial_master_nodes: ["10.10.0.253", "10.10.0.254"]
- 第三个节点修改
[root@elk-es3 config]# pwd /opt/elasticsearch-7.8.0/config [root@elk-es3 config]# vim elasticsearch.yml node.name: node-3 network.host: 10.10.0.254 cluster.initial_master_nodes: ["10.10.0.254", "10.10.0.252"]
启动 Elasticsearch
- 添加用户组、用户,设置密码,三台一起操作
[root@elk-es1 bin]# groupadd elasticsearch [root@elk-es1 bin]# useradd elasticsearch -g elasticsearch [root@elk-es1 bin]# passwd elasticsearch Changing password for user elasticsearch. New password: Retype new password: passwd: all authentication tokens updated successfully. [root@elk-es1 bin]# chown -R elasticsearch:elasticsearch /opt/*
- 添加参数(最后面)然后重启系统,三台都执行
[root@elk-es1 bin]# vim /etc/security/limits.conf * soft nofile 65535 * hard nofile 65535
- 再执行这个,三台一起
[root@elk-es1 bin]# sysctl -w vm.max_map_count=262144 vm.max_map_count = 262144
- 启动服务
[root@elk-es1 bin]# su - elasticsearch [elasticsearch@elk-es1 ~]$ cd /opt/elasticsearch-7.8.0/ [elasticsearch@elk-es1 elasticsearch-7.8.0]$ nohup ./bin/elasticsearch &
- 启动第二和第三台
[root@elk-es2 config]# su - elasticsearch [elasticsearch@elk-es2 ~]$ cd /opt/elasticsearch-7.8.0/ [elasticsearch@elk-es2 elasticsearch-7.8.0]$ nohup ./bin/elasticsearch & [root@elk-es3 config]# su - elasticsearch [elasticsearch@elk-es3 ~]$ cd /opt/elasticsearch-7.8.0/ [elasticsearch@elk-es3 elasticsearch-7.8.0]$ nohup ./bin/elasticsearch &
集群状态
- 集群状态显示“Green”,表示集群健康。还有其他“Yellow和Red”两种状态
[elasticsearch@elk-es1 elasticsearch-7.8.0]$ curl -X GET "10.10.0.252:9200/_cat/health?v" epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 1593677867 08:17:47 www.centoscn.vip green 3 3 0 0 0 0 0 0 - 100.0%
- 查看集群节点-----heap.percent是堆内存的百分比
[elasticsearch@elk-es1 ~]$ curl -X GET "10.10.0.252:9200/_cat/nodes?v" ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name 10.10.0.253 10 57 3 0.02 0.08 0.07 dilmrt - node-2 10.10.0.254 7 57 4 0.02 0.10 0.09 dilmrt * node-3 10.10.0.252 12 57 3 0.01 0.15 0.13 dilmrt - node-1
- 列出索引
[elasticsearch@elk-es1 ~]$ curl -X GET "10.10.0.252:9200/_cat/indices?v" health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
# 当下没有创建索引,所以默认显示上述结果。
继续阅读
- 我的QQ
- QQ扫一扫
-
- 我的头条
- 头条扫一扫
-
评论