es单机搭建会没有备份,es会报yellow 修复状态,如果修复可以用两种方式,一种是添加节点,第二种是更新es没有节点模式
curl -XPUT "http://10.158.2.4:9400/_settings" -d' { "number_of_replicas" : 0 } '
查看集群健康模式
curl -X GET http://10.158.2.4:9400/_cat/health?v
从上面可以看到问题已经解决了
es的增删索引
删除索引
curl -X DELETE 'http://10.158.2.4:9400/nginx-access2019.11.29?pretty'
#nginx-access2019.11.29是索引名称
创建索引
curl -X PUT "10.158.2.4:9400/commodity?pretty"
#commodity是索引名称
注意:默认情况下,创建的索引分片数量是 5 个,副本数量是 1 个。
es的健康值red怎么解决
如果es状态此时还是red, 则需要找出red状态的索引并且删除 (这个时候的red状态的索引应该是少部分)
[root@elk-node02 system]# curl -XGET "http://10.0.8.45:9200/_cat/indices?v"|grep -w "red"
比如找出的red状态的索引名为"10.0.61.24-vfc-intf-ent-order.log-2019.03.04", 删除它即可
[root@elk-node02 system]# curl -XDELETE http://10.0.8.44:9200/10.0.61.24-vfc-intf-ent-order.log-2019.03.04
如果还是不行,请参考链接解决问题
logstash多行学习
链接:https://www.jianshu.com/p/58bf62a5c4ad
脚本
#读
input {
file {
path => "文件全路径"
type => "任意名字最好有意义"#自定义日志区分类型
start_position => "beginning" #从文件开始处读写
}
}
#过滤
filter {
grok {
#切割后日期名字叫logdate
match => ["message", "%{TIMESTAMP_ISO8601:logdate}"]
}
date {
#logdate 从上面过滤后取到的字段名,yyyy-MM-dd HH:mm:ss.SSS 日期格式条件
match => ["logdate", "yyyy-MM-dd HH:mm:ss.SSS"]
#match => ["logdate", "yyyyMMdd","yyyy-MM-dd"]
#赋值给那个key
target => "@timestamp"
#删除不需要的字段
remove_field => ["logdate"]
}
#合并错误日志
multiline {
pattern => "^\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2}"
negate => true
what => "previous"
}
}
#输出
output{
#输出到ES
elasticsearch{
hosts=>["127.0.0.1:9200"]
#es的index名字,默认就是这个,可以更改
index => "logstash-%{+YYYY.MM.dd}"
}
#输出到控制台
stdout{codec => rubydebug}
}
logstash抓取json文件到es
input{
file{
path => "/home/softer/x.json" #输入文件名
type => "data1" #别名
start_position => "beginning" #从头到尾
sincedb_path => "/dev/null" #linux的空文件,让logstash每次启动都以为是第一次
codec => json{ #json文件
charset => "UTF-8" #字符集或者ISO-8859-1
}
}
}
output{
elasticsearch{
hosts => "http://10.10.7.235:9200" #esip地址
index => "shunteng1" #索引名
document_type => "log_packet" #类型名
}
}
logstash必须type为小写,要是小写就报错
logstash从头开始抓取文件,加以下两行代码就行
start_position => "beginning"
sincedb_path => "/dev/null" #从头读