本篇文件前提是在centos7.6上使用rpm包安装的logstash,添加systemd方式启动。
#默认为rpm包安装,进行执行目录
cd /usr/share/logstash/bin/
#系统自带的system-install就是提供的开机自启动,查看文档说明
[root@db01 bin]# ./system-install --help
OPTIONSFILE: Full path to a startup.options file
OPTIONSFILE is required if STARTUPTYPE is specified, but otherwise looks first
in /usr/share/logstash/config/startup.options and then /etc/logstash/startup.options
Last match wins #我们只看这一行,如果是rpm包,会有/etc/logstash/startup.options文件,进行文件,查看选项是否为各目录存放地址
新建logstash配置文件
#贴上一个简单的实列,作为systemd启动的配置文件
cat /etc/logstash/conf.d/kafka.conf #conf.d目录下只能配置一个.conf文件
input {
kafka{ #从kafka集群中拉取数据
bootstrap_servers => ["10.0.0.200:9092,10.0.0.201:9092,10.0.0.202:9092"]
group_id => "test"
auto_offset_reset => "earliest"
consumer_threads => "5"
decorate_events => "false"
topics => ["kafka"]
type => "nginx_log"
codec => json
}
}
output {
stdout {}
elasticsearch {
hosts => "http://192.168.2.23:9200"
manage_template => false
index => "nginx-%{+yyyy.MM}"
}
}
生成systemd
#生成systemd
/opt/kafka/bin/kafka-server-start.sh -daemon /opt/kafka/config/server.properties
#启动logstash
systemctl start logstash
systemctl enable logstash
#观察日志查看是否启动成功
tail -f /var/log/logstash/logstash-plain.log