elasticsearch+logstash记录日志
记录一下一个记录日志的组合拳工具。
安装elasticsearch
1、下载elasticsearch
地址:https://github.com/elastic/elasticsearch/releases/tag/v7.16.3
2、解压之后将解压后的文件放到:/usr/local目录下
3、elasticsearch不能以root用户运行,添加一个用户:useradd esuser
4、给/usr/local/elasticsearch-7.16.2这个文件直接权力给esuser这个用户:chown elastic /usr/local/elasticsearch-7.16.2 -R
5、进入esuser角色:su esuser
6、进入到/usr/local/elasticsearch-7.16.2/bin运行elasticsearch:./elasticsearch -d运行
7、验证:浏览器输入IP:9200
安装elasticsearch-head
直接去谷歌上搜索这个名字的插件,安装最新版,安装完之后在浏览器最顶上输入你的服务地址,如:http://IP:9200/
安装logstash
1、下载logstash
地址:https://www.elastic.co/cn/downloads/past-releases/logstash-7-6-2
2、解压后进入修改config下的文件test.conf:
input {
beats {
port => 5044
}
file {
path => "/root/xxx/log/INFO.log" ##锁定哪个文件下的log文件
type => "INFO" ##log类型
start_position => "beginning" ##从文件的哪个位置开始记录
}
file {
path => "/root/lixueming/log/ERROR.log"
type => "ERROR"
start_position => "beginning"
}
}
output {
elasticsearch {
hosts => ["http://127.0.0.1:9200"] ##es的地址
index => "sche1_log" ##索引名称
#user => "esuser"
#password => "changeme"
}
}
3、进入bin目录下启动logstash:
命令:-f 指定config文件的地址
nohup ./logstash -f /root/logstash-7.16.2/config/logstash-test.conf --config.reload.automatic &