springboot 部署jar项目与自启动
1.项目路径
jar包路径:/usr/local/src/apps/govdata.jar
2.启动项目
nohup java -jar govdata.jar &
3.查看项目启动日志
tail -f nohup.out
注:& 表示以后台进程的方式运行jar包
4.配置自启动
使用 /etc/rc.d/rc.local配置,授予rc.local 执行权限
输入命令:
chmod +x /etc/rc.d/rc.local
/usr/local/src/apps/目录下,创建启动文件runJar.sh:
#!/bin/bash export JAVA_HOME=/usr/local/src/jdk1.8.0_161 export JRE_HOME=/usr/local/src/jdk1.8.0_161/jre export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$PATH cd /usr/local/src/apps/ nohup java -jar govdata.jar >govdata.log 1>&1 & nohup java -jar uums.jar >uums.log 1>&1 &
赋予runJar.sh执行权限:
chmod +x /usr/local/src/apps/runJar.sh
编辑rc.local文件:
vi /etc/rc.d/rc.local
#!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using this file. # # In contrast to previous versions due to parallel execution during boot # this script will NOT be run after all other services. # # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure # that this script will be executed during boot. touch /var/lock/subsys/local
/usr/local/src/apps/runJar2.sh
注意最后一行 加入我们的启动文件,然后重启服务器:
[root@localhost ~]# reboot