网关:
一:apisix
doc:https://apisix.apache.org/zh/docs/apisix/getting-started/README/
github:https://github.com/apache/apisix
二:Kong
github:https://github.com/Kong/kong
三:Ocelot
github:https://github.com/ThreeMammals/Ocelot
四:janus
github:https://github.com/motiv-labs/janus
前置条件:docker,yaml
microservice.yaml
 View Code目前使用docker启动apisix,需要依赖etcd,- etcd:
- container_name: etcd
- hostname: etcd
- image: bitnami/etcd
- volumes:
- - ./etcd/data:/bitnami/etcd
- environment:
- ETCD_ENABLE_V2: "true"
- ALLOW_NONE_AUTHENTICATION: "yes"
- ETCD_ADVERTISE_CLIENT_URLS: "http://etcd:2379" #https://github.com/apache/apisix-dashboard/issues/2756 需要更换为host域名不能使用0.0.0.0
- ETCD_LISTEN_CLIENT_URLS: "http://0.0.0.0:2379"
- ports:
- - "2379:2379/tcp"
- networks:
- caseor_bridge:
- ipv4_address: 172.0.10.8
- apisix:
- container_name: apisix
- hostname: apisix
- image: apache/apisix
- volumes:
- - ./apisix/log:/usr/local/apisix/logs
- - ./apisix/conf/config.yaml:/usr/local/apisix/conf/config.yaml:ro
- depends_on:
- - etcd
- ports:
- - "9088:9088/tcp"
- - "9180:9180/tcp"
- - "127.0.0.1:9090:9090/tcp"
- networks:
- caseor_bridge:
- ipv4_address: 172.0.10.9
-
- apisix-dashboard:
- container_name: apisix-dashboard
- image: apache/apisix-dashboard
- depends_on:
- - etcd
- ports:
- - "9188:9188"
- volumes:
- - ./apisix/conf/dashboard.yaml:/usr/local/apisix-dashboard/conf/conf.yaml
- networks:
- caseor_bridge:
- ipv4_address: 172.0.10.10
复制代码 使用apisix dashboard的时候 会出现一个bug,需要在启动etcd的时候设置ETCD_ADVERTISE_CLIENT_URLS为host域名 而不能使用0.0.0.0
apisix的config yaml
  - apisix:
- node_listen:
- - port: 9088
- enable_ipv6: true
- enable_control: true
- control:
- ip: "[::]"
- port: 9090
- discovery:
- nacos:
- host:
- - "http://172.0.10.7:8848"
- deployment:
- role: traditional
- role_traditional:
- config_provider: etcd
- admin:
- admin_listen:
- port: 9180
- allow_admin:
- - 0.0.0.0/0
- admin_key:
- - name: "admin"
- key: b848941cd4e1003f2f961a7786ecf75f
- role: admin
- - name: "viewer"
- key: dd3bc5bde63f272f554b91336bfcfcb3
- role: viewer
- etcd:
- host:
- - http://etcd:2379
- prefix: /apisix
- timeout: 30
- #plugin_attr:
- # prometheus:
- # export_addr:
- # ip: "0.0.0.0"
- # port: 9091
- #END
复制代码 View Codedashboard的config yaml
  - conf:
- listen:
- host: 0.0.0.0 # `manager api` listening ip or host name
- port: 9188 # `manager api` listening port
- allow_list: # If we don't set any IP list, then any IP access is allowed by default.
- - 0.0.0.0/0
- etcd:
- endpoints: # supports defining multiple etcd host addresses for an etcd cluster
- - "http://etcd:2379"
- # yamllint disable rule:comments-indentation
- # etcd basic auth info
- # username: "root" # ignore etcd username if not enable etcd auth
- # password: "123456" # ignore etcd password if not enable etcd auth
- mtls:
- key_file: "" # Path of your self-signed client side key
- cert_file: "" # Path of your self-signed client side cert
- ca_file: "" # Path of your self-signed ca cert, the CA is used to sign callers' certificates
- # prefix: /apisix # apisix config's prefix in etcd, /apisix by default
- log:
- error_log:
- level: warn # supports levels, lower to higher: debug, info, warn, error, panic, fatal
- file_path:
- logs/error.log # supports relative path, absolute path, standard output
- # such as: logs/error.log, /tmp/logs/error.log, /dev/stdout, /dev/stderr
- access_log:
- file_path:
- logs/access.log # supports relative path, absolute path, standard output
- # such as: logs/access.log, /tmp/logs/access.log, /dev/stdout, /dev/stderr
- # log example: 2020-12-09T16:38:09.039+0800 INFO filter/logging.go:46 /apisix/admin/routes/r1 {"status": 401, "host": "127.0.0.1:9000", "query": "asdfsafd=adf&a=a", "requestId": "3d50ecb8-758c-46d1-af5b-cd9d1c820156", "latency": 0, "remoteIP": "127.0.0.1", "method": "PUT", "errs": []}
- authentication:
- secret:
- secret # secret for jwt token generation.
- # NOTE: Highly recommended to modify this value to protect `manager api`.
- # if it's default value, when `manager api` start, it will generate a random string to replace it.
- expire_time: 3600 # jwt token expire time, in second
- users: # yamllint enable rule:comments-indentation
- - username: admin # username and password for login `manager api`
- password: admin
- - username: user
- password: user
- plugins: # plugin list (sorted in alphabetical order)
- - api-breaker
- - authz-keycloak
- - basic-auth
- - batch-requests
- - consumer-restriction
- - cors
- # - dubbo-proxy
- - echo
- # - error-log-logger
- # - example-plugin
- - fault-injection
- - grpc-transcode
- - hmac-auth
- - http-logger
- - ip-restriction
- - jwt-auth
- - kafka-logger
- - key-auth
- - limit-conn
- - limit-count
- - limit-req
- # - log-rotate
- # - node-status
- - openid-connect
- - prometheus
- - proxy-cache
- - proxy-mirror
- - proxy-rewrite
- - redirect
- - referer-restriction
- - request-id
- - request-validation
- - response-rewrite
- - serverless-post-function
- - serverless-pre-function
- # - skywalking
- - sls-logger
- - syslog
- - tcp-logger
- - udp-logger
- - uri-blocker
- - wolf-rbac
- - zipkin
- - server-info
- - traffic-split
复制代码 View Code在文件夹下启动- docker-compose -f microservice.yaml up
复制代码

本地打开 http://localhost:9188 使用admin ,admin 登录
配置路由信息



这里使用的是nacos作为服务发现,具体查看nacos配置

启动以8083端口的服务- dotnet run --urls=http://*:8083
复制代码
打开浏览器调试下接口

接下来使用网关请求

再启动以8084端口的服务

nacos中出现了两个实例

继续使用网关请求
在log中的access.log 可以查看到网关请求到不同端口的服务


几个注意点:
1.etcd的ETCD_ADVERTISE_CLIENT_URLS 需要更换为host域名不能使用0.0.0.0

2.apisix的nacos配置在 config.yaml中的discovery

尽量使用host名称

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |