前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ShenYu 网关开发:在本地启用运行

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

作者头像
晓晨
发布2022-09-01 16:17:11
1K0
发布2022-09-01 16:17:11
举报
文章被收录于专栏:晓晨的专栏晓晨的专栏

1.先决条件

无论什么方式安装,都需要先初始化数据库,这里我选择了在本地通过 Docker 启用一个 mysql 5.7

代码语言:javascript
复制
docker run -d \
  --name mysql \
  -p 3306:3306 \
  -e MYSQL_ROOT_PASSWORD=xyzj1a2y3 \
  -e TZ=Asia/Shanghai \
  mysql:5.7

启动以后,可以通过数据库管理软件进行连接 localhost:3306 用户名和密码都是 root。

然后根据文档执行 mysql 数据库初始化,我是直接通过数据库管理软件执行的 sql。执行成功以后创建一个 shenyu 数据库,并且会创建一些表并插入必须数据。

image-20220701023537365
image-20220701023537365

2.本地部署

文档:https://shenyu.apache.org/zh/docs/deployment/deployment-local

Clone 代码到本地

代码语言:javascript
复制
git clone https://github.com/apache/incubator-shenyu.git
cd incubator-shenyu
mvn clean install -Dmaven.javadoc.skip=true -B -Drat.skip=true -Djacoco.skip=true -DskipITs -DskipTests

配置 Mysql

代码语言:javascript
复制
cd shenyu-admin/src/main/resources

application-mysql.yml:

代码语言:javascript
复制
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

shenyu:
  database:
    dialect: mysql
    init_enable: true

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/shenyu?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull
    username: root
    password: xyzj1a2y3
    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

image-20220701031344257
image-20220701031344257

3.运行测试

ShenYu 提供了多方方式接入网关,直接在 UI 操作,通过 client 接入,client 又分为 http、nacos、zookeeper 等等。这里我是用了 client http 的方式接入。

我运行的是 dotnet client 仓库提供的 example,注册成功后可以在 Admin 界面查询到 selector 信息:

image-20220701161104529
image-20220701161104529

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

image-20220701161226958
image-20220701161226958

可以看到成功进行了调用

独立博客:https://xcmaster.com/posts/64946.html

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022-07-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1.先决条件
  • 2.本地部署
  • 3.运行测试
相关产品与服务
数据库管理
数据库管理(Database Management Center,DMC)是一个高效,安全,可靠的数据库一站式管理平台。DMC 提供可视化的库管理、实例会话管理、SQL 窗口、SQL 安全审计、SQL 变更审批、实时监控、操作审计等数据库管理能力,集成诊断优化和数据可视化分析能力,从而简化和规范数据库管理操作、降低数据库运维门槛、提升运维效率。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档