How to start a service by splitting the configuration without using Multiple Pipelines in logstash
※I turned Japanese articles written in Qiita into English.
Japanese:https://qiita.com/henatyokotraveler/items/51ddbb26d84343d07b5d
Thing I want to do
In creating a mechanism to import various files into elasticsearch with logstash, I want to split the config file for readability.
If the logstash version is 6.0 or later,
You can use Multiple Pipelines ,
My environment is 5.6, so I tried it without using Multiple Pipelines.
Points to consider
I referred to the following. ※Japanese Site
- Unit definition file: https://qiita.com/migo/items/21767287dba0f0ee43fd
- Logstash startup user is “logstash” and access authority: http://atsuizo.hatenadiary.jp/entry/2017/09/13/093018
- ”Path.data” error when starting multiple logstash services: https://www.mtioutput.com/entry/2019/02/19/180000
Create unit definition file
Installation and disabling
# yum install logstash
### If it is already running, disable it below ###
# systemctl stop logstash.service
# systemctl disable logstash.service
Create unit definition file
① Make a copy of the original unit definition
# cp -p /etc/systemd/system/logstash.service /etc/systemd/system/logstash_hoge.service
②Create directory for path.data
# mkdir/etc/logstash/logstash_hoge
③Unit definition file
# vi /etc/systemd/system/logstash_hoge.service
Modify the following
- Description correction
- Change User and Group from logstash to root
- Added “ — path.data /etc/logstash/logstash_hoge”at the end of ExecStart
[Unit]
Description = logstash_hoge
[Service]
Type=simple
User=root
Group=root
# Load env vars from /etc/default/ and /etc/sysconfig/ if they exist.
# Prefixing the path with ‘-’ makes it try to load, but if the file doesn’t
# exist, it continues onward.
EnvironmentFile=-/etc/default/logstash
EnvironmentFile=-/etc/sysconfig/logstash
ExecStart=/usr/share/logstash/bin/logstash “--path.settings” “/etc/logstash” -path.data /etc/logstash/logstash_hoge
Restart=always
WorkingDirectory=/
Nice=19
LimitNOFILE=16384[Install]
WantedBy=multi-user.target
Service registration
# systemctl enable logstash_hoge.service
# systemctl start logstash_hoge.service