61 lines
4.9 KiB
HTML
61 lines
4.9 KiB
HTML
<p>jar文件发布:</p>
|
||
<p>准备工作:</p>
|
||
<p>发布在springboot项目中的pom.xml文件添加如下:</p>
|
||
<div class="cnblogs_code">
|
||
<pre><span style="color: #0000ff;"><</span><span style="color: #800000;">build</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">plugins</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">plugin</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>org.springframework.boot<span style="color: #0000ff;"></</span><span style="color: #800000;">groupId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>spring-boot-maven-plugin<span style="color: #0000ff;"></</span><span style="color: #800000;">artifactId</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">configuration</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"><</span><span style="color: #800000;">executable</span><span style="color: #0000ff;">></span>true<span style="color: #0000ff;"></</span><span style="color: #800000;">executable</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">configuration</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">plugin</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">plugins</span><span style="color: #0000ff;">></span>
|
||
<span style="color: #0000ff;"></</span><span style="color: #800000;">build</span><span style="color: #0000ff;">></span></pre>
|
||
</div>
|
||
<p> </p>
|
||
<p>一、正常启动:</p>
|
||
<p>后台运行,关闭远程后不会自动退出:nohup java -jar demo-1.0.1.jar >msg.log &</p>
|
||
<p>后面msg.log为运行日志</p>
|
||
<p>查看8080端口是否已使用:netstat -lanp|grep 8080</p>
|
||
<p>查看java进程: ps -ef | grep java </p>
|
||
<p>停止java进程: kill -9 进程ID</p>
|
||
<p> </p>
|
||
<p>二、添加软连接以service方式启动</p>
|
||
<p>打开ssh运行:ln -sb 原文件 /etc/init.d/服务名</p>
|
||
<p>日志可到 <span class="cnblogs_code">/var/log/服务名</span> 查看</p>
|
||
<p>设置权限:chmod 777 服务名</p>
|
||
<p>服务启动停止查看状态命令:service 服务名 start|stop|status|restart</p>
|
||
<p>使用自定义的.conf文件来变更默认配置,在jar包相同路径下创建一个.conf文件,名称应该与.jar的名称相同</p>
|
||
<div class="cnblogs_code">
|
||
<pre>JAVA_HOME=<span style="color: #000000;">/usr/local/jdk
|
||
JAVA_OPTS</span>=<span style="color: #000000;">-Xmx1024M
|
||
LOG_FOLDER</span>=/data/logs/myapp</pre>
|
||
</div>
|
||
<p> </p>
|
||
<p>三、添加系统服务,开机自动启动</p>
|
||
<p>切换目录:cd /ets/systemd/system</p>
|
||
<p>添加文件:服务名.service</p>
|
||
<p>文件内容如下:</p>
|
||
<div class="cnblogs_code">
|
||
<pre><span style="color: #800000; font-weight: bold;">[</span><span style="color: #800000;">Unit</span><span style="color: #800000; font-weight: bold;">]</span><span style="color: #000000;">
|
||
Description</span>=描述<span style="color: #000000;">
|
||
After</span>=<span style="color: #000000;">network.target
|
||
|
||
</span><span style="color: #800000; font-weight: bold;">[</span><span style="color: #800000;">Service</span><span style="color: #800000; font-weight: bold;">]</span><span style="color: #000000;">
|
||
WorkingDirectory</span>=<span style="color: #000000;">/root/api
|
||
ExecStart</span>=/usr/bin/java <span style="color: #000000;">-jar /root/api/ROOT.jar
|
||
ExecStop</span>=<span style="color: #000000;">kill $MAINPID
|
||
Restart</span>=<span style="color: #000000;">always
|
||
|
||
</span><span style="color: #800000; font-weight: bold;">[</span><span style="color: #800000;">Install</span><span style="color: #800000; font-weight: bold;">]</span><span style="color: #000000;">
|
||
WantedBy</span>=multi-user.target</pre>
|
||
</div>
|
||
<p>如不知道java安装目录可运行:which java</p>
|
||
<p>重新加载服务:systemctl daemon-reload</p>
|
||
<p>运行服务:systemctl start 服务名</p>
|
||
<p>查看日志:journalctl -u 服务名</p>
|
||
<p>查看、停止服务状态: <span class="cnblogs_code">systemctl stop 服务名</span> 、 <span class="cnblogs_code">systemctl status 服务名</span> 、 <span class="cnblogs_code">systemctl restart 服务名</span> </p>
|
||
<p><span><span>设置开机启动和禁止开机启动: <span class="cnblogs_code">systemctl enable 服务名</span> 、 <span class="cnblogs_code">systemctl disable 服务名</span> </span></span></p>
|
||
<p> </p> |