网关属性配置
本篇主要讲解如何在 Apache Shenyu 网关配置 ShenYu 的相关属性。
属性配置
shenyu:
netty:
tcp:
webServerFactoryEnabled: true
selectCount: 1
workerCount: 4
serverSocketChannel:
soRcvBuf: 87380
soBackLog: 128
soReuseAddr: true
connectTimeoutMillis: 30000
writeBufferHighWaterMark: 65536
writeBufferLowWaterMark: 32768
writeSpinCount: 16
autoRead: false
allocType: "pooled"
socketChannel:
soKeepAlive: false
soReuseAddr: false
soLinger: -1
tcpNoDelay: true
soRcvBuf: 87380
soSndBuf: 16384
ipTos: 0
allowHalfClosure: false
connectTimeoutMillis: 30000
writeBufferHighWaterMark: 65536
writeBufferLowWaterMark: 32768
writeSpinCount: 16
autoRead: false
allocType: "pooled"
instance:
enabled: false
registerType: zookeeper #etcd #consul
serverLists: localhost:2181 #http://localhost:2379 #localhost:8848
props:
# httpclient:
# strategy: webClient
# connectTimeout: 45000
# responseTimeout: 3000
# readerIdleTime: 3000
# writerIdleTime: 3000
# allIdleTime: 3000
# readTimeout: 3000
# writeTimeout: 3000
# wiretap: false
# keepAlive: false
# pool:
# type: ELASTIC
# name: proxy
# maxConnections: 16
# acquireTimeout: 45000
# maxIdleTime: 3000
# proxy:
# host:
# port:
# username:
# password:
# nonProxyHostsPattern:
# ssl:
# useInsecureTrustManager: false
# keyStoreType: PKCS12
# keyStorePath: classpath:keystore.p12
# keyStorePassword: 123456
# keyStoreProvider:
# keyPassword: 123456
# trustedX509Certificates:
# handshakeTimeout:
# closeNotifyFlushTimeout:
# closeNotifyReadTimeout:
# defaultConfigurationType:
sync:
websocket:
urls: ws://localhost:9095/websocket
allowOrigin: ws://localhost:9195
# zookeeper:
# url: localhost:2181
# sessionTimeout: 5000
# connectionTimeout: 2000
# http:
# url: http://localhost:9095
# nacos:
# url: localhost:8848
# namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
# username:
# password:
# acm:
# enabled: false
# endpoint: acm.aliyun.com
# namespace:
# accessKey:
# secretKey:
# etcd:
# url: http://localhost:2379
# consul:
# url: http://localhost:8500
# waitTime: 1000
# watchDelay: 1000
cross:
enabled: true
allowedHeaders:
allowedMethods: "*"
allowedOrigin: "*"
allowedExpose: "*"
maxAge: "18000"
allowCredentials: true
switchConfig:
local: true
file:
enabled: true
maxSize : 10
exclude:
enabled: false
paths:
- /favicon.ico
extPlugin:
path:
enabled: true
threads: 1
scheduleTime: 300
scheduleDelay: 30
scheduler:
enabled: false
type: fixed
threads: 16
upstreamCheck:
enabled: false
timeout: 3000
healthyThreshold: 1
unhealthyThreshold: 1
interval: 5000
printEnabled: true
printInterval: 60000
属性详解
shenyu.NettyTcpProperties 配置
ShenYu reactor-netty 配置
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| webServerFactoryEnabled | Boolean | true | No | 是否开启自定义参数,true-开启,false-可以自行配置NettyReactiveWebServerFactory |
| selectCount | Integer | 1 | No | Netty 选择器数 |
| workerCount | Integer | 4 | No | Netty 工作线程数 |
| ServerSocketChannelConfig | ||||
| soRcvBuf | Integer | -- | No | Socket参数,TCP数据接收缓冲区大小,默认由系统决定 |
| soBackLog | Integer | 128 | No | Socket参数,服务端接受连接的队列长度 |
| soReuseAddr | Boolean | true | No | Socket 参数,是否复用地址,reactor-netty中默认值为true |
| connectTimeoutMillis | Integer | 30000 | No | Netty 参数,连接超时时间 |
| writeBufferHighWaterMark | Integer | 65536 | No | Netty 参数,通道水位线上限 |
| writeBufferLowWaterMark | Integer | 32768 | No | Netty 参数,通道水位线下限 |
| writeSpinCount | Integer | 16 | No | Netty参数,一个Loop写操作执行的最大次数 |
| autoRead | Boolean | false | No | Netty参数,自动读取,reactor-netty中默认值为false,且只能为false |
| allocType | String | pooled | No | Netty参数,ByteBuf的分配器 |
| SocketChannelConfig | ||||
| soKeepAlive | Boolean | false | No | Socket 参数,是否启用心跳保活机制 |
| soReuseAddr | Boolean | true | No | Socket 参数,是否复用地址,reactor-netty中默认值为true |
| soLinger | Integer | -1 | No | Socket 参数,关闭 Socket 的延迟时间 |
| tcpNoDelay | Boolean | true | No | Socket 参数,是否启用 Nagle 算法 |
| soRcvBuf | Integer | -- | No | Socket参数,TCP数据接收缓冲区大小,默认由系统决定 |
| soSndBuf | Integer | -- | No | Socket参数,TCP数据发送缓冲区大小,默认由系统决定 |
| ipTos | Integer | 0 | No | IP参数,设置IP头部的Type-of-Service字段,用于描述IP包的优先级和QoS选项 |
| allowHalfClosure | Boolean | false | No | Netty参数,一个连接的远端关闭时本地端是否关闭 |
| connectTimeoutMillis | Integer | 30000 | No | Netty 参数,连接超时时间 |
| writeBufferHighWaterMark | Integer | 65536 | No | Netty 参数,通道水位线上限 |
| writeBufferLowWaterMark | Integer | 32768 | No | Netty 参数,通道水位线下限 |
| writeSpinCount | Integer | 16 | No | Netty参数,一个Loop写操作执行的最大次数 |
| autoRead | Boolean | false | No | Netty参数,自动读取,reactor-netty中默认值为false,且只能为false |
| allocType | String | pooled | No | Netty参数,ByteBuf的分配器 |
shenyu.instance 配置
这是 ShenYu 网关注册到注册中心的相关配置,注册中心配置请参考 注册中心配置 。
| 名称 | 类型 | 默认值 | 是否必填 | 说明 |
|---|---|---|---|---|
| enabled | boolean | false | 是 | 是否启动 |
| registerType | String | zookeeper | 是 | 使用哪个注册中心,目前支持zookeeper、etcd |
| serverLists | String | localhost:2181 | 是 | 注册中心的地址。若使用集群,用 , 分隔 |
| props | 使用不同注册类型时,属性取值不同。 |
props配置
使用不同的注册中心时,属性取值不同。
当注册类型为 zookeeper 时,支持的属性配置如下:
| 名称 | 类型 | 默认值 | 是否必填 | 说明 |
|---|---|---|---|---|
| sessionTimeout | int | 30000 | 否 | session超时时间(毫秒) |
| connectionTimeout | int | 3000 | 否 | 连接超时时间(毫秒) |
当注册类型为 etcd 时,支持的属性配置如下:
| 名称 | 类型 | 默认值 | 是否必填 | 说明 |
|---|---|---|---|---|
| etcdTimeout | int | 30000 | 否 | etcd超时时间(毫秒) |
| etcdTTL | int | 5 | 否 | 租约生存时间(秒) |
shenyu.httpclient 配置
这是 ShenYu 网关中代理Http及SpringCloud协议后,用于发送代理请求的HttpClient配置。
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| strategy | String | webClient | No | HttpClientPlugin实现策略(默认使用webClient): - webClient:使用WebClientPlugin- netty:使用NettyHttpClientPlugin |
| connectTimeout | int | 45000 | No | 连接超时时间 (毫秒),默认值为 45000。 |
| responseTimeout | int | 3000 | No | 结果超时时间 (毫秒),默认值为 3000。 |
| readerIdleTime | int | 3000 | No | 指定读空闲超时时间 (毫秒),默认值为 3000。 |
| writerIdleTime | int | 3000 | No | 指定写空闲超时时间 (毫秒),默认值为 3000。 |
| allIdleTime | int | 3000 | No | 指定读和写超时时间 (毫秒),默认值为 3000。 |
| readTimeout | int | 3000 | No | 读取超时 (毫秒),默认值为 3000。 |
| writeTimeout | int | 3000 | No | 输出超时 (millisecond),默认值为 3000。 |
| wiretap | Boolean | false | No | 启用 Netty HttpClient 的窃听调试,默认值为 false。 |
| keepAlive | Boolean | false | No | 启用或禁用请求的 Keep-Alive 支持,默认值为 false |