centos 7的Logstash文件服务帐户



我试图在CentOS 7环境中获得filebeat(用于logstash转发),以便在我创建的用户帐户下运行:filebeat而不是root。我尝试将/etc/rc.d/init.d/filebeat文件编辑为以下内容,但无济于事。我可能做错了什么,但对BASH脚本仍然有点陌生,我可能把它放在错误的地方?我试图按照建议的实现说明位于这里

为简洁起见,我只显示上述文件的第一部分,因为后面的部分没有变化:

#!/bin/bash
#
# filebeat          filebeat shipper
#
# chkconfig: 2345 98 02
#
### BEGIN INIT INFO
# Provides:          filebeat
# Required-Start:    $local_fs $network $syslog
# Required-Stop:     $local_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Sends log files to Logstash or directly to Elasticsearch.
# Description:       filebeat is a shipper part of the Elastic Beats
#                                        family. Please see: https://www.elastic.co/products/beats
### END INIT INFO

PATH=/usr/bin:/sbin:/bin:/usr/sbin
export PATH
[ -f /etc/sysconfig/filebeat ] && . /etc/sysconfig/filebeat
pidfile=${PIDFILE-/var/run/filebeat.pid}
agent=${PB_AGENT-/usr/bin/filebeat}
args="-c /etc/filebeat/filebeat.yml"
test_args="-e -configtest"
wrapper="filebeat-god"
wrapperopts="-r / -n -p $pidfile"
RETVAL=0
service_user="filebeat"
# Source function library.
. /etc/rc.d/init.d/functions
# Determine if we can use the -p option to daemon, killproc, and status.
# RHEL < 5 can't.
if status | grep -q -- '-p' 2>/dev/null; then
    daemonopts="--user $service_user --group $service_group --pidfile $pidfile"
    **chown -R $service_user /etc/filebeat || return 1
    chown $service_user $pidfile || return 1
    chmod g+w $pidfile || return 1**
    pidopts="-p $pidfile"
    touch
fi

之前,我创建了一个用户帐户filebeat,使用类似于以下内容:

useradd filebeat -u 5044 -c "Filebeat Service Account" -d /dev/null -s /sbin/nologin

但是,当我尝试在启动后查看进程时,它仍然显示为由root拥有:

[root@testvm ~]# ps -aef | grep filebeat
root     26030     1  0 13:16 ?        00:00:00 /usr/bin/filebeat -c /etc/filebeat/filebeat.yml

在RHEL/CentOS 7上,systemd管理服务,所以init。不使用D文件。您应该修改Filebeat的单元文件,以便作为不同的用户运行该服务。单元文件安装在/lib/systemd/system/filebeat.service

您需要在Service部分添加User选项。

[Service]
User=<username>

用户必须对日志文件具有读权限,对日志文件所在目录具有搜索权限(执行位)。Filebeat使用stat收集文件的inode, stat根据手册页要求目录上的执行权限。

最新更新