gpt4 book ai didi

centos - 在 Centos 6.5 上以不同的用户或服务帐户运行 filebeat

转载 作者:行者123 更新时间:2023-12-04 19:44:09 27 4
gpt4 key购买 nike

在 Centos 6.5 上以不同用户或服务帐户启动 filebeat 的最佳方法是什么?

在我用 service filebeat start 启动它的那一刻,它始终以 root 身份运行。

这些是 Centos 6.5 上/etc/init.d/filebeat 文件的内容:

#!/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

# 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="--pidfile $pidfile"
pidopts="-p $pidfile"
fi

test() {
$agent $args $test_args
}

start() {
echo -n $"Starting filebeat: "
test
if [ $? -ne 0 ]; then
echo
exit 1
fi
daemon $daemonopts $wrapper $wrapperopts -- $agent $args
RETVAL=$?
echo
return $RETVAL
}

stop() {
echo -n $"Stopping filebeat: "
killproc $pidopts $wrapper
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${pidfile}
}

restart() {
test
if [ $? -ne 0 ]; then
return 1
fi
stop
start
}

rh_status() {
status $pidopts $wrapper
RETVAL=$?
return $RETVAL
}

rh_status_q() {
rh_status >/dev/null 2>&1
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
exit 1
esac

exit $RETVAL

谢谢

最佳答案

你试过改变:

daemonopts="--pidfile $pidfile"

至:
daemonopts="--pidfile $pidfile --user <REPLACE_YOUR_UID_HERE>"

您也可以使用变量代替 <REPLACE_YOUR_UID_HERE>

关于centos - 在 Centos 6.5 上以不同的用户或服务帐户运行 filebeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40108866/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com