Centos7安装Elasticsearch及集群

来源:互联网 发布:齐鲁软件大赛奖金 编辑:程序博客网 时间:2024/05/16 11:11

在官方下载elasticsearch.rpm后安装好,配置主要是http地址绑定和port

删除数据:curl -XDELETE 'http://192.168.1.1:9200/user-log*'

集群配置:

主要的是cluster-name要一样,node.master,node.data及discovery.zen.ping.unicast.hosts的配置

比如二个如下配置就行:

node-6206配置:

cluster.name: my-application
node.name: node-6206

path.data: /home/elasticsearch/data
path.logs: /home/elasticsearch/log

network.host: 192.168.6.206
http.port: 9200

http.cors.enabled: true
http.cors.allow-origin: "*"

node.master: true
node.data: false
discovery.zen.ping.unicast.hosts: ["192.168.6.206"]

node-6207配置:

cluster.name: my-application
node.name: node-6207

path.data: /home/elasticsearch/data
path.logs: /home/elasticsearch/log

network.host: 192.168.6.207
http.port: 9200

http.cors.enabled: true
http.cors.allow-origin: "*"

node.master: false
node.data: true
discovery.zen.ping.unicast.hosts: ["192.168.6.206"]

然后先启动master再启动slave就行

查看cluster状态:

http://192.168.6.206:9200/_cat/health?v

查看nodes:

http://192.168.6.206:9200/_cat/nodes?v

查看索引:

http://192.168.6.206:9200/_cat/indices?v

基本操作:

curl -XPUT '192.168.6.206:9200/customer'//创建索引
//插入数据
curl -XPUT '192.168.6.206:9200/customer/external/1'-d '
{
  "name": "John Doe"
}'
curl '192.168.6.206:9200/customer/external/1'//查询数据
curl -XDELETE '192.168.6.206:9200/customer'//删除索引

定时删除(非原创):

#!/bin/bash
# filename:deleteEsData.sh
# 每天2点定时删除es中指定日期的数据
# crontab: 0 2 * * * sh /Application/enterprise/deengine/deleteEsData.sh >> /Application/enterprise/deengine/run.log 2>&1
# 如今天是2015-09-09,删除3天前数据,就是删除2015-09-06的数据
# createdate: 20150909
# author: yuanlong.zhou
today=`date +%Y-%m-%d`;
echo "今天是${today}"
# 获得要删除的日期
# 不指定参数时,默认删除30天前以nginx-开头的数据(因为是凌晨删除,所以不含当天)
daynum=15
# 当参数个数大于1时,提示参数错误
if [ $# -gt 1 ] ;then
        echo "要么不传参数,要么只传1个参数!"
        exit 101;
fi
# 当参数个数为1时,获取指定的参数
if [ $# == 1 ] ;then
        daynum=$1
fi
esday=`date -d '-'"${daynum}"' day' +%Y.%m.%d`;
echo "${daynum}天前是${esday}"
curl -XDELETE http://192.168.6.11:9200/nginx-${esday}
echo "${today}执行完成"

0 0
原创粉丝点击