简体   繁体   English

如何使用Spring Boot微服务extern log4j.properties文件并将其作为Linux服务运行?

[英]How to Extern log4j.properties file with Spring Boot Microservice and Run It As a Linux Service?

Have a Spring Boot (1.5.4.RELEASE) based microservice which I deploy a jar to an AWS EC Instance (Linux environment). 有一个基于Spring Boot(1.5.4.RELEASE)的微服务,我将jar部署到AWS EC实例(Linux环境)。 Now, I am also deploying an external log4j.properties file so I have to start the microservice like this: 现在,我还部署了一个外部log4j.properties文件,所以我必须像这样启动微服务:

java -jar myapp.jar -Dlogging.config=/path/to/log4j.properties

How can I configure this Spring Boot Microservice as a Linux service where I can start and stop it using these flags: 如何将此Spring Boot微服务配置为Linux服务,我可以使用这些标志启动和停止它:

sudo service myapp start | stop | status | restart

Thank you very much. 非常感谢你。

Using a symbolic link to your springboot app you can make it controllable as service... 使用指向springboot应用程序的符号链接,您可以将其作为服务进行控制......

sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp

Placing an application.properties into your myapp folder you can override the one bundled inside your app. application.properties放入myapp文件夹,您可以覆盖应用程序中捆绑的应用程序。 This way you don't need to use command line switches. 这样您就不需要使用命令行开关。 Simply specify the path to your log configuration as value to property key logging.config inside of it. 只需将日志配置的路径指定为其内部属性键logging.config值。

NOTE, though, that this solution is not really best practice. 但请注意,此解决方案并非真正的最佳实践。 Once you're running a whole bunch of services in production, you probably rather want to go for something along the lines of spring cloud config for externalizing configuration and you probably also want your logs aggregated at a centralized service that allows for an overview of all your services' logs in one place. 一旦你在生产中运行了一大堆服务,你可能更愿意采用Spring cloud配置的内容来进行外部化配置,你可能还希望将日志聚合在一个集中的服务上,以便对所有服务进行概述。您的服务在一个地方登录。

As per spring-boot deployment , 根据spring-boot部署

A fully executable jar can be executed like any other executable binary or it can be registered with init.d or systemd 完全可执行的jar可以像任何其他可执行二进制文件一样执行,也可以使用init.dsystemd注册

Make sure you build your app using the plug-in below (gradle version in shared link): 确保使用下面的插件构建应用程序(共享链接中的gradle版本):

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <executable>true</executable>
    </configuration>
</plugin>

and as shown by Jörg, create a symbolic link inside init.d: 并且如Jörg所示,在init.d中创建一个符号链接:

sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp

That is the simplified version :) 那是简化版:)

More to your question, you need to customize the init and this can be done by a conf file - all specified in the documentation. 更多问题,您需要自定义init,这可以通过conf文件完成 - 所有这些都在文档中指定。

With the exception of JARFILE and APP_NAME , the settings can be configured using a .conf file. JARFILEAPP_NAME ,可以使用.conf文件配置设置。 The file is expected next to the jar file and have the same name but suffixed with .conf rather than .jar. 该文件位于jar文件旁边,并且具有相同的名称,但后缀为.conf而不是.jar。 For example, a jar named /var/myapp/myapp.jar will use the configuration file named /var/myapp/myapp.conf. 例如,名为/var/myapp/myapp.jar的jar将使用名为/var/myapp/myapp.conf的配置文件。

such as: myapp.conf 例如: myapp.conf

JAVA_OPTS=-Xmx1024M
LOG_FOLDER=/custom/log/folder

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring(Boot)忽略我的log4j.properties文件 - Spring (Boot) ignores my log4j.properties file 记录器无法在Spring Boot 1.5.7中使用log4j.properties打印 - Logger not printing with log4j.properties within Spring Boot 1.5.7 如何使用相同的log4j.properties文件记录两个不同的Spring-Boot应用程序? - How to log with same log4j.properties files for two different Spring-Boot Applications? 如何在不使用绝对路径的情况下使用log4j.properties为Java Web Service创建日志文件 - How to use log4j.properties to create a log file for a Java Web Service without using an absolute path 如何在服务器上使用-Dlog4j.configuration = file:/path/to/log4j.properties运行我的flink作业 - how to run my flink job with -Dlog4j.configuration=file:/path/to/log4j.properties on server 如何在log4j.properties文件中互助追加器属性? - How to mutualize appenders properties in log4j.properties file? 如何将 log4j.properties 文件转换为 log4j2.xml 或 log4j2.properties 文件 - How to convert the log4j.properties file to log4j2.xml or log4j2.properties file 如何根据 Spring 中的参数读取不同的 log4j.properties 文件? - How can I read different log4j.properties file depending on an argument in Spring? log4J没有在Spring Boot Microservice中写入特定的日志文件 - log4J is Not Writing to Specific Log File in Spring Boot Microservice 如何将log4j.properties文件的路径更改为特定路径? - How to change the path of the log4j.properties file to a specific one?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM