【问题标题】:Unable to create tempDir. java.io.tmpdir is set to /tmp无法创建 tempDir。 java.io.tmpdir 设置为 /tmp
【发布时间】:2020-03-17 18:04:23
【问题描述】:

在 ubuntu 服务器上运行我的 springboot Web 服务 java jar 应用程序会导致如下所示的错误,我已经对该错误进行了一些研究,但是我无法找到解决方案。我用来运行 jar 文件的命令是

java -jar mySpringBootApp.jar

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to create tempDir. java.io.tmpdir is set to /tmp
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:157) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) ~[spring-context-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at aacctt.payments.org.Application.main(Application.java:18) [classes!/:0.0.1-SNAPSHOT]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [ mySpringBootApp-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [ mySpringBootApp-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [ mySpringBootApp-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [ mySpringBootApp-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to create tempDir. java.io.tmpdir is set to /tmp
    at org.springframework.boot.web.server.AbstractConfigurableWebServerFactory.createTempDir(AbstractConfigurableWebServerFactory.java:182) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:162) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    ... 16 common frames omitted
Caused by: java.io.IOException: Read-only file system
    at java.io.UnixFileSystem.createFileExclusively(Native Method) ~[na:1.8.0_191]
    at java.io.File.createTempFile(File.java:2024) ~[na:1.8.0_191]
    at java.io.File.createTempFile(File.java:2070) ~[na:1.8.0_191]
    at org.springframework.boot.web.server.AbstractConfigurableWebServerFactory.createTempDir(AbstractConfigurableWebServerFactory.java:173) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    ... 19 common frames omitted

【问题讨论】:

  • 要么授予用户写入 tmp 的权限,要么使用 jvm 选项更改 tmp 目录 -Djava.io.tmpdir=。

标签: java spring spring-boot jar


【解决方案1】:

您的应用程序用户可能没有足够的权限在/tmp 目录中创建任何内容...请参阅最后一条消息Caused by: java.io.IOException: Read-only file system

【讨论】:

  • 关于如何授予它权限的任何想法
  • 首先尝试如果您真的没有权限...像touch /tmp/testfile.txt 这样的命令可能会给您一个结果。如果它告诉您您没有权限,请尝试chmod 1777 /tmp
  • 运行第一个命令时出现此错误 ``` touch: cannot touch '/tmp/testfile.txt': Read-only file system ```
  • 当我运行最后一个命令时,我得到了 chmod: changed permissions of '/tmp': Read-only file system
【解决方案2】:

尝试以下任一方法:

1) 更改 /tmp 的权限以授予您的用户访问权限。 chmod -R 777 /tmp 确保您使用 sudo 访问 (root) 运行上述命令

2) 将用户添加到 sudo 组。

【讨论】:

    【解决方案3】:

    对于在运行/调试配置中提供环境变量时从 Intellij IDEA 运行时遇到相同异常的用户: 请查看是否勾选了“包含父环境变量”

    【讨论】:

      【解决方案4】:

      如果您在 Kubernetes 中部署 Spring Boot 应用程序时遇到此问题,值得检查的配置之一是 readOnlyRootFilesystem。在您尝试有意运行只读容器之前,必须将其设置为 false。

      它可以在部署配置中使用如下:

      template:
          metadata:
            labels:
              app: hello
          spec:
            containers:
            - name: hello
              image: hello-world
              securityContext:
                runAsUser: 1000
                readOnlyRootFilesystem: false ## this should not be true
      

      【讨论】:

        猜你喜欢
        • 2018-11-09
        • 2019-12-18
        • 1970-01-01
        • 1970-01-01
        • 2012-04-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-19
        相关资源
        最近更新 更多