开启 Stand-alone 模式的 APISIX 节点,将不再使用默认的 etcd 作为配置中心。
这种方式比较适合两类用户:
APISIX 节点服务启动后会立刻加载 conf/apisix.yaml
文件中的路由规则到内存,并且每间隔一定时间 (默认 1 秒钟),都会尝试检测文件内容是否有更新,如果有更新则重新加载规则。
注意:重新加载规则并更新时,均是内存热更新,不会有工作进程的替换过程,是个热更新过程。
通过设置 conf/config.yaml
中的 apisix.config_center
选项为 yaml
表示启 用 Stand-alone 模式。
参考下面示例:
apisix: # ... config_center: yaml # etcd: use etcd to store the config value # yaml: fetch the config value from local yaml file `/your_path/conf/apisix.yaml` # ...
此外由于目前 Admin API 都是基于 etcd 配置中心解决方案,当开启 Stand-alone 模式后, Admin API 实际将不起作用。
所有的路由规则均存放在 conf/apisix.yaml
这一个文件中,APISIX 会以每秒(默认)频率检查文件是否有变化,如果有变化,则会检查文件末尾是否能找到 #END
结尾,找到后则重新加载文件更新到内存。
下面就是个最小的示例:
routes: - uri: /hello upstream: nodes: "127.0.0.1:1980": 1 type: roundrobin #END
注意:如果conf/apisix.yaml
末尾不能找到 #END
,那么 APISIX 将不会加载这个文件规则到内存。
单个 Router:
routes: - uri: /hello upstream: nodes: "127.0.0.1:1980": 1 type: roundrobin #END
多个 Router:
routes: - uri: /hello upstream: nodes: "127.0.0.1:1980": 1 type: roundrobin - uri: /hello2 upstream: nodes: "127.0.0.1:1981": 1 type: roundrobin #END
routes: - uri: /hello service_id: 1 services: - id: 1 upstream: nodes: "127.0.0.1:1980": 1 type: roundrobin #END
routes: - uri: /hello upstream_id: 1 upstreams: - id: 1 nodes: "127.0.0.1:1980": 1 type: roundrobin #END
routes: - uri: /hello service_id: 1 services: - id: 1 upstream_id: 2 upstreams: - id: 2 nodes: "127.0.0.1:1980": 1 type: roundrobin #END