1采盒、將SpringBoot項(xiàng)目打包成jar旧乞,詳見(jiàn) eclipse中,將springboot項(xiàng)目打成jar包
2磅氨、將jar包復(fù)制到CentOS系統(tǒng)中尺栖,可參考 CentOS7掛載windows下的共享文件夾
3、關(guān)閉CentOS防火墻
CentOS 7.0默認(rèn)使用的是firewall作為防火墻
查看防火墻狀態(tài)
firewall-cmd --state
停止firewall
systemctl stop firewalld.service
禁止firewall開(kāi)機(jī)啟動(dòng)
systemctl disable firewalld.service
開(kāi)機(jī)啟用firewall
systemctl enable firewalld.service
4烦租、新建SpringBoot服務(wù)
1) 進(jìn)入/etc/systemd/system目錄
cd /etc/systemd/system
2) 創(chuàng)建服務(wù)
touch hello.service
3) 服務(wù)設(shè)置延赌,往“hello.service”添加如下內(nèi)容
根據(jù)自己的情況修改 Description 和 ExecStart 的內(nèi)容除盏,其中 java -jar xxx.jar 是啟動(dòng)服務(wù)的關(guān)鍵。
[Unit]
Description=hello
After=syslog.target
[Service]
ExecStart=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64/bin/java -jar /usr/local/apps/hello-0.0.1-SNAPSHOT.jar
[Install]
WantedBy=multi-user.target
5.服務(wù)操作
啟動(dòng)服務(wù)
systemctl start hello
or
systemctl start hello.service
停止服務(wù)
systemctl stop hello
or
systemctl stop hello.service
服務(wù)狀態(tài)
systemctl status hello
or
systemctl status hello.service
開(kāi)機(jī)啟動(dòng)
systemctl enable hello
or
systemctl enable hello.service
項(xiàng)目日志
journalctl -u hello
or
journalctl -u hello.service