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資料備份與恢復
安裝備份& 恢復工具
-
安裝 node
$ curl --silent --location https://rpm.nodesource.com/setup_12.x | sudo bash -
$ yum install -y nodejs;
$ node --version; -
設定淘寶鏡像
$ npm config set registry http://registry.npm.taobao.org -
安裝 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;
如果您覺得有幫助,歡迎點贊哦 ~ 謝謝!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/394192.html
標籤:其他
