springcloud gateway 项目打包部署运行
新建一个springboot项目然后做了一个小demo跳转到baidu
pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.drawnblue</groupId>
<artifactId>pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.drawblue</groupId>
<artifactId>gateway</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>gateway</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>0.9.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>bundle</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${basedir}/src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build> </project>
其中项目同其他随笔上的pom项目,由于springcloud gateway 不能在tomcat运行,所以一定要注释掉web依赖
属性文件:
spring:
application:
name: gateway
cloud:
nacos:
discovery:
server-addr: 192.168.135.129:8848
gateway:
routes:
- id: test-gateway
uri: http://www.baidu.com
predicates:
- Path=/test/**
filters:
- StripPrefix=1
server:
port: 8800
我将该项目注册在nacos上,另外注意
- StripPrefix=1不加的话就会报错,因为跳转后有前缀导致跳转错误不能跳转到百度
本项目搞的是个demo,nacos上没有其他服务,所以启动类上可以不加任何注解去发现注册到nacos上的服务
项目结构如下:

assembly.xml
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<!-- 不配置会报错:Assembly ID must be present and non-empty -->
<id>bin</id>
<formats>
<!--压缩文件的类型-->
<format>tar.gz</format>
</formats>
<!--指明打包后是否有分发包的最外层,如果不写,默认是true-->
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<!--需要包含的文件与输出的路径-->
<fileSet>
<!--指明要对src/main/assembly/bin文件夹操作-->
<directory>src/main/assembly/bin</directory>
<!--指明经过assembly插件打包后bin目录会放置在项目根目录下-->
<outputDirectory>bin</outputDirectory>
<!--指明bin目录下所有文件的权限为755-->
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include></include>
</includes>
<outputDirectory>conf</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
start.sh
#!/bin/bash cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR=`pwd`
SERVER_NAME=gateway
JAR_File=$DEPLOY_DIR/lib/gateway-0.0.1-SNAPSHOT.jar echo " " PIDS=`ps -ef | grep java | grep "$JAR_File" |awk '{print $2}'`
if [ -n "$PIDS" ]; then
echo "ERROR: The server $SERVER_NAME already started!"
echo "PID: $PIDS"
echo " "
exit 1
fi LOGS_DIR=$DEPLOY_DIR/logs if [ ! -d $LOGS_DIR ]; then
mkdir $LOGS_DIR
fi STDOUT_FILE=$LOGS_DIR/stdout.log JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "
JAVA_DEBUG_OPTS=""
if [ "$1" = "debug" ]; then
JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "
fi
JAVA_JMX_OPTS=""
if [ "$1" = "jmx" ]; then
JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "
fi
JAVA_MEM_OPTS=""
BITS=`java -version 2>&1 | grep -i 64-bit`
if [ -n "$BITS" ]; then
JAVA_MEM_OPTS=" -server -Xmx2g -Xms2g -Xmn256m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "
else
JAVA_MEM_OPTS=" -server -Xms1g -Xmx1g -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "
fi echo -e "Starting the server $SERVER_NAME ...\c"
nohup java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -jar $JAR_File -Ddubbo.application.logger=slf4j > $STDOUT_FILE 2>&1 & echo "OK!"
PIDS=`ps -ef | grep java | grep "$JAR_File" | awk '{print $2}'`
echo "Server $SERVER_NAME startup, PID: $PIDS"
echo "STDOUT: $STDOUT_FILE"
echo " "
restart.sh
#!/bin/bash
cd `dirname $0`
./stop.sh
./start.sh
stop.sh
#!/bin/bash cd `dirname $0`
cd ..
DEPLOY_DIR=`pwd` SERVER_NAME=gateway
JAR_File=$DEPLOY_DIR/lib/gateway-0.0.1-SNAPSHOT.jar echo " " PIDS=`ps -ef | grep java | grep "$JAR_File" |awk '{print $2}'`
if [ -z "$PIDS" ]; then
echo "ERROR: The server $SERVER_NAME does not started!"
echo " "
exit 1
fi echo -e "Stopping the server $SERVER_NAME ...\c"
for PID in $PIDS ; do
kill $PID > /dev/null 2>&1
done COUNT=0
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1 PIDS=`ps -ef | grep java | grep "$JAR_File" |awk '{print $2}'`
if [ -z "$PIDS" ]; then
COUNT=2
fi
done echo "OK!"
echo " "
status.sh
#!/bin/bash cd `dirname $0`
cd ..
DEPLOY_DIR=`pwd` SERVER_NAME=gateway
JAR_File=$DEPLOY_DIR/lib/gateway-0.0.1-SNAPSHOT.jar echo " " PIDS=`ps -ef | grep java | grep "$JAR_File" |awk '{print $2}'`
if [ -n "$PIDS" ]; then
echo "The server $SERVER_NAME is running!"
echo "PID: $PIDS"
echo " "
exit 1
fi if [ -z "$PIDS" ]; then
echo "The server $SERVER_NAME is stop!"
echo " "
exit 1
fi
stop.sh
#!/bin/bash cd `dirname $0`
cd ..
DEPLOY_DIR=`pwd` SERVER_NAME=gateway
JAR_File=$DEPLOY_DIR/lib/gateway-0.0.1-SNAPSHOT.jar echo " " PIDS=`ps -ef | grep java | grep "$JAR_File" |awk '{print $2}'`
if [ -z "$PIDS" ]; then
echo "ERROR: The server $SERVER_NAME does not started!"
echo " "
exit 1
fi echo -e "Stopping the server $SERVER_NAME ...\c"
for PID in $PIDS ; do
kill $PID > /dev/null 2>&1
done COUNT=0
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1 PIDS=`ps -ef | grep java | grep "$JAR_File" |awk '{print $2}'`
if [ -z "$PIDS" ]; then
COUNT=2
fi
done echo "OK!"
echo " "
打包后target目录

部署项目
将tar.gz部署到linux上解压,进入bin文件启动,启动后,开放端口,然后再重新加载一下

注意:启动时候要确保nacos已经启动且端口可以访问
然后查看nacos

浏览器中输入:http://192.168.135.130:8800/test,回车
然后看到跳转至百度页面

springcloud gateway 项目打包部署运行的更多相关文章
- Spring Boot + Spring Cloud 实现权限管理系统 后端篇(十四):项目打包部署
项目打包部署 安装MySQL镜像 注意:如果使用docker镜像安装MySQL,也需要在前端部署主机安装MySQL,因为备份还原功能是使用MySQL的本地命令进行操作的. 下载镜像 执行以下命令,拉取 ...
- idea14导入eclipse项目并部署运行完整步骤
idea14导入eclipse项目并部署运行完整步骤 2015年05月12日 14:08:04 阅读数:40456 首先说明一下:idea里的project相当于eclipse里的workspace, ...
- 如何将Spring Boot项目打包部署到外部Tomcat
1.项目打包 项目开发结束后,需要打包部署到外部服务器的Tomcat上,主要有几种方式. (1)生成jar包 cd 项目跟目录(和pom.xml同级)mvn clean package## 或 ...
- idea新建项目打包 ,运行jar,并放入maven仓库
1.新建项目(转自:http://www.cnblogs.com/wql025/p/5215570.html) 创建一个新Maven项目 new 一个project 不选择任何Maven模板 起个Gr ...
- yo angualr-fullstatck 项目打包部署
yoeman使用grunt进行打包部署,直接运行grunt命令即可,期间会对代码进行检查,如果存在不规范的地方jshint会指定出来. grunt会对静态资源进行打包而且对资源文件名进行了MD5作为版 ...
- 【转】vue项目打包部署——nginx代理访问
我又来了,今天部署了下vue项目,使用nginx做了代理,这样可以解决跨域的问题,这里做一个简单讲解. 1.先看vue项目打包(我这里使用的是vscode开发工具) 这里是我的项目结构: 打包之前需要 ...
- vue项目 打包部署上线
1. npm run dev:本地开发的时候做调试用的. 2. npm run build:打包部署上线,生成一个 dist 文件夹. 注意:用 npm run build 时,常遇到因引用路径不对导 ...
- java项目打包部署
网上打包的教程很多, 但是自己动手总归出现各种各样的问题,自己总结下: 由于刚刚接触JAVA,做了一个简单的java project 项目, 但是包含第三方的jar包, 结果打包的时候就出现问题了. ...
- 使用cmd命令创建maven(web)项目+项目转换成IDEA项目+项目打包+Jetty运行Web项目
3条件:配置好环境 配置环境教程:https://www.cnblogs.com/weibanggang/p/9623705.html 第一步:查看版本信息,在cmd输入mvn –version,如果 ...
随机推荐
- Vue组件介绍及开发
一. 通过axios实现数据请求 1.json json是 JavaScript Object Notation 的首字母缩写,单词的意思是javascript对象表示法,这里说的json指的是类似于 ...
- python学习之HTML
1.HTML初知 <!DOCTYPE html> <html lang="en"> <head> html头 <meta charset= ...
- Hibernate学习(五)
自关联测试案例 1.创建表 drop table if exists t_category ; create table t_category ( id ) primary key , name ) ...
- 文件的读取与保存(try-with-resource优雅关闭)
借鉴:https://www.cnblogs.com/itZhy/p/7636615.html 一.背景 在Java编程过程中,如果打开了外部资源(文件.数据库连接.网络连接等),我们必须在这些外部资 ...
- Algorightm----DynamicProgramming
参考资料: 1. 告别动态规划,连刷40道动规算法题,我总结了动规的套路
- Linux OS 集群 免密登录
1. ssh-keygen 生成密钥 2. ssh-copy-id 集群主机名 参考: [图文详解]linux下配置远程免密登录
- Java语言特性、加载与执行
[开源.免费.纯面向对象.跨平台] 简单性: 相对而言,例如,Java是不支持多继承的,C++是支持多继承的,多继承比较复杂:C++ 有指针,Java屏蔽了指针的概念.所以相对来说Java是简单的. ...
- 深度学习之父低调开源 CapsNet,欲取代 CNN
“卷积神经网络(CNN)的时代已经过去了!” ——Geoffrey Hinton 酝酿许久,深度学习之父Geoffrey Hinton在10月份发表了备受瞩目的Capsule Networks(Cap ...
- [阿里移动推荐算法]比赛_快速入门_4_19_update_仅供参考,思维不要受局限
[这里只讲快速入门——即破题,正负样本不平衡.特征数量等问题就自己多看论文或者其他资料吧~~如果还有数据挖掘相关基础知识不了解的,建议看看<数据挖掘导论>] [以下是理解错误案例]:错误的 ...
- springboot2.0集成RestTemplate
实际集成 获取restTemplate实例,封装方法 package com.quant.api.utils.restTemplate; import org.springframework.http ...