1 Star 0 Fork 166

yinren / Apache APISIX

forked from iresty / Apache APISIX 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
stand-alone.md 3.72 KB
一键复制 编辑 原始数据 按行查看 历史

English

Stand-alone mode

开启 Stand-alone 模式的 APISIX 节点,将不再使用默认的 etcd 作为配置中心。

这种方式比较适合两类用户:

  1. kubernetes(k8s):声明式 API 场景,通过全量 yaml 配置来动态更新修改路由规则。
  2. 不同配置中心:配置中心的实现有很多,比如 Consule 等,使用全量 yaml 做中间转换桥梁。

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

单个 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

配置 Router + Service

routes:
    -
        uri: /hello
        service_id: 1
services:
    -
        id: 1
        upstream:
            nodes:
                "127.0.0.1:1980": 1
            type: roundrobin
#END

配置 Router + Upstream

routes:
    -
        uri: /hello
        upstream_id: 1
upstreams:
    -
        id: 1
        nodes:
            "127.0.0.1:1980": 1
        type: roundrobin
#END

配置 Router + Service + Upstream

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
Lua
1
https://gitee.com/liujunao153/apisix.git
git@gitee.com:liujunao153/apisix.git
liujunao153
apisix
Apache APISIX
master

搜索帮助