centos6下filebeat多开问题

centos6下filebeat多开问题

0. 场景

比如之前在用filebeat做收集,但是想新开一个实例把之前的日志全部重新导一遍,如果直接指定filebeat -c 是不行的,因为filebeat把文件读取的游标记录在文件里面了。默认是/var/lib/filebeat下面。

网上搜了一下是没找到相关文档,所以记录一下自己的做法。下面做法的一个大前提是centos6,centos7的做法最后会提到。

1. 做法

做法其实很简单,启动脚本进行修改了以后尝试即可。我们看看filebeat的启动脚本。

...
args="-c /etc/filebeat/filebeat.yml -path.home /usr/share/filebeat -path.config /etc/filebeat -path.data /var/lib/filebeat -path.logs /var/log/filebeat"
...

基本上你结合filebeat -h的帮助,改下参数即可得到多开方案。
这里面有3个点,

  1. -c 配置文件
  2. -path.data 存放metadata的,
  3. -path.logs 日志目录

结合filebeat -h

Flags:
  -E, --E setting=value      Configuration overwrite
  -M, --M setting=value      Module configuration overwrite
  -N, --N                    Disable actual publishing for testing
  -c, --c string             Configuration file, relative to path.config (default "filebeat.yml")
      --cpuprofile string    Write cpu profile to file
  -d, --d string             Enable certain debug selectors
  -e, --e                    Log to stderr and disable syslog/file output
  -h, --help                 help for filebeat
      --httpprof string      Start pprof http server
      --memprofile string    Write memory profile to this file
      --modules string       List of enabled modules (comma separated)
      --once                 Run filebeat only once until all harvesters reach EOF
      --path.config string   Configuration path (default "")
      --path.data string     Data path (default "")
      --path.home string     Home path (default "")
      --path.logs string     Logs path (default "")
      --plugin pluginList    Load additional plugins
      --setup                Load sample Kibana dashboards and setup Machine Learning
      --strict.perms         Strict permission checking on config files (default true)
  -v, --v                    Log at INFO level

跟原来的区别开就行,我试了,可以正常运行的。 但是有点小瑕疵,比如pid问题:

2. pid

看filebeat的帮助里面是没法指定pidfile的,没pidfile就不大好杀进程了,得查了根据命令参数或者启动时间来判断,比较麻烦,后面仔细看了启动脚本,发现脚本是

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

# 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
$wrapper

wrapper="/usr/share/filebeat/bin/filebeat-god"

wrapperopts="-r / -n -p $pidfile"

其实是掉了filebeat-god, 这个命令是可以加pidfile的。

限定centos6

其实centos7是没有filebeat-god,用了systemctl以后很简洁:

[Service]
ExecStart=/usr/share/filebeat/bin/filebeat -c /etc/filebeat/filebeat.yml -path.home /usr/share/filebeat -path.config /etc/filebeat -path.data /var/lib/filebeat -path.logs /var/log/filebeat
Restart=always

systemctl应该是会自己记pid,stop的时候发送kill信好就行了。比6高到不知道哪里去了。

猜你喜欢

转载自www.cnblogs.com/gqdw/p/10587127.html
今日推荐