博客
关于我
使用envoy组网.netcore微服务
阅读量:378 次
发布时间:2019-03-05

本文共 6343 字,大约阅读时间需要 21 分钟。

eShopOnContainers-dev部署指南

1. 下载并配置Envoy代理

下载开源项目

eShopOnContainers-dev克隆至本地环境,提取src/ApiGateways/Envoy/config/mobileshopping/envoy.yaml文件并修改配置:

  • 80端口改为86
  • 8001改为9901,避免端口冲突。

部署步骤

  • 将文件拷贝至服务器路径 /application/envoyconfig/envoy.yaml
  • 使用命令验证配置文件:
    cd /application/envoyconfigenvoy -c envoy.yaml --mode validate
  • 部署Envoy代理并初始化日志:
    envoy -c envoy.yaml --bootstrap-version 2 --log-path logs/custom2.log
  • 打开防火墙端口:
    firewall-cmd --zone=public --add-port=9901/tcp --permanentfirewall-cmd --zone=public --add-port=86/tcp --permanentfirewall-cmd --reload
  • 2. 新建NetCore项目

    项目创建

    创建一个新的NetCore项目,命名为Ali.Mi.Demo,并添加以下控制器:

    • CatalogApiController:定义API端点,访问地址为https://localhost:5008/catalog-api/catalogs
    • BasketController:处理购物 basket逻辑。
    • OrderingController:实现订单管理功能。

    项目配置

    修改envoy.yaml文件,添加以下路由配置:

    admin:  access_log_path: "/dev/null"  address:    socket_address:      address: 0.0.0.0      port_value: 9901static_resources:  listeners:    - address:        socket_address:          address: 0.0.0.0          port_value: 86        filter_chains:          - filters:            - name: envoy.http_connection_manager              config:                codec_type: auto                stat_prefix: ingress_http                route_config:                  name: eshop_backend_route                  virtual_hosts:                    - name: eshop_backend                      domains:                        - "*"                      routes:                        - name: c-short                          match:                            prefix: "/c/"                          route:                            auto_host_rewrite: true                            prefix_rewrite: "/catalog-api/"                            cluster: catalog                        - name: c-long                          match:                            prefix: "/catalog-api/"                          route:                            auto_host_rewrite: true                            cluster: catalog                        - name: o-short                          match:                            prefix: "/o/"                          route:                            auto_host_rewrite: true                            prefix_rewrite: "/ordering-api/"                            cluster: ordering                        - name: o-long                          match:                            prefix: "/ordering-api/"                          route:                            auto_host_rewrite: true                            cluster: ordering                        - name: h-long                          match:                            prefix: "/hub/notificationhub"                          route:                            auto_host_rewrite: true                            cluster: signalr-hub                            timeout: 300s                        - name: b-short                          match:                            prefix: "/b/"                          route:                            auto_host_rewrite: true                            prefix_rewrite: "/basket-api/"                            cluster: basket                        - name: b-long                          match:                            prefix: "/basket-api/"                          route:                            auto_host_rewrite: true                            cluster: basket                        - name: agg                          match:                            prefix: "/"                          route:                            auto_host_rewrite: true                            prefix_rewrite: "/"                            cluster: shoppingagg              http_filters:                - name: envoy.router              access_log:                - name: envoy.file_access_log                  filter:                    not_health_check_filter: {}                  config:                    json_format:                      time: "%START_TIME%"                      protocol: "%PROTOCOL%"                      duration: "%DURATION%"                      request_method: "%REQ(:METHOD)%"                      request_host: "%REQ(HOST)%"                      path: "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%"                      response_flags: "%RESPONSE_FLAGS%"                      route_name: "%ROUTE_NAME%"                      upstream_host: "%UPSTREAM_HOST%"                      upstream_cluster: "%UPSTREAM_CLUSTER%"                      upstream_local_address: "%UPSTREAM_LOCAL_ADDRESS%"                    path: "/tmp/access.log"              clusters:                - name: shoppingagg                  connect_timeout: 0.25s                  type: strict_dns                  lb_policy: round_robin                  hosts:                    - socket_address:                        address: webshoppingagg                        port_value: 86                - name: catalog                  connect_timeout: 0.25s                  type: strict_dns                  lb_policy: round_robin                  hosts:                    - socket_address:                        address: 192.168.1.106                        port_value: 5008                - name: basket                  connect_timeout: 0.25s                  type: strict_dns                  lb_policy: round_robin                  hosts:                    - socket_address:                        address: basket-api                        port_value: 86                - name: ordering                  connect_timeout: 0.25s                  type: strict_dns                  lb_policy: round_robin                  hosts:                    - socket_address:                        address: ordering-api                        port_value: 86                - name: signalr-hub                  connect_timeout: 0.25s                  type: strict_dns                  lb_policy: round_robin                  hosts:                    - socket_address:                        address: ordering-signalrhub                        port_value: 86

    3. 启动NetCore项目

    项目运行

  • 进入项目目录:
    cd /data/wwwroot/Ali.Mi.Demo
  • 使用命令启动服务:
    dotnet Ali.Mi.Demo.dll --urls="http://*:5008"
  • 防火墙配置

    确保防火墙允许以下端口:

    firewall-cmd --zone=public --add-port=5008/tcp --permanentfirewall-cmd --reload

    4. 浏览器访问

    直接访问API

    访问地址:http://192.168.1.106:5008/catalog-api/catalogs

    通过Envoy代理访问

    访问地址:http://192.168.1.106:86/c/catalogs

    转载地址:http://hwuwz.baihongyu.com/

    你可能感兴趣的文章
    mysql where中如何判断不为空
    查看>>
    MySQL Workbench 使用手册:从入门到精通
    查看>>
    mysql workbench6.3.5_MySQL Workbench
    查看>>
    MySQL Workbench安装教程以及菜单汉化
    查看>>
    MySQL Xtrabackup 安装、备份、恢复
    查看>>
    mysql [Err] 1436 - Thread stack overrun: 129464 bytes used of a 286720 byte stack, and 160000 bytes
    查看>>
    MySQL _ MySQL常用操作
    查看>>
    MySQL – 导出数据成csv
    查看>>
    MySQL —— 在CentOS9下安装MySQL
    查看>>
    MySQL —— 视图
    查看>>
    mysql 不区分大小写
    查看>>
    mysql 两列互转
    查看>>
    MySQL 中开启二进制日志(Binlog)
    查看>>
    MySQL 中文问题
    查看>>
    MySQL 中日志的面试题总结
    查看>>
    mysql 中的all,5分钟了解MySQL5.7中union all用法的黑科技
    查看>>
    MySQL 中的外键检查设置:SET FOREIGN_KEY_CHECKS = 1
    查看>>
    Mysql 中的日期时间字符串查询
    查看>>
    mysql 中索引的问题
    查看>>
    MySQL 中锁的面试题总结
    查看>>