最近線上的ES集群埋點數(shù)據(jù)量暴漲,機器的內存磁盤空間眼看就要炸了。但這部分數(shù)據(jù)又是冷數(shù)據(jù),現(xiàn)時不需要查詢,但又不能直接delete,需保留日后數(shù)據(jù)分析。由于前期急于上線,業(yè)務代碼沒有合理分配索引按月切割,全年數(shù)據(jù)丟進單個索引,導致單索引數(shù)據(jù)暴漲到100G+
為解決磁盤空間的瓶頸,針對不常用的分片數(shù)據(jù),做快照冷存儲。
應用場景:
三節(jié)點的ES集群:192.168.85.39 ,192.168.85.36,192.168.85.33
找一臺有磁盤空間的服務器,搭建NFS,用于共享目錄掛載。已192.168.85.63為例
應用場景:ES集群三節(jié)點 192.168.85.39,192.168.85.33,192.168.85.36
NFS存儲服務器:192.168.5.63
一.搭建NFS共享存儲服務器 (5.63上操作)
1.安裝 nfs服務
yum install -y nfs-utils
2. 開機啟動
systemctl enable rpcbind.service
systemctl enable nfs-server.service
3. 分別啟動rpcbind和nfs服務:
systemctl start rpcbind.service
systemctl start nfs-server.service
4.firewalld 防火墻針對es節(jié)點內網(wǎng)ip開放NFS服務監(jiān)聽端口:
111 udp端口 20048 tcp端口 2049 tcp 和 udp全開
5.創(chuàng)建本地數(shù)據(jù)共享目錄 并設置權限
mkdir /data/db/elasticsearch/backup
chmod 777 /data/db/elasticsearch/backup
chown -R elasticsearch:elasticsearch /data/db/elasticsearch/backup
6.配置NFS目錄訪問權限
vim etc/exports
/data/db/elasticsearch/backup 192.168.85.39(rw,sync,all_squash) 192.168.85.33(rw,sync,all_squash) 192.168.85.36(rw,sync,all_squash)
exports -r //生效
exports -s //查看
7.es節(jié)點上安裝客戶端(85.39 85.33 85.36 上操作)
yum -y install showmount
開啟服務:
systemctl enable rpcbind.service
systemctl start rpcbind.service
8.創(chuàng)建掛載目錄(85.39 85.33 85.36 上分別操作)
mkdir /mnt/elasticsearch
chmod 777 elasticsearch
掛載共享目錄到本地
mount -t nfs 192.168.5.63:/data/db/elasticsearch/backup /mnt/elasticsearch
df -h //查看確認是否成功掛載
二.創(chuàng)建快照倉庫
curl -XPUT http://192.168.85.39:9002/_snapshot/backup -d'
{
"type": "fs",
"settings": {
"location": "/mnt/elasticsearch/backup",
"compress": true,
"max_snapshot_bytes_per_sec" : "50mb",
"max_restore_bytes_per_sec" : "50mb"
}
}'
備注說明:
1.可在es任一節(jié)點操作
2.backup: 指定倉庫名稱為backup ,生成的備份文件存放路徑為/mnt/elasticsearch/backup
3.max_snapshot_bytes_per_sec,max_restore_bytes_per_sec 限定備份和恢復的數(shù)據(jù)字節(jié)內容大小為50mb,
為了防止磁盤IO過高。數(shù)值越大,備份恢復速度越快。50mb為推薦值,IO性能高的機器可不限制
curl -XPUT http://192.168.85.39:9002/_snapshot/backup -d '
{
"type": "fs",
"settings": {
"location": "/mnt/elasticsearch/backup",
"compress": true
}
}'
三.創(chuàng)建快照備份
1.針對全索引快照備份
curl -XPUT 192.168.85.39:9002/_snapshot/backup/snapshot_all?pretty
備注說明:
1.指定備份到倉庫backup
2.快照名稱為 snapshot_all
2.針對指定某個單獨索引快照備份(為了區(qū)分不同索引備份目錄,建議倉庫用索引名稱命名)
單獨快照備份user_event_201810這個索引
2.1先針對索引創(chuàng)建倉庫
curl -XPUT http://192.168.85.39:9002/_snapshot/user_event_201810 -d'
{
"type": "fs",
"settings": {
"location": "/mnt/elasticsearch/user_event_201810",
"compress": true,
"max_snapshot_bytes_per_sec" : "50mb",
"max_restore_bytes_per_sec" : "50mb"
}
}'
2.2 快照備份索引user_event_201810操作
curl -XPUT http://192.168.85.39:9002/_snapshot/user_event_201810/user_event_201810?wait_for_completion=true -d '
{
"indices":"user_event_201810",
"ignore_unavailable": "true",
"include_global_state": false
}'
備注說明:
1.創(chuàng)建的倉庫名為user_event_201810
2.存放的文件目錄為/mnt/elasticsearch/user_event_201810
3.indices:指定索引源為user_event_201810
4.增加?wait_for_completion=true參數(shù)是為了執(zhí)行完成返回結果狀態(tài)
四.恢復快照備份數(shù)據(jù)到es集群
1.針對全索引快照備份的恢復操作
curl -XPOST http://192.168.85.39:9200/_snapshot/backup/snapshot_all/_restore
備注說明:
1.指定倉庫名稱backup
2.指定快照備份名稱snapshot_all
2.針對某個指定索引的快照備份恢復操作
針對索引user_event_201810快照恢復
curl -XPOST http://192.168.85.39:9002/_snapshot/user_event_201810/user_event_201810/_restore
備注說明:
1.指定倉庫名稱user_event_201810
2.指定快照備份名稱user_event_201810
五:輔助操作命令
1.查看已存在倉庫
curl 192.168.85.39:9002/_cat/repositories?
2.查看已存在快照
curl -XGET http://192.168.85.39:9002/_snapshot? //查看全部
curl -XGET http://192.168.85.39:9002/_snapshot/user_event_201810/user_event_201810//查看指定索引
3.刪除快照
curl -XDELETE http://192.168.85.39:9002/_snapshot/user_event_201810/user_event_201810
//刪除快照user_event_201810
4.刪除倉庫
curl -XDELETE http://192.168.85.39:9002/_snapshot/user_event_201810
//刪除倉庫user_event_201810
elasticsearch其中一節(jié)點配置文件
cluster.name: my-application1
node.name: node-3
path.data: /data/db/elasticsearch
path.logs: /data/log/elasticsearch/logs
path.repo: ["/mnt/elasticsearch"]
network.host: 192.168.85.33
http.port: 9002
transport.tcp.port: 9102
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["192.168.85.39:9102","192.168.85.36:9102","192.168.85.33:9102"]
discovery.zen.minimum_master_nodes: 2
indices.query.bool.max_clause_count: 10240
http.cors.enabled: true
http.cors.allow-origin: "*"
NFS
mount -t nfs 192.168.5.63:/data/db/elasticsearch/backup /mnt/elasticsearch
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
網(wǎng)站標題:elasticsearch索引數(shù)據(jù)快照備份和恢復-創(chuàng)新互聯(lián)
文章分享:http://muchs.cn/article24/dphdje.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供微信公眾號、網(wǎng)站設計、做網(wǎng)站、品牌網(wǎng)站建設、營銷型網(wǎng)站建設、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內容