ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2022-07-01 16:33:54  阅读:199  来源: 互联网

标签:网关 shenyu License 启用 under mysql apache ShenYu true


1.先决条件

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

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

2.本地部署

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

Clone 代码到本地

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

cd shenyu-admin/src/main/resources

application-mysql.yml:

# 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

3.运行测试

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

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

image-20220701161104529

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

image-20220701161226958

可以看到成功进行了调用

标签:网关,shenyu,License,启用,under,mysql,apache,ShenYu,true
来源: https://www.cnblogs.com/stulzq/p/16435077.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有