1. 程式人生 > >Tomcat空間不足:java.lang.IllegalStateException: Unable to create the directory [/tmp/tomcat.]

Tomcat空間不足:java.lang.IllegalStateException: Unable to create the directory [/tmp/tomcat.]

今天在伺服器部署專案的時候遇到了專案無法啟動的錯誤,仔細一看異常:

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.IllegalStateException: Unable to create the directory [/tmp/tomcat.xxx] to use as the base directory
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
	at com.example.ruledemo.RuledemoApplication.main(RuledemoApplication.java:10) [ruledemo.jar:na]
Caused by: java.lang.IllegalStateException: Unable to create the directory [/tmp/tomcat.3736867899040188915.8080] to use as the base directory
	at org.apache.catalina.startup.Tomcat.initBaseDir(Tomcat.java:724) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
	at org.apache.catalina.startup.Tomcat.getServer(Tomcat.java:539) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
	at org.apache.catalina.startup.Tomcat.getService(Tomcat.java:472) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
	at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:165) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
	... 8 common frames omitted

大體意思就是無法啟動服務,沒辦法建立目錄?許可權不夠?這必然不可能,使用的已經是最高許可權。那必然便是磁碟不夠了,df -h一查果然如此。理論上該問題到這裡就結束了啊,但是問題是這目錄裡的東西不知道哪些沒有用哪些有用啊?那這怎麼辦?

沒事,假若別的地方還有空間,那麼一開始其實系統已經提示你了:

Try using the -Djava.io.tmpdir= option to select an alternate temp location.

照著方法來就是了,所以我們在啟動jar包的時候,多加上這麼一條,形如:

java -Djava.io.tmpdir=/xxx/xxxx/tmp -jar xxxx.jar 

中間的tmpdir替換成有空間的目錄就行了,最後專案完美的啟動了啟動。

Started TestdemoApplication in 32.283 seconds (JVM running for 37.222)