在linux中怎样同时运行三个微服务保证退出时不会终止

前言

1.maven中打jar包

使用插件打包,必须在pom.xml中添加插件,否则不能在linux中编译运行

复制代码
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.1.1.RELEASE</version>
                <configuration>
                    <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <warName>${project.artifactId}</warName>
                </configuration>
            </plugin>
        </plugins>
        <finalName>${project.artifactId}</finalName>
    </build>

2.将在maven中打包好的文件存放在linux的指定目录中

3.使用命令启动jar包,同时创建记录日志的文件(在此使用三个微服务为例),只需更换为自己的jar包名称

shop-gateway.jar, shop-order-server.jar, shop-product-server.jar

nohup java -jar shop-gateway.jar > gateway.log 2>&1 & nohup java -jar shop-order-server.jar > order.log 2>&1 & nohup java -jar shop-product-server.jar > product.log 2>&1

4.先使用命'netstat -ntlp'查看是否服务占用了端口,若占用了端口说明启动成功

5.使用vim任意进入一个日志文件查看是否有内容,有内容代表启动成功

相关推荐
fanly1110 小时前
Surging AI Agent 完整产品介绍
微服务·microservice
tntxia11 小时前
linux curl命令详解_curl详解
linux
扛枪的书生13 小时前
Linux 网络管理器用法速查
linux
SkyWalking中文站15 小时前
认识 Horizon UI · 1/17:SkyWalking 新一代可观测性控制台
运维·前端·监控
顺风尿一寸16 小时前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
雪梨酱QAQ18 小时前
Kubeneters HA Cluster部署
运维
江华森1 天前
Spring Cloud 微服务全栈实战:从 Eureka 到 Docker Compose 一文贯通
运维
江华森1 天前
Matplotlib 数据绘图基础入门
运维
XIAOHEZIcode1 天前
Ubuntu 终端美化全栈指南:Bash 到 Kitty 踩坑实录
linux·ubuntu·命令行
江华森1 天前
NumPy 数值计算基础入门
运维