栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Elasticsearch(二)

Elasticsearch(二)

Elasticsearch 二
  • 下载 Elasticsearc
  • Linux部署
    • 单机部署
    • 集群部署
    • Windows集群
  • 安装 Kibana
  • Elasticsearch数据备份与恢复
    • 安装备份& 恢复工具
      • 数据备份脚本
      • 数据恢复脚本

下载 Elasticsearc
  • https://www.elastic.co/cn/downloads/past-releases#elasticsearch
Linux部署
  • 创建用户(ES不允许 root用户直接运行
    $ groupadd es; useradd -g es es;
    $ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.0-linux-x86_64.tar.gz;
    $ tar -xvf elasticsearch-7.8.0-linux-x86_64.tar.gz;
    $ chown es.es elasticsearch-7.8.0 -R
单机部署

$ vim config/elasticsearch.yml;

cluster.name: elasticsearch
node.name: node-1
path.data: /path/to/data
path.logs: /path/to/logs
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: ["node-1"]

集群部署

$ vim config/elasticsearch.yml;

# 集群名称
cluster.name: cluster-es
# 节点名称, 每个节点的名称不能重复
node.name: node-1
path.data: /path/to/data
path.logs: /path/to/logs
# ip地址, 每个节点的地址不能重复
network.host: linux1
# 是不是有资格主节点
node.master: true
node.data: true
# HTTP API端口
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: ["linux1:9300","linux2:9300","linux3:9300"]
gateway.recover_after_nodes: 2
network.tcp.keep_alive: true
network.tcp.no_delay: true
# 集群间组件 TCP监听端口
transport.tcp.port: 9300
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

$ vim /etc/security/limits.conf

# 每个进程可以打开文件数的限制
es soft nofile 65536
es hard nofile 65536

$ vim /etc/security/limits.d/20-nproc.conf

# 每个进程可以打开文件数的限制
es soft nofile 65536
es hard nofile 65536
# 操作系统级别对每个用户创建进程数的限制
* hard nproc 4096

$ vim /etc/sysctl.conf

# 一个进程可以拥有的 VMA(虚拟内存区域)的数量, 默认值为 65536
vm.max_map_count=655360

  • 重新加载:
    $ sysctl -p;

  • 启动 ES

$ bin/elasticsearch # 启动
$ bin/elasticsearch -d # 后台启动

Windows集群
# 节点 1
cluster.name: my-elasticsearch
# 节点名称, 集群内要唯一
node.name: node-1
node.master: true
node.data: true
# ip地址
network.host: localhost
# HTTP API端口
http.port: 9201
# 集群间组件 TCP监听端口
transport.tcp.port: 9301
#discovery.seed_hosts: ["localhost:9301", "localhost:9302","localhost:9303"]
#discovery.zen.fd.ping_timeout: 1m
#discovery.zen.fd.ping_retries: 5
# 集群内的可以被选为主节点的节点列表
#cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
# 跨域配置
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"

# 节点 2
cluster.name: my-elasticsearch
# 节点名称, 集群内要唯一
node.name: node-2
node.master: true
node.data: true
# ip地址
network.host: localhost
# HTTP API端口
http.port: 9202
# 集群间组件 TCP监听端口
transport.tcp.port: 9302
# discovery是 es用于指定 master节点的模块; master节点是不用加的
discovery.seed_hosts: ["localhost:9301"]
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
# 集群内的可以被选为主节点的节点列表
#cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
# 跨域配置
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"

# 节点 3
cluster.name: my-elasticsearch
# 节点名称, 集群内要唯一
node.name: node-3
node.master: true
node.data: true
# ip地址
network.host: localhost
# HTTP API端口
http.port: 9203
# 集群间组件 TCP监听端口
transport.tcp.port: 9303
# 候选主节点的地址, 在开启服务后可以被选为主节点
discovery.seed_hosts: ["localhost:9301", "localhost:9302"]
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
# 集群内的可以被选为主节点的节点列表
#cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
# 跨域配置
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"

  • 启动节点
    $ bin/elasticsearch.bat

  • 查看集群节点状态:
    http://localhost:9201/_cluster/health

安装 Kibana
  • Kibana是 ES的节点监控& 数据可视化工具
1. Kibana下载: 
https://artifacts.elastic.co/downloads/kibana/kibana-7.8.0-windows-x86_64.zip

2. 解压后修改 config/kibana.yml文件
# 默认端口
server.port: 5601
# ES 服务器的地址
elasticsearch.hosts: ["http://localhost:9200"]
# 索引名
kibana.index: ".kibana"
# 支持中文
i18n.locale: "zh-CN"

3. Windows环境下执行 
bin/kibana.bat文件

4. 通过浏览器访问
http://localhost:5601

Elasticsearch数据备份与恢复 安装备份& 恢复工具
  1. 安装 node
    $ curl --silent --location https://rpm.nodesource.com/setup_12.x | sudo bash -
    $ yum install -y nodejs;
    $ node --version;

  2. 设置淘宝镜像
    $ npm config set registry http://registry.npm.taobao.org

  3. 安装 elasticdump
    $ npm install elasticdump -g;

数据备份脚本

$ mkdir /home/es/backup/data -p;
$ touch /home/es/backup/backup-data.sh;
$ chmod 755 /home/es/backup/backup-data.sh;

- 编辑脚本
$ vim backup-data.sh
#!/bin/bash
index=${1}
address=${2}
echo 'begin backup index: '${index}' from '${address}
elasticdump --input=http://${address}:9200/${index} --output=/home/es/backup/data/${index}_alias.json --type=alias &> /dev/null
elasticdump --input=http://${address}:9200/${index} --output=/home/es/backup/data/${index}_analyzer.json --type=analyzer &> /dev/null
elasticdump --input=http://${address}:9200/${index} --output=/home/es/backup/data/${index}_data.json --type=data &> /dev/null
elasticdump --input=http://${address}:9200/${index} --output=/home/es/backup/data/${index}_template.json --type=template &> /dev/null
echo "end backup."

- 开始备份数据(参数1:索引名称, 参数2:目标 ES地址
$ ./backup-data.sh article 127.0.0.1

数据恢复脚本

$ touch /home/es/backup/recovery-data.sh;
$ chmod 755 /home/es/backup/recovery-data.sh;

$ vim recovery-data.sh
#!/bin/bash
index=${1}
address=${2}
echo 'begin recovery index: '${index}' from '${address}
elasticdump --input=/home/es/backup/data/${index}_alias.json --output=http://${address}:9200/${index} --type=alias &> /dev/null
elasticdump --input=/home/es/backup/data/${index}_analyzer.json --output=http://${address}:9200/${index} --type=analyzer &> /dev/null
elasticdump --input=/home/es/backup/data/${index}_data.json --output=http://${address}:9200/${index} --type=data &> /dev/null
elasticdump --input=/home/es/backup/data/${index}_template.json --output=http://${address}:9200/${index} --type=template &> /dev/null
echo "end recovery."

- 开始恢复数据(参数1:索引名称, 参数2:目标 ES地址
$ ./recovery-data.sh article 127.0.0.1

  • 配置环境变量
    $ vim /etc/profile
    export ELASTIC_DUMP=/usr/lib/node_modules/elasticdump
    export PATH= P A T H : PATH: PATH:ELASTIC_DUMP/bin

使生效系统变量:
$ source /etc/profile;

如果您觉得有帮助,欢迎点赞哦 ~ 谢谢!!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/688529.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号