0
点赞
收藏
分享

微信扫一扫

nginxelk日志收集


elk 如何创建新的索引

创建kibana索引

若只需要收集显示nginx的访问日志,则可以建立一个名为nginx+时间的索引

若是需要收集一个服务器下的多个服务日志,则可以在一个conf下添加多个input并根据type来区分和实现

192.168.2.112ES/kibana

192.168.2.118logstash/nginx

192.168.2.117logstash/mysql/nginx

建立nginx索引

1)在118服的logstash/etc目录下建立的nginxlog.conf,添加

input{

file{

path=>"/usr/local/nginx/logs/access.log"

type=>"nginx"

output{

elasticsearch{

hosts=>"192.168.2.112:9200"

index=>"nginx-%{+YYYY.MM.dd}"

}12345678910111213

其中,index即代表对应的索引名称

2)然后启动logstash

[root@localhostetc]#pwd/usr/local/logstash/etc

[root@localhostetc]#../bin/logstash-fnginxlog.conf1234

3)登陆kibana设置索引

4)然后手动访问nginx页面后,可以在kibana的discover界面看到

收集nginx日志和mysql日志

1)把118服的logstash目录复制到117服对应目录下

scp-rlogstash/*root@192.168.2.117:/usr/local/logstash1

2)在117服logstash/etc目录下建立all.conf

input{

file{

path=>"/usr/local/nginx/logs/access.log"

type=>"nginx"

input{

file{

path=>"/var/log/mysqld.log"

type=>"mysql"

output{if[type]=="nginx"{

elasticsearch{

hosts=>"192.168.2.112:9200"

index=>"nginx-%{+YYYY.MM.dd}"

}if[type]=="mysql"{

elasticsearch{

hosts=>"192.168.2.112:9200"

index=>"mysql-%{+YYYY.MM.dd}"

}1234567891011121314151617181920212223242526272829

3)在kibana页面建立mysql索引

4)启动logstash

[root@host107etc]#pwd/usr/local/logstash/etc

[root@host107etc]#../bin/logstash-fall.conf1234

5)然后启动及关闭mysql服务,就可以看到日志数据

6)同样的,访问nginx页面后,也会收到nginx日志数据

1)其中上面的host列显示0.0.0.0,是因为没有设置主机名,在/etc/hosts下加上

127.0.0.1hostmysqlnginx

然后hostnamehostmysqlnginx

重启下logstash,就可以看到host

linux基础培训课程哪个好

现在linux培训机构那么多,网络消息铺天盖地,具体选择哪家机构,最好还是自己去考察一下,现在不同城市linux机构有很多,最好自己去试听一下,看看整体机构的质量如何,是否符合你的要求和标准。

举报

相关推荐

0 条评论