1. 编写插件logstash.lua
位置:/usr/local/apisix/apisix/plugins/logstash.lua
local core = require("apisix.core")
local plugin_name = "logstash"
local schema = {
type = "object",
properties = {
content = {
type = "string"
}
}
}
local _M = {
version = 0.2,
priority = 5001,
name = plugin_name,
schema = schema,
}
function _M.access(conf, ctx)
core.log.warn(conf.content)
end
return _M
2. 添加到插件列表
位置: /usr/local/apisix/conf/config-default.yaml
plugins: # plugin list (sorted by priority)
- logstash # priority: 5001
3.重启apisix或者热加载插件
重启命令
docker restart apisix-apisix-dashboard-1
热加载插件
curl http://127.0.0.1:9080/apisix/admin/plugins/reload -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT
注意:插件编写有问题,插件不会添加
4.更新apisix-dashboard的插件列表
# apisix容器内部执行
curl 127.0.0.1:9092/v1/schema > schema.jsonjson
# 宿主机执行
docker cp apisix-apisix-1:/usr/local/apisix/schema.json schema.json
docker cp apisix-apisix-dashboard-1:/usr/local/apisix/schema.json schema.json.bak
docker cp schema.json apisix-apisix-dashboard-1:/usr/local/apisix-dashboard/conf/schema.json
docker restart apisix-apisix-dashboard-1
5.检查页面插件列表