Configure the SpringBoot project under Centos8 to start up

Today, the Springboot project is published to the Alibaba Cloud server and can be accessed normally, but the SpringBoot project will hang when the Alibaba Cloud server is restarted. I hope the project will start automatically when the cloud server restarts

1. Write the script to start the jar package with .sh (vi is available without the vim command)

vim start_jar.sh

Press i to enter the editing mode, copy the following content into it

export JAVA_HOME=/usr/local/jre/jre1.8.0_221
export CLASSPATH=$:CLASSPATH:$JAVA_HOME/lib/
export PATH=$PATH:$JAVA_HOME/bin
sleep 30
nohup java -jar /usr/local/jar/test/你的项目jar包.jar > /usr/local/jar/test/启动日志文件.log 2>&1 &

Note: The JAVA_HOME environment path and jar package path inside should be written according to your own situation.
Finally, press esc to exit editing and then : wq to save the file

2. Move the .sh script file you just wrote to the /etc/init.d/ folder

mv start_jar.sh /etc/init.d/jar.sh

3. Authorize the jar.sh file

chmod +x /etc/init.d/jar.sh

4. Modify the /etc/rc.local file

vim /etc/rc.local

5. Add the following information to the last line of the file (the script file and the file just moved)

/etc/init.d/jar.sh

6. Authorize the rc.local file

chmod +x /etc/rc.local 

7. When finished, restart the Alibaba Cloud server and enter the following command to see if the project starts with the server startup

netstat -ntlp | grep 8080 (查看端口)
ps aux|grep java(查看服务)

I hope the big guys point out something wrong! ! !
 

 

Guess you like

Origin blog.csdn.net/qq_43037478/article/details/114857837