upyun / slardar

Updating your upstream list and run lua scripts without reloading Nginx.
494 stars 111 forks source link

How to add upstream backup server in consul, Does it support? #4

Open xiaoxuanzi opened 7 years ago

xiaoxuanzi commented 7 years ago

I know how to add upstream server in consul in README:

key: upstreams/node-dev.example servers: {"enable": true, "servers": [{"host": "127.0.0.1","port": 8001,"weight": 1,"max_fails": 6,"fail_timeout": 30}]}

But i don not know how to add upstream backup servers, and how slardar use backup server when all primary server dowm with the round-robin method? And i did't find any code to process backup servers. Can you tell me how? I am wait online! THX!

`local servers = get_servers(consul_cluster, key .. "?raw") if not servers or not next(servers) then return false end

    if not check_servers(servers["servers"]) then
        return false
    end

    local cls = {
        servers = servers["servers"],
        keepalive = tonumber(servers["keepalive"]),
        try =  tonumber(servers["try"]),
    }

    config[skey] = {
        cluster = { cls },
    }`
yejingx commented 7 years ago

Sorry for late reply.

how to add upstream backup servers

Checkups support multi-level servers. But Slardar doesn't support by now. You can see only one level is passed to checkups.update_upstream here.

If you want multi-level, maybe you can call checkups.update_upstreams like this:

checkups.update_upstream(skey, {
                    {     -- primary
                        servers = {
                            {host="127.0.0.1", port=12350},
                            {host="127.0.0.1", port=12351},
                        }
                    },
                    {      -- backup
                        servers = {
                            {host="127.0.0.1", port=12352},
                            {host="127.0.0.1", port=12353},
                        }
                    },
            })

Patches welcome.

how slardar use backup server

Slardar use backup servers when all primary servers are down by the same RR policy.

xiaoxuanzi commented 7 years ago

I'm glad to have received your respone, thanks a lot. I want to use Slardar in my project . I have already change some of code in to Slardar adjust my to adapt to the scene in my project. and make Slardar more general.

i am very happy to submit patches in the next months and anticipate your reply.