文章目录
Linux发布Spring Boot项目
一、CentOS7虚拟机环境
- CentOS7
- JDK 1.8.0_331
- MySQL 8.0.18
1、清理后打包项目
2、上传jar到Linux中
[root@mycentos7 ~]# ll
总用量 30276
-rw-r--r--. 1 root root 30998612 9月 3 13:36 day63_springboot_ssmp-0.0.1-SNAPSHOT.jar
3、查看IP
// 查看IP为:192.168.8.136
[root@mycentos7 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.8.136 netmask 255.255.255.0 broadcast 192.168.8.255
inet6 fe80::8962:9acc:7179:e2f2 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:ca:f5:b2 txqueuelen 1000 (Ethernet)
RX packets 1671096 bytes 2372855953 (2.2 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 236520 bytes 31727598 (30.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 200 bytes 39477 (38.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 200 bytes 39477 (38.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:7d:f7:90 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
4、关闭防火墙
// 关闭防火墙
[root@mycentos7 jar]# systemctl stop firewalld
5、运行jar包
[root@mycentos7 jar]# java -jar day63_springboot_ssmp-0.0.1-SNAPSHOT.jar
6、浏览器访问
- http://192.168.8.136/pages/books.html
二、真实服务器环境
4、需要开启端口
- 这里开启的端口是 9000
// 查看防火墙状态
[root@VM-20-13-centos bin]# systemctl status firewalld
// 开启9000端口
[root@VM-20-13-centos sgz]# firewall-cmd --zone=public --add-port=9000/tcp --permanent
success
// 重启防火墙
[root@VM-20-13-centos sgz]# systemctl restart firewalld.service
// 查看所有的开启端口
[root@VM-20-13-centos sgz]# firewall-cmd --list-ports
20/tcp 21/tcp 22/tcp 80/tcp 888/tcp 8888/tcp 9000/tcp 39000-40000/tcp
// 查看全部信息
[root@VM-20-13-centos bin]# firewall-cmd --list-all
三、后台运行
- nohup java -jar xxx.jar > server.log 2>&1 &
[root@mycentos7 ~]# nohup java -jar day63_springboot_ssmp-0.0.1-SNAPSHOT.jar > server.log 2>&1 &
[1] 3764