Kong 服务和路由的添加

管理服务

这里参考DB-less-Mode,因为使用的是yaml配置文件的形式,所以所有的相关配置只需要往初始化的kong.yml文件中添加就可以了,就像nginx的配置文件

DB-less-Mode

创建服务

vim /etc/kong/kong.yml

yaml 复制代码
services:
- name: my-service  # 服务名称
  url: localhost:8801  # 这里填写backend服务地址
  tags:
   - test-service
  routes:
  - name: ngrok-mep-server  # 路由名称
    paths:
    - /test-service  # 路由后缀名称


# 下面是初始化的建议配置
 services:
 - name: example-service
   url: http://example.com
   # Entities can store tags as metadata
   tags:
   - example
   # Entities that have a foreign-key relationship can be nested:
   routes:
   - name: example-route
     paths:
     - /
   plugins:
   - name: key-auth
 - name: another-service
   url: https://example.org

检查文件

shell 复制代码
kong config -c kong.conf parse kong.yml

Response:

复制代码
parse successful

加载文件

复制代码
kong start -c kong.conf
已启动的使用
kong restart -c kong.conf

校验服务是否正常

我们可以在kong的8000端口后加上路由后缀/test-service查看服务是否正常

复制代码
curl -i localhost:8000/test-service

这里由于项目路径原因显示404,但其实后端已经收到请求了

相关推荐
半旧夜夏1 天前
【Gateway】服务调用和网关配置攻略
java·spring boot·spring cloud·gateway
小坏讲微服务1 天前
Nginx集群与SpringCloud Gateway集成Nacos的配置指南
spring boot·nginx·spring cloud·gateway
小坏讲微服务1 天前
使用 Spring Cloud Gateway 实现集群
java·spring boot·分布式·后端·spring cloud·中间件·gateway
没有bug.的程序员1 天前
Spring Cloud Gateway 路由与过滤器机制
java·开发语言·spring boot·spring·gateway
serendipity_hky3 天前
【微服务 - easy视频 | day01】准备工具+gateway网关及路由至内部服务
java·微服务·架构·gateway·springcloud
三口吃掉你6 天前
微服务之网关(Spring Cloud Gateway)
java·网关·微服务·gateway
余衫马7 天前
微服务SpringCloud报错合集
spring boot·gateway
Zz_waiting.7 天前
统一服务入口-Gateway
java·开发语言·gateway
菲兹园长8 天前
微服务组件(E、L、N、O、G)
linux·服务器·gateway
tuokuac11 天前
依赖spring-cloud-starter-gateway与spring-cloud-gateway-dependencies的区别
java·gateway