Skip to content

Latest commit

 

History

History
139 lines (114 loc) · 4.41 KB

File metadata and controls

139 lines (114 loc) · 4.41 KB

config-server使用方式

  • config-server是一个spring-boot的web工程,最低要求java21,配置文件包括 application.ymllogback.xml
  • 通过配置 application.yml 可以选择不同的配置中心,当前支持 etcdnacoslocal,你也可以自定义(需要java开发能力)

config-server的部署

使用etcd作为数据源

lb-driver-config-server:
  config-type: etcd
  config:
    "etcd.target": "ip:///etcd0:2379,etcd1:2379,etcd2:2379"
#    "etcd.endpoints": "http://etcd0:2379,http://etcd1:2379,http://etcd2:2379" #etcd.target和etcd.endpoints二选一,优先使用etcd.target
#    "etcd.user": "xx"
#    "etcd.password": "xx"
#    "etcd.namespace": "xx"
#    "etcd.authority": "xx"
    "etcd.config.key.prefix": "/obproxy/yunxin"
  • 其中 /obproxy/yunxin/{schema} 表示某个schema的配置

使用nacos作为数据源

lb-driver-config-server:
  config-type: nacos
  config:
    "nacos.serverAddr": "127.0.0.1:8848"
    "nacos.group": "xxx"
    "nacos.username": "xxx"
    "nacos.password": "xxx"
    "nacos.init.schema.list": "xxx,yyy,zzz" #逗号分隔
  • 其中 dataId={schema} 表示某个schema的配置
  • 其中 nacos.init.schema.list 表示初始化时加载的schema列表

使用本地配置文件作为数据源

lb-driver-config-server:
  config-type: local
  config:
    "local.config.file": "config.json"
#    "local.config.file.path": "/xxx/xx/config.json"
  • config.json 是一个json数组,每个元素表示一个schema
  • 可以配置文件名(classpath下),也可以配置文件绝对路径(优先级更高)

配置示例

  • config-server 从数据源获取配置,配置要求为json结构,如下:
  • etcd 或者 nacos 更新配置后,config-server会自动监听配置变更,lb-driver也会在几秒内获取到最新的sql-proxy节点列表
  • local 更新配置后,需要调用 /reload 接口才会更新配置,随后,lb-driver也会在几秒内获取到最新的sql-proxy节点列表
{
  "schema": "im_user",
  "auth.enable": true,
  "api.keys":
  [
    "aaaa",
    "bbbb",
    "cccc"
  ],
  "proxy":
  [
    "10.0.0.1:3306",
    "10.0.0.2:3306"
  ]
}
  • schema 表示sql-proxy归属的schema
  • auth.enable 表示lb-driver请求config-server时是否鉴权,默认false
  • api.keys 表示鉴权的api-key,支持多个
  • proxy 表示配置的sql-proxy节点列表

接口文档

## 获取配置,lb-driver调用的就是这个接口
curl -H "Authorization: Bearer xxxxx" "http://127.0.0.1:8080/fetch_sql_proxy_list?schema=xxxx"
## 强制reload,local则重新读取本地配置文件,nacos/etcd则重新去远程拉取一次配置
curl "http://127.0.0.1:8080/reload"
## 监控数据
curl "http://127.0.0.1:8080/monitor"
## 健康检查接口
curl "http://127.0.0.1:8080/health/status"
## 上线接口,调用后,/health/status返回200
curl "http://127.0.0.1:8080/health/online"
## 下线接口,调用后,/health/status返回500
curl "http://127.0.0.1:8080/health/offline"

nginx配置示例

server {
    server_name xxx-lbd-config-server.xxx.com;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_set_header Host $host;
    proxy_set_header X-From-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    location /fetch_sql_proxy_list {
        proxy_pass http://xxx-lbd-config-server;
    }
}

upstream xxx-lbd-config-server {
    server 10.0.0.1:8080 max_fails=0;
    server 10.0.0.2:8080 max_fails=0;
    server 10.0.0.3:8080 max_fails=0;
    check interval=3000 rise=3 fall=3 timeout=3000 type=http;
    check_http_send "GET /health/status HTTP/1.0\r\n\r\n";
    check_http_expect_alive http_2xx http_3xx;
    keepalive 64;
}