CentOS7 logstash配置部署

(1)logstash介绍

Logstash是一个开源的数据收集引擎,可以水平伸缩,而且logstash是整个ELK当中拥有最多插件的一个组件,其可以接收来自不同源的数据并统一输入到指定的且可以是不同目的地。
logstash收集日志基本流程: input-->codec-->filter-->codec-->output 
	input:从哪里收集日志。 
	filter:发出去前进行过滤 
	output:输出至Elasticsearch或Redis消息队列 
	codec:输出至前台,方便边实践边测试 
	数据量不大日志按照月来进行收集
```
#(2)安装和配置logstash
1.安装logstash
```
wget https://artifacts.elastic.co/downloads/logstash/logstash-6.0.0.rpm
yum install -y logstash-6.0.0.rpm 
ln -sv /usr/share/logstash/bin/logstash /bin/								//创建一个软连接,每次执行命令的时候不用在写安装路劲(默认安装在/usr/share下)
chown -R logstash.logstash /etc/logstash/conf.d/
 ll /etc/logstash/conf.d/     												//logstash的主配置目录 
```
2.logstash基本语法
```
input {
        指定输入
}
output {
        指定输出
}
```
3.测试标准输入输出
```
logstash -e 'input { stdin { } } output { stdout { } }'
```
![](https://images2018.cnblogs.com/blog/1195071/201805/1195071-20180528173113622-1012856198.png)
4.测试标准输入输出-更详细信息
```
logstash -e 'input { stdin { } } output { stdout { codec => rubydebug } }'
```
![](https://images2018.cnblogs.com/blog/1195071/201805/1195071-20180528173124967-1292362824.png)
5.测试输出到elasticsearch和屏幕上
```
logstash -e 'input { stdin { } } output { elasticsearch { hosts => ["192.168.1.31:9200"] } stdout { codec => rubydebug } }'
```
![](https://images2018.cnblogs.com/blog/1195071/201805/1195071-20180528173142440-85335088.png)
![](https://images2018.cnblogs.com/blog/1195071/201805/1195071-20180528173221263-278466291.png)
6.测试使用配置文件
```
#vim /etc/logstash/conf.d/elk.conf
input { stdin { } }
output {
        elasticsearch {
                hosts => ["192.168.1.31"]
                index => "logstash-%{+YYYY.MM.dd}"
                }
        stdout { codec => rubydebug }
}
#logstash -f /etc/logstash/conf.d/elk.conf                 //启动
```
![](https://images2018.cnblogs.com/blog/1195071/201805/1195071-20180528173250260-117202887.png)
7.测试使用file插件
```
#vim /etc/logstash/conf.d/elk.conf
input {
        file {
                path => "/var/log/messages"
                type => "system"
                start_position => "beginning"
        }
}

output {
        elasticsearch {
                hosts => ["192.168.1.31"]
                index => "system-%{+YYYY.MM.dd}"
                }
}
```
![](https://images2018.cnblogs.com/blog/1195071/201805/1195071-20180528173300317-228288530.png)
posted @ 2018-05-28 17:33  你很棒  阅读(1370)  评论(0编辑  收藏  举报