橡皮、老虎皮、狮子皮哪一个最不好?

logstash docker-compose启动失败,一直报没有权限,包括文件配置路径及端口映射

Logstash | 作者 sun_changlong | 发布于2018年11月06日 | 阅读数:4253

今天通过拉取官方logstash 6.4.2 镜像在centos中进行部署,运行时遇到很奇怪的问题,以下是我的配置;
logstash目录结构:


├── conf.d
│   └── summary.conf
├── config
│   ├── jvm.options
│   ├── log4j2.properties
│   ├── logstash.yml
│   ├── pipelines.yml
│   └── startup.options
├── docker-compose.yml
├── log
│   └── sys.log
├── logs
│   ├── logstash-plain.log
│   └── logstash-slowlog-plain.log
├── logstash
│   └── maps
└── maps
    └── GeoLite2-City-gaode.mmdb


 
docker-compose.yml


version: '2' 
services:
  logstash: 
    image: logstash:6.4.2
    container_name: logstash 
    privileged: true
    volumes: 
      - ./data:/usr/share/logstash/data #:rw
      - ./logs:/usr/share/logstash/logs #:rw
      - ./log:/usr/share/logstash/log #:rw
      - ./conf.d:/etc/logstash/conf.d #:rw
      - ./config/logstash.yml:/usr/share/logstash/config/logstash.yml #:rw
      - ./config/startup.options:/usr/share/logstash/config/startup.options #:rw
      - ./config/log4j2.properties:/usr/share/logstash/config/log4j2.properties #:rw
      - ./logstash/maps:/usr/share/logstash/maps #:rw
    
    ports:
      - 9600:9600
      - 5044:5044
      - 515:515/udp
    command: "-f /etc/logstash/conf.d -r"
    networks:
      - lognet

networks:
  lognet



docker-compose.yml 中设置了  privileged: true
config下 startup.options 的配置LS_USER  给为root  LS_USER=root
 
运行docker-compose up 以后出现报错,主要是volumes 和 ports 没有权限,部分信息如下:
 
