zoukankan      html  css  js  c++  java
  • [elk]elasticsearch dashboard+保留10天内索引+导入导出备份

    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的日志不到四五分钟就导完毕: 从一个集群到另一个集群

  • 相关阅读:
    宋元
    隋唐
    中国历史上三次大分裂时期
    三国
    PCL点云 no override found for 'vtkActor'.
    PCL 点云欧式聚类
    PCL区域生长分割
    OPENCV 求轮廓方向
    pcl点云的创建、访问与转换
    PCL 圆柱模型和平面模型的分割
  • 原文地址:https://www.cnblogs.com/iiiiher/p/8029062.html
Copyright © 2011-2022 走看看