首页 > 其他 > 详细

[elk]elasticsearch dashboard+保留10天内索引+导入导出备份

时间:2017-12-12 20:15:45      阅读:391      评论:0      收藏:0      [点我收藏+]

es dashboard

有两款

先修改es的配置文件: elasticsearch.yml追加
http.cors.enabled: true
http.cors.allow-origin: "*"


docker run -d -v /etc/localtime:/etc/localtime --restart=always -p 9100:9100 mobz/elasticsearch-head:5

技术分享图片

docker run  -d     --net=host     --restart=always     -v /etc/localtime:/etc/localtime:ro     -v /root/elasticsearch-HQ/royrusso-elasticsearch-HQ-eb117d4:/usr/share/nginx/html     --name nginx 

es数据保留10天以内

#!/bin/bash

###################################
#删除早于十天的ES集群的索引
###################################
function delete_indices() {
    comp_date=`date -d "10 day ago" +"%Y-%m-%d"`
    date1="$1 00:00:00"
    date2="$comp_date 00:00:00"

    t1=`date -d "$date1" +%s`
    t2=`date -d "$date2" +%s`

    if [ $t1 -le $t2 ]; then
        echo "$1时间早于$comp_date,进行索引删除"
        #转换一下格式,将类似2017-10-01格式转化为2017.10.01
        format_date=`echo $1| sed ‘s/-/\./g‘`
        curl -XDELETE http://192.168.x.x:9200/*$format_date
    fi
}

curl -XGET http://192.168.x.x:9200/_cat/indices | awk -F" " ‘{print $3}‘ | awk -F"-" ‘{print $NF}‘ | egrep "[0-9]*\.[0-9]*\.[0-9]*" | sort | uniq  | sed ‘s/\./-/g‘ | while read LINE
do
    #调用索引删除函数
    delete_indices $LINE
done

es数据备份: elasticsearch-dump

https://github.com/taskrabbit/elasticsearch-dump

  • 安装
npm install elasticdump
./bin/elasticdump
  • 使用
支持导出文件
支持导出文件压缩
支持导出后直接导入到另一个stage escluster
elasticdump --help
# Backup index data to a file:
elasticdump   --input=http://production.es.com:9200/my_index   --output=/data/my_index_mapping.json   --type=mapping
elasticdump   --input=http://production.es.com:9200/my_index   --output=/data/my_index.json   --type=data

# Backup and index to a gzip using stdout:
elasticdump   --input=http://production.es.com:9200/my_index   --output=$   | gzip > /data/my_index.json.gz

# Backup the results of a query to a file
elasticdump   --input=http://production.es.com:9200/my_index   --output=query.json   --searchBody ‘{"query":{"term":{"username": "admin"}}}‘

1g的日志不到四五分钟就导完毕: 从一个集群到另一个集群 技术分享图片

[elk]elasticsearch dashboard+保留10天内索引+导入导出备份

原文:http://www.cnblogs.com/iiiiher/p/8029062.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!