Creating network "logstash_test_lognet" with the default driver
Creating logstash ... done
Attaching to logstash
logstash | Sending Logstash logs to /usr/share/logstash/logs which is now configured via log4j2.properties
logstash | 2018-11-06 09:47:19,510 main ERROR RollingFileManager (/usr/share/logstash/logs/logstash-plain.log) java.io.FileNotFoundException: /usr/share/logstash/logs/logstash-plain.log ([b]Permission denied[/b]) java.io.FileNotFoundException: /usr/share/logstash/logs/logstash-plain.log (Permission denied)
logstash | at java.io.FileOutputStream.open0(Native Method)
logstash | at java.io.FileOutputStream.open(FileOutputStream.java:270)
logstash | at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
logstash | at java.io.FileOutputStream.<init>(FileOutputStream.java:133)
logstash | at org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory.createManager(RollingFileManager.java:640)
logstash | at org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory.createManager(RollingFileManager.java:608)
logstash | at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:113)
logstash | at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:115)
logstash | at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.getFileManager(RollingFileManager.java:188)
logstash | at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:144)
logstash | at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:60)
logstash | at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
logstash | at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:958)
logstash | at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:898)
logstash | at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:890)
logstash | at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:513)
logstash | at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:237)
logstash | at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:249)
logstash | at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
logstash | at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617)
logstash | at org.apache.logging.log4j.core.LoggerContext.setConfigLocation(LoggerContext.java:603)
logstash | at org.logstash.log.LoggerExt.reconfigure(LoggerExt.java:158)
logstash | at org.logstash.log.LoggerExt$INVOKER$s$1$0$reconfigure.call(LoggerExt$INVOKER$s$1$0$reconfigure.gen)
logstash | at org.jruby.internal.runtime.methods.JavaMethod$JavaMethodN.call(JavaMethod.java:739)
logstash | at org.jruby.ir.targets.InvokeSite.invoke(InvokeSite.java:145)
logstash | at usr.share.logstash.logstash_minus_core.lib.logstash.runner.RUBY$method$execute$0(/usr/share/logstash/logstash-core/lib/logstash/runner.rb:257)
logstash | at usr.share.logstash.logstash_minus_core.lib.logstash.runner.RUBY$method$execute$0$__VARARGS__(/usr/share/logstash/logstash-core/lib/logstash/runner.rb)
logstash | at org.jruby.internal.runtime.methods.CompiledIRMethod.call(CompiledIRMethod.java:77)
logstash | at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:93)
logstash | at org.jruby.ir.targets.InvokeSite.invoke(InvokeSite.java:145)
logstash | at usr.share.logstash.vendor.bundle.jruby.$2_dot_3_dot_0.gems.clamp_minus_0_dot_6_dot_5.lib.clamp.command.RUBY$method$run$0(/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/clamp-0.6.5/lib/clamp/command.rb:67)
logstash | at usr.share.logstash.vendor.bundle.jruby.$2_dot_3_dot_0.gems.clamp_minus_0_dot_6_dot_5.lib.clamp.command.RUBY$method$run$0$__VARARGS__(/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/clamp-0.6.5/lib/clamp/command.rb)
logstash | at org.jruby.internal.runtime.methods.CompiledIRMethod.call(CompiledIRMethod.java:77)
logstash | at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:93)
logstash | at org.jruby.ir.runtime.IRRuntimeHelpers.instanceSuper(IRRuntimeHelpers.java:983)
logstash | at org.jruby.ir.runtime.IRRuntimeHelpers.instanceSuperSplatArgs(IRRuntimeHelpers.java:974)
logstash | at org.jruby.ir.targets.InstanceSuperInvokeSite.invoke(InstanceSuperInvokeSite.java:39)
logstash | at usr.share.logstash.logstash_minus_core.lib.logstash.runner.RUBY$method$run$0(/usr/share/logstash/logstash-core/lib/logstash/runner.rb:237)
logstash | at usr.share.logstash.logstash_minus_core.lib.logstash.runner.RUBY$method$run$0$__VARARGS__(/usr/share/logstash/logstash-core/lib/logstash/runner.rb)
logstash | at org.jruby.internal.runtime.methods.CompiledIRMethod.call(CompiledIRMethod.java:77)
logstash | at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:93)
logstash | at org.jruby.ir.targets.InvokeSite.invoke(InvokeSite.java:145)
logstash | at usr.share.logstash.vendor.bundle.jruby.$2_dot_3_dot_0.gems.clamp_minus_0_dot_6_dot_5.lib.clamp.command.RUBY$method$run$0(/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/clamp-0.6.5/lib/clamp/command.rb:132)
logstash | at org.jruby.internal.runtime.methods.CompiledIRMethod.call(CompiledIRMethod.java:77)
logstash | at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:93)
logstash | at org.jruby.ir.targets.InvokeSite.invoke(InvokeSite.java:145)
logstash | at usr.share.logstash.lib.bootstrap.environment.RUBY$script(/usr/share/logstash/lib/bootstrap/environment.rb:73)
logstash | at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
logstash | at org.jruby.ir.Compiler$1.load(Compiler.java:95)
logstash | at org.jruby.Ruby.runScript(Ruby.java:828)
logstash | at org.jruby.Ruby.runNormally(Ruby.java:747)
logstash | at org.jruby.Ruby.runNormally(Ruby.java:765)
logstash | at org.jruby.Ruby.runFromMain(Ruby.java:578)
logstash | at org.logstash.Logstash.run(Logstash.java:102)
logstash | at org.logstash.Logstash.main(Logstash.java:45)


logstash 目录我通过 chmod -R 777 给过权限
已邀请:

rochy - rochy_he

赞同来自:

根据日志是说文件 /usr/share/logstash/logs/logstash-plain.log 没有读取权限
你可以设置一下日志目录的权限
 

sun_changlong

赞同来自:

我找到了解决办法, 在docker-compose 中使用 user:选项去设置root 用户启动docker,能解决权限问题
 
可以参考: logstash docker-compose启动 权限问题 
 

zqc0512 - andy zhou

赞同来自:

docker 都是坑 。
用户root 启动 要取日志权限。
 
 

要回复问题请先登录注册