创建kibana索引
若只需要收集显示nginx的访问日志,则可以建立一个名为nginx+时间的索引
若是需要收集一个服务器下的多个服务日志,则可以在一个conf下添加多个input并根据type来区分和实现
环境
192.168.2.112 ES/kibana
192.168.2.118 logstash/nginx
192.168.2.117 logstash/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}"
}
}
其中,index即代表对应的索引名称
2)然后启动logstash
[root@localhost etc]# pwd
/usr/local/logstash/etc
[root@localhost etc]# ../bin/logstash -f nginxlog.conf
3)登陆kibana设置索引
4)然后手动访问nginx页面后,可以在kibana的discover界面看到
- 收集nginx日志和mysql日志
1)把118服的logstash目录复制到117服对应目录下
scp -r logstash/* root@192.168.2.117:/usr/local/logstash
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}"
}
}
}
3)在kibana页面建立mysql索引
4)启动logstash
[root@host107 etc]# pwd
/usr/local/logstash/etc
[root@host107 etc]# ../bin/logstash -f all.conf
5)然后启动及关闭mysql服务,就可以看到日志数据
6)同样的,访问nginx页面后,也会收到nginx日志数据
备注:
1)其中上面的host列显示0.0.0.0,是因为没有设置主机名,在/etc/hosts下加上
127.0.0.1 hostmysqlnginx
然后hostname hostmysqlnginx
重启下logstash,就可以看到host