概要

今天在群里一个关于在 logstash 的配置目录存在多个配置文件时候如何处理的问题?

我说是加载所有配置文件并合并为一个。

lcy@lcy:~/ELK/logstash$ sudo /opt/logstash/bin/logstash --help
[sudo] password for lcy:
Usage:
/bin/logstash agent [OPTIONS] Options:
-f, --config CONFIG_PATH Load the logstash config from a specific file
or directory. If a directory is given, all
files in that directory will be concatenated
in lexicographical order and then parsed as a
single config file. You can also specify
wildcards (globs) and any matched files will
be loaded in the order described above.

下面,做个小实验用以说明。

文件说明

1. conf.d 目录说明

存在2个配置文件 1.conf 和 2.conf

// 存在2个配置文件
lcy@lcy:/etc/logstash/conf.d$ ls
.conf .conf

其中 1.conf 配置了 input ,使用 file 插件来导入文件 file_1(input中参数配置为 file_*) 的内容。并且在 fileter 中加一个 filed ,名称叫 add_from_1。输出格式为 rubydebug。

// 文件1.conf的内容
lcy@lcy:/etc/logstash/conf.d$ cat .conf
input {
file {
path => "/home/lcy/file_*"
start_position => "beginning"
ignore_older =>
stat_interval =>
discover_interval =>
}
}
filter {
mutate {
add_field => {
"add_from_1" => ""
}
}
}
output {
stdout {
codec => rubydebug
}
}

其中 2.conf 没有配置 input 。在 fileter 中加一个 filed ,名称叫 add_from_2。输出格式为 JSON。

// 文件2.conf的内容
lcy@lcy:/etc/logstash/conf.d$ cat .conf
filter {
mutate {
add_field => {
"add_from_2" => ""
}
}
}
output {
stdout {
codec => json
}
}

2. 输入源文件

file_1 很简单,就一个单行 JSON 文件。

// file_1 的文件内容
lcy@lcy:~$ cat file_1
{"file_1":{"tag_1":"value_1"}}

执行结果

1. 启动 logstash

lcy@lcy:/etc/logstash/conf.d$ sudo /opt/logstash/bin/logstash -f /etc/logstash/conf.d/
Settings: Default pipeline workers:
Logstash startup completed

2. 输出结果

即输出了 rubydebug 格式,又输出了 JSON 格式。

lcy@lcy:/etc/logstash/conf.d$ sudo /opt/logstash/bin/logstash -f /etc/logstash/conf.d/
Settings: Default pipeline workers:
Logstash startup completed
{
"message" => "{\"file_1\":{\"tag_1\":\"value_1\"}}",
"@version" => "",
"@timestamp" => "2016-04-28T06:42:43.050Z",
"path" => "/home/lcy/file_1",
"host" => "lcy",
"add_from_1" => "",
"add_from_2" => ""
}
{"message":"{\"file_1\":{\"tag_1\":\"value_1\"}}","@version":"","@timestamp":"2016-04-28T06:42:43.050Z","path":"/home/lcy/file_1","host":"lcy","add_from_1":"","add_from_2":""}
^CSIGINT received. Shutting down the pipeline. {:level=>:warn}
^CSIGINT received. Terminating immediately.. {:level=>:fatal}
^CSIGINT received. Terminating immediately.. {:level=>:fatal}

结论

可以看出,实际执行中,把 1.conf 和 2.conf 文件的内容完全合并为了一个配置文件

INPUT    :2.conf 没有配置 input 不会报错,因为 1.conf 中有(input 为必须)
FILETER :输出内容中即添加了 add_from_1 也添加了 add_from_2 两个 filed
OUTPUT :输出了2中格式,rubydebug 和 JSON

