一、ES集群规划:
关系型数据库(比如Mysql) | 非关系型数据库(Elasticsearch) | 非关系型数据库(Elasticsearch) |
---|---|---|
centos7 | hadoop103 | 192.168.148.3 |
centos7 | hadoop104 | 192.168.148.4 |
centos7 | hadoop105 | 192.168.148.5 |
二、集群环境搭建:
2.1.Docker部署ES-7.12集群:
第1步:.编写docker-compose文件:
version: '2.2'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.12.1
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data01:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- elastic
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.12.1
container_name: es02
environment:
- node.name=es02
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data02:/usr/share/elasticsearch/data
networks:
- elastic
es03:
image: docker.elastic.co/elasticsearch/elasticsearch:7.12.1
container_name: es03
environment:
- node.name=es03
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es02
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data03:/usr/share/elasticsearch/data
networks:
- elastic
volumes:
data01:
driver: local
data02:
driver: local
data03:
driver: local
networks:
elastic:
driver: bridge
第2步:执行docker-compose文件:
docker-compose up
2.2.直接搭建方式(基于ES-7.8.0):
第1步:下载ES
- 1.解压压缩包:
tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz -C /opt/module
- 2.将文件名更改成es-cluster:
mv elasticsearch-7.8.0 es-cluster
:
第2步:创建用户:
- 1.创建用户:Elasticsearch 因为安全问题,不允许 root 用户直接运行,所以要在每个节点中创建新用户,在 root 用户中创建新用户
useradd es #新增 es 用户
passwd es #为 es 用户设置密码
userdel -r es #如果错了,可以删除再加
chown -R es:es /opt/module/es-cluster #文件夹所有者
- 2.将软件分发到另外两台服务器上:
第3步:更改配置
- 1.配置目录:安装完毕后会生成很多文件,包括配置文件日志文件等等,下面几个是
最主要的配置文件路径
/opt/module/es-cluster/
# elasticsearch 安装目录/opt/module/es-cluster/config/elasticsearch.yml
#elasticsearch的配置文件/opt/module/es-cluster/config/jvm.options
#JVM相关的配置,内存大小等等/data/elk1/data
# 数据存放路径/data/elk1/logs
# 日志存放路径
- 2.创建用于存放数据与日志的目录:数据文件会随着系统的运行飞速增长,所以默认的日志文件与数据文件的路径不能满足我们的需求,需要手动创建日志与数据文件路径
mkdir -p /data/elk1/data
mkdir -p /data/elk1/logs
- 3.集群配置:
vim /opt/module/es-cluster/config/elasticsearch.yml
(yml文件有严格的语法要求,在配置的时候,一定要注意语法,这里容易出现错误)
# 加入如下配置
# #集群名称
cluster.name: cluster-es
# 节点名称,每个节点的名称不能重复
node.name: node-1
#ip 地址,每个节点的地址不能重复
network.host: hadoop103
#是不是有资格主节点
node.master: true
node.data: true
http.port: 9200
## head 插件需要这打开这两个配置
http.cors.allow-origin: "*"
http.cors.enabled: true
http.max_content_length: 200mb
##es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举 master
cluster.initial_master_nodes: ["node-1"]
##es7.x 之后新增的配置,节点发现
discovery.seed_hosts: ["192.168.148.3:9300","192.168.148.4:9300","192.168.148.5:9300"]
gateway.recover_after_nodes: 2
network.tcp.keep_alive: true
network.tcp.no_delay: true
transport.tcp.compress: true
##集群内同时启动的数据任务个数,默认是 2 个
cluster.routing.allocation.cluster_concurrent_rebalance: 16
##添加或删除节点及负载均衡时并发恢复的线程个数,默认 4 个
cluster.routing.allocation.node_concurrent_recoveries: 16
##初始化数据恢复时,并发恢复线程的个数,默认 4 个
cluster.routing.allocation.node_initial_primaries_recoveries: 16
# 加入如下配置
# #集群名称
cluster.name: cluster-es
# 节点名称,每个节点的名称不能重复
node.name: node-2
#ip 地址,每个节点的地址不能重复
network.host: hadoop104
#是不是有资格主节点
node.master: true
node.data: true
http.port: 9200
## head 插件需要这打开这两个配置
http.cors.allow-origin: "*"
http.cors.enabled: true
http.max_content_length: 200mb
##es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举 master
cluster.initial_master_nodes: ["node-1"]
##es7.x 之后新增的配置,节点发现
discovery.seed_hosts: ["192.168.148.3:9300","192.168.148.4:9300","192.168.148.5:9300"]
gateway.recover_after_nodes: 2
network.tcp.keep_alive: true
network.tcp.no_delay: true
transport.tcp.compress: true
##集群内同时启动的数据任务个数,默认是 2 个
cluster.routing.allocation.cluster_concurrent_rebalance: 16
##添加或删除节点及负载均衡时并发恢复的线程个数,默认 4 个
cluster.routing.allocation.node_concurrent_recoveries: 16
##初始化数据恢复时,并发恢复线程的个数,默认 4 个
cluster.routing.allocation.node_initial_primaries_recoveries: 16
# 加入如下配置
# #集群名称
cluster.name: cluster-es
# 节点名称,每个节点的名称不能重复
node.name: node-3
#ip 地址,每个节点的地址不能重复
network.host: hadoop105
#是不是有资格主节点
node.master: true
node.data: true
http.port: 9200
## head 插件需要这打开这两个配置
http.cors.allow-origin: "*"
http.cors.enabled: true
http.max_content_length: 200mb
##es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举 master
cluster.initial_master_nodes: ["node-1"]
##es7.x 之后新增的配置,节点发现
discovery.seed_hosts: ["192.168.148.3:9300","192.168.148.4:9300","192.168.148.5:9300"]
gateway.recover_after_nodes: 2
network.tcp.keep_alive: true
network.tcp.no_delay: true
transport.tcp.compress: true
##集群内同时启动的数据任务个数,默认是 2 个
cluster.routing.allocation.cluster_concurrent_rebalance: 16
##添加或删除节点及负载均衡时并发恢复的线程个数,默认 4 个
cluster.routing.allocation.node_concurrent_recoveries: 16
##初始化数据恢复时,并发恢复线程的个数,默认 4 个
cluster.routing.allocation.node_initial_primaries_recoveries: 16
- 三台机器不一样的
elasticsearch.yml
配置点如下
node.name: node-1 #192.168.148.3
node.name: node-2 #192.168.148.4
node.name: node-3 #192.168.148.5
network.host: 192.168.148.3 #192.168.148.3
network.host: 192.168.148.4 #192.168.148.4
network.host: 192.168.148.5 #192.168.148.5
- 4.JVM配置:
- 由于Elasticsearch是Java开发的,所以可以通过
/etc/elasticsearch/jvm.options
配置文件来设定JVM的相关设定。如果没有特殊需求按默认即可。 - 但是其中还是有两项最重要的-Xmx1g与-Xms1gJVM的最大最小内存。如果太小会导致Elasticsearch刚刚启动就立刻停止。太大会拖慢系统本身。
- 由于Elasticsearch是Java开发的,所以可以通过
vim /opt/module/es-cluster/config/jvm.options
-Xms1g 修改为 ===> -Xms2g
-Xmx1g 修改为 ===> -Xmx2g
第4步:修改配置
- 1.修改
/etc/sysctl.conf
:添加如下配置后并重新加载:sysctl -p
:
vm.max_map_count=655360
- 2.切换用户es后,切到es的安装目录后,启动服务:
./bin/elasticsearch
2.3."_cat"集群命令介绍:
GET /_cat/nodes #查看所有节点。集群中会用到
GET /_cat/health #查看es健康状况
GET /_cat/master #查看主节点
GET /_cat/indices #查看所有索引 ,等价于mysql数据库的show databases;