Spring boot application service installation and deployment (maven project)
1. First introduce the following tags in the pom file of the maven project and save
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
In this way, the Spring boot project can be packaged into an executable jar package
Open the windows cmd or linux command line to execute the typed executable jar package with the following command
java -jar abcd.jar can execute the spring boot application
2. Edit and install the linux service installation file
I edited it with notepad in the windows environment and then uploaded it to the centos7 system
(1) First create a notepad file
(2) Write the following statement for the convenience of pasting directly on the text
[Unit] Description=abcd service After=syslog.target [Service] Type=simple ExecStart= /usr/bin/java -jar /home/app/abcd.jar [Install] WantedBy=multi-user.target
illustrate
Description Service description
/usr/bin/java java path (I am an absolute path here, you can use other executable java paths)
/home/app/abcd.jar Path to executable jar package Then save the text file with the extension .service After the above file is saved, it can be abcd.service 3. Upload the executable jar package and the .service installation file Upload the jar package program file to a custom location (we will define a folder called app under each system user to save the jar package in this folder) Upload the .service file to the /etc/systemd/system directory of the system (I am using the centos7 system, other systems are similar and different as appropriate) (if you are proficient in linux text editing, you can directly create a file for editing) Note that the encoding should be consistent (to verify whether it is consistent, just open the .service file on the linux server to see if it is consistent with windows and whether there are garbled characters) 4. Execute the following command on the deployment server (centos7) First sudo systemctl daemon-reload refresh the service configuration file Then sudo systemctl enable abcd.service to set boot restart (depending on the situation) Then sudo systemctl start abcd.service to start the service 5. View the log sudo journalctl -u abcd.service The above linux operations are basically the same as other versions of the system under centos7, but the commands are different In this way, the deployment can avoid the problem of multiple project paths caused by the deployment of war packages, and also supports the spring cloud registry (in fact, it is mainly for the use of the spring cloud registry)