2. ElasticSearch 各种安装

2.1 单节点安装

首先打开ES官网,找到Elasticsearch:

将下载的文件解压,解压后的目录含义如下:

目录 含义
modeules 依赖模块目录
lib 第三方依赖库
logs 输出日志目录
plugins 插件目录
bin 可执行文件目录
config 配置文件目录
data 数据存储目录

配置文件 elasticsearch.yml

#ES集群名称,同一个集群内的所有节点集群名称必须保持一致
cluster.name: ES-Cluster

#ES集群内的节点名称,同一个集群内的节点名称要具备唯一性
node.name: ES-master-01

#允许节点是否可以成为一个master节点,ES是默认集群中的第一台机器成为master,如果这台机器停止就会重新选举
node.master: true

#允许该节点存储索引数据(默认开启)
node.data: true

#数据存储路径(path可以指定多个存储位置,分散存储,有助于性能提升)
#目录还要对elasticsearch的运行用户有写入权限
path.data: /usr/local/elasticsearch-cluster/elasticsearch-a/data
path.logs: /usr/local/elasticsearch-cluster/elasticsearch-a/logs

#在ES运行起来后锁定ES所能使用的堆内存大小,锁定内存大小一般为可用内存的一半左右;锁定内存后就不会使用交换分区
#如果不打开此项,当系统物理内存空间不足,ES将使用交换分区,ES如果使用交换分区,那么ES的性能将会变得很差
bootstrap.memory_lock: true

#es绑定地址,支持IPv4及IPv6,默认绑定127.0.0.1;es的HTTP端口和集群通信端口就会监听在此地址上
network.host: 192.168.3.21

#是否启用tcp无延迟,true为启用tcp不延迟,默认为false启用tcp延迟
network.tcp.no_delay: true
#是否启用TCP保持活动状态,默认为true
network.tcp.keep_alive: true
#是否应该重复使用地址。默认true,在Windows机器上默认为false
network.tcp.reuse_address: true
#tcp发送缓冲区大小,默认不设置
network.tcp.send_buffer_size: 128mb
#tcp接收缓冲区大小,默认不设置
network.tcp.receive_buffer_size: 128mb

#设置集群节点通信的TCP端口,默认是9300
transport.tcp.port: 9301
#设置是否压缩TCP传输时的数据,默认为false
transport.tcp.compress: true
#设置http请求内容的最大容量,默认是100mb
http.max_content_length: 200mb

#是否开启跨域访问
http.cors.enabled: true
#开启跨域访问后的地址限制,*表示无限制
http.cors.allow-origin: "*"
#定义ES对外调用的http端口,默认是9200
http.port: 9201

#Elasticsearch7.x新增参数,写入候选主节点的设备地址,来开启服务时就可以被选为主节点,由discovery.zen.ping.unicast.hosts:参数改变而来
discovery.seed_hosts: ["192.168.3.21:9301", "192.168.3.22:9301","192.168.3.23:9301"]
#Elasticsearch7新增参数,写入候选主节点的设备地址,来开启服务时就可以被选为主节点
cluster.initial_master_nodes: ["192.168.3.21:9301", "192.168.3.22:9301","192.168.3.23:9301"]
#Elasticsearch7新增参数,设置每个节点在选中的主节点的检查之间等待的时间。默认为1秒
cluster.fault_detection.leader_check.interval: 2s 
#Elasticsearch7新增参数,启动后30秒内,如果集群未形成,那么将会记录一条警告信息,警告信息未master not fount开始,默认为10秒
discovery.cluster_formation_warning_timeout: 30s 
#Elasticsearch7新增参数,节点发送请求加入集群后,在认为请求失败后,再次发送请求的等待时间,默认为60秒
cluster.join.timeout: 30s
#Elasticsearch7新增参数,设置主节点等待每个集群状态完全更新后发布到所有节点的时间,默认为30秒
cluster.publish.timeout: 90s 
#集群内同时启动的数据任务个数,默认是2个
cluster.routing.allocation.cluster_concurrent_rebalance: 32
#添加或删除节点及负载均衡时并发恢复的线程个数,默认4个
cluster.routing.allocation.node_concurrent_recoveries: 32
#初始化数据恢复时,并发恢复线程的个数,默认4个
cluster.routing.allocation.node_initial_primaries_recoveries: 32

# 开启xpack安全验证
xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
# 证书配置
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12

启动方式

  1. ./bin/elasticsearch (非守护进程)
  2. ./bin/elasticsearch -d (守护进程)

默认监听端口 9200,启动后浏览器直接输入localhost:9200 可查看节点信息

{
  "name" : "node-1",
  "cluster_name" : "zyc-es-cluster",
  "cluster_uuid" : "i4_AiVlXQB6j4vEOG8T_ug",
  "version" : {
    "number" : "7.4.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "22e1767283e61a198cb4db791ea66e3f11ab9910",
    "build_date" : "2019-09-27T08:36:48.569419Z",
    "build_snapshot" : false,
    "lucene_version" : "8.2.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

节点的名字以及集群(默认是 elasticsearch)的名字,我们都可以自定义配置。

打开 config/elasticsearch.yml 文件,可以配置集群名称以及节点名称。配置方式如下:

cluster.name: zyc-es-cluster
node.name: node-1

Es 支持矩阵:

2.2 HEAD插件安装

Elasticsearch-head 插件,可以通过可视化的方式查看集群信息。

2.2.1 浏览器插件安装

Chrome需要在APP Store搜素Elasticsearch-head,点击安装,但是需要FQ。

2.2.2 源码安装

github上一个开源项目

  • git clone git://github.com/mobz/elasticsearch-head.git
  • cd elasticsearch-head
  • npm install
  • npm run start

启动后浏览器直接访问 “http://localhost:9100

注意,此时看不到集群数据。原因在于这里通过跨域的方式请求集群数据的,默认情况下,集群不支持跨域,所以这里就看不到集群数据。

解决办法如下,修改 es 的 config/elasticsearch.yml 配置文件,添加如下内容,使之支持跨域:

http.cors.enabled: true
http.cors.allow-origin: "*"

PS:默认状况下,ES 只容许本机访问,若是须要远程访问,能够修改 Elastic 安装目录的config/elasticsearch.yml文件,去掉network.host的注释,将它的值改为0.0.0.0,让任何人均可以访问(线上环境别这么设置哦),而后从新启动 ES。固然,也能够在这里修改集群和节点名称。

配置完成后,重启 es,此时 head 上就有数据了。

2.3 分布式安装

2.3.1 伪集群

一台机器上部署多个实例组装集群,一主二从

配置步骤
分别解压3个es包,修改config/elasticsearch.yml

  • master机器
cluster.name zyc_cluster
node.name: node-1
# 主节点
node.master: true
# 数据节点
node.data: true
network.host: 0.0.0.0
http.port: 9200
transport.port: 9300
discovery.seed_hosts:["192.168.19.10:9300","192.168.19.10:9301","192.168.19.10:9302"]
cluster.initial_master_nodes: ["node-1"] # 确保当前节点是主节点
http.cors.enabled: true
http.cors.allow-origin: "*"
path.logs: /opt/es/elasticsearch-7.4.0/logs
path.data: /opt/es/elasticsearch-7.4.0/data
  • slave1
cluster.name: zyc_cluster
node.name: node-2

node.master: false
node.data: true
network.host: 0.0.0.0
http.port: 9201
transport.port: 9301
discovery.seed_hosts: ["192.168.19.10:9300", "192.168.19.10:9301","192.168.19.10:9302"]
cluster.initial_master_nodes: ["node-1", "node-2","node3"]
http.cors.enabled: true
http.cors.allow-origin: "*"
path.logs: /opt/es-slave1/elasticsearch-7.4.0/logs
path.data: /opt/es-slave1/elasticsearch-7.4.0/data
  • slave2
cluster.name: zyc_cluster
node.name: node-3

node.master: false
node.data: true
network.host: 0.0.0.0
http.port: 9202
transport.port: 9302
discovery.seed_hosts: ["192.168.19.10:9300", "192.168.19.10:9301","192.168.19.10:9302"]
cluster.initial_master_nodes: ["node-1", "node-2","node3"]
http.cors.enabled: true
http.cors.allow-origin: "*"
path.logs: /opt/es-slave2/elasticsearch-7.4.0/logs
path.data: /opt/es-slave2/elasticsearch-7.4.0/data

若报错说找不到主节点,可以先启动主节点,等主节点集群建立后,再启动从节点,观察从节点日志输出,确保从节点加入集群。
可以先分别启动查看状态,待配置无误后再用脚本启动

startup.sh

#!/bin/bash
/usr/bin/su - eszyc -c '/opt/es/elasticsearch-7.4.0/bin/elasticsearch -p /tmp/elasticsearch_9200_pid -d'
/usr/bin/su - eszyc -c '/opt/es-slave1/elasticsearch-7.4.0/bin/elasticsearch -p /tmp/elasticsearch_9201_pid -d'
/usr/bin/su - eszyc -c '/opt/es-slave2/elasticsearch-7.4.0/bin/elasticsearch -p /tmp/elasticsearch_9202_pid -d'

shutdown.sh

#!/bin/bash
kill -9 `ps -u eszyc|awk '{print $1}'`

2.3.2 集群

es分别多台机器安装,组装集群,核心cluster.name相同,ES是一个去中心化的中间件,因此不需要特意设置master

2.4 安装kibana

kibanba时elastic旗下的一款产品,下载地址:https://www.elastic.co/cn/downloads/kibana(下载速度慢)
推荐使用国内的镜像(https://mirrors.huaweicloud.com/home),选择合适的版本下载。
修改kibana配置文件config/kibana.yml

server.port: 5601
server.host: 192.168.19.10
i18n.locale: "zh-CN"
elasticsearch.hosts: ["http://192.168.19.10:9200"]

启动kiana: ./bin/kibana &

默认访问地址:localhost:5601

posted on 2021-11-02 16:20  --工具人  阅读(313)  评论(0编辑  收藏  举报