ShenYu 网关开发:在本地启用运行

打印 上一主题 下一主题

主题 893|帖子 893|积分 2679

1.先决条件

无论什么方式安装,都需要先初始化数据库,这里我选择了在本地通过 Docker 启用一个 mysql 5.7
  1. docker run -d \
  2.   --name mysql \
  3.   -p 3306:3306 \
  4.   -e MYSQL_ROOT_PASSWORD=xyzj1a2y3 \
  5.   -e TZ=Asia/Shanghai \
  6.   mysql:5.7
复制代码
启动以后,可以通过数据库管理软件进行连接 localhost:3306 用户名和密码都是 root。
然后根据文档执行 mysql 数据库初始化,我是直接通过数据库管理软件执行的 sql。执行成功以后创建一个 shenyu 数据库,并且会创建一些表并插入必须数据。

2.本地部署

文档:https://shenyu.apache.org/zh/docs/deployment/deployment-local
Clone 代码到本地
  1. git clone https://github.com/apache/incubator-shenyu.git
  2. cd incubator-shenyu
  3. mvn clean install -Dmaven.javadoc.skip=true -B -Drat.skip=true -Djacoco.skip=true -DskipITs -DskipTests
复制代码
配置 Mysql
  1. cd shenyu-admin/src/main/resources
复制代码
application-mysql.yml:
  1. # Licensed to the Apache Software Foundation (ASF) under one or more
  2. # contributor license agreements.  See the NOTICE file distributed with
  3. # this work for additional information regarding copyright ownership.
  4. # The ASF licenses this file to You under the Apache License, Version 2.0
  5. # (the "License"); you may not use this file except in compliance with
  6. # the License.  You may obtain a copy of the License at
  7. #
  8. #     http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. shenyu:
  16.   database:
  17.     dialect: mysql
  18.     init_enable: true
  19. spring:
  20.   datasource:
  21.     url: jdbc:mysql://localhost:3306/shenyu?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull
  22.     username: root
  23.     password: xyzj1a2y3
  24.     driver-class-name: com.mysql.cj.jdbc.Driver
复制代码
启动 ShenYu Admin
使用 IDE 启动 org.apache.shenyu.admin.ShenyuAdminBootstrap 并配置参数 --spring.profiles.active = mysql。
启用 ShenYu Bootstrap
使用 IDE 启动 org.apache.shenyu.bootstrap.ShenyuBootstrapApplication
访问 Admin
访问 http://localhost:9095 ,默认用户名密码分别为 admin 和 123456

3.运行测试

ShenYu 提供了多方方式接入网关,直接在 UI 操作,通过 client 接入,client 又分为 http、nacos、zookeeper 等等。这里我是用了 client http 的方式接入。
我运行的是 dotnet client 仓库提供的 example,注册成功后可以在 Admin 界面查询到 selector 信息:

然后采用 postman 调用测试,需要注意的是 9095 端口是 admin 端口,9195 才是网关的端口:

可以看到成功进行了调用
独立博客:https://xcmaster.com/posts/64946.html
    声明:原创博客请在转载时保留原文链接或者在文章开头加上本人博客地址,如发现错误,欢迎批评指正。凡是转载于本人的文章,不能设置打赏功能,如有特殊需求请与本人联系!</strong>
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

惊雷无声

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表