Logstash conf.d 多个配置文件的更多相关文章

  1. ELK学习笔记之Logstash不停机自动重载配置文件

    0x00 自动重新加载配置 为了可以自动检测配置文件的变动和自动重新加载配置文件,需要在启动的时候使用以下命令: ./bin/lagstash -f configfile.conf --config. ...

  2. logstash/conf.d文件编写

    logstash-01.conf input { beats { port => 5044 host => "0.0.0.0" type => "log ...

  3. smb.conf - Samba组件的配置文件

    总览 SYNOPSIS smb.conf是Samba组件的配置文件,包含Samba程序运行时的配置信息.smb.conf被设计成可由swat (8)程序来配置和管理.本文件包含了关于smb.conf的 ...

  4. svnserve.conf - snvserve 的仓库配置文件

    SYNOPSIS 总览 repository-path/conf/svnserve.conf DESCRIPTION 描述 每个代码仓库都有一个 svnserve.conf 文件来控制 svnserv ...

  5. nginx.conf nginx反向代理配置文件

    nginx反向代理配置文件 nginx.conf proxy_default.conf proxy.conf vhost/*.conf upstream/*.conf cache/*.conf ngi ...

  6. nginx.conf 文中描述的配置文件

    ###############################nginx.conf 件里文说明 #user nobody; # user 主模块指令,指令nginx worker 执行用户和用户组(u ...

  7. /etc/sysctl.conf 控制内核相关配置文件

    /etc/sysctl.conf 用于控制内核相关的配置参数,而且它的内容全部是对应于 /proc/sys/ 这个目录的子目录及文件 [root@MongoDB ~]# ll /proc/sys to ...

  8. logstash.conf 根据不同地址创建索引

    input { http { host => "0.0.0.0" port => 9700 type => "from_ys" }}input ...

  9. centos7搭建ELK Cluster集群日志分析平台(二):Logstash

    续  centos7搭建ELK Cluster集群日志分析平台(一) 已经安装完Elasticsearch 5.4 集群. 安装Logstash步骤 . 安装Java 8 官方说明:需要安装Java ...

随机推荐

  1. HDU 5634 Rikka with Phi 线段树

    题意:bc round 73 div1 D 中文题面 分析:注意到10^7之内的数最多phi O(log(n))次就会变成1, 因此可以考虑把一段相同的不为1的数缩成一个点,用平衡树来维护. 每次求p ...

  2. PHP 判断协议是否为HTTPS

    if ($_SERVER['HTTPS'] != "on") { echo "This is not HTTPS"; }else{ echo "Thi ...

  3. Unix 基础IO

    内核通过文件描述符引用打开的文件,通常通过open函数或者create函数返回文件描述符. 基本函数: unix中基础的文件操作函数只有5个,分别是open,close,lseek,read,writ ...

  4. 微软Azure云主机及blob存储的网络性能测试

    http://www.cnblogs.com/sennly/p/4137024.html 微软Azure云主机及blob存储的网络性能测试 1. 测试目的 本次测试的目的在于对微软Azure的云主机. ...

  5. Error starting static Resources java.lang.IllegalArgumentException: Document base D:\Program Files\apache-tomcat-xxx\webapps\xxx does not exist or is not a readable directory

    网上的答案大多数如下: 但并没有解决我的问题  经过我的观察: 在tomcat的server.xml有Lottery项目描述,但实际上,该项目已被我删除,不存在于webapps中了    该行Cont ...

  6. Windows命令行使用FTP

    1.系统环境 FTP客户端:Windows7旗舰版,管理员权限命令行: FTP服务端:CentOS 6.5,VSFTP,端口 21(默认) 2.登陆FTP 在命令行下输入 ftp,出现 ftp> ...

  7. hdoj 3371 Connect the Cities

    Connect the Cities Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  8. 新浪新闻API接口

    头条 http://api.sina.cn/sinago/list.json?channel=news_toutiao推荐 http://api.sina.cn/sinago/list.json?ch ...

  9. Modbus调试利器 Modbus Poll

    Modbus Poll是一个非常不错的工具,支持TCP/串口 下载地址:http://pan.baidu.com/share/link?shareid=2880213929&uk=248325 ...

  10. SpringMVC(三)

    今天是学习Spring的第四天,今天终于又把Spring+SpringMVC+Mybatis(SSM)高了一遍,这次运行的代码和配置和昨天的不一样,今天运行的很成功. 主要学习的一点就是我今天使用的是 ...