有关consul的check服务

check是用来做服务的健康检查的,可以有多个,也可以没有,支持多种方式的检查

check必须是script或者TTL类型的,如果是script类型,则script和interval变量必须被提供,如果是TTL类型,则ttl变量必须被提供

script是consul主动去检查服务的健康状况,ttl是服务主动向consul报告自己的健康状况

以下是几种配置方式

script check

{
    "service":{
        "name":"mysql_name",
        "tags":["mysql", "v1"], 
        "port":3306,

        "check": {
            "id": "mysql_id",
            "name": "mysql_check_name",
            "script": "./check.py",  
            "interval": "10s",
            "timeout": "1s"
        }
    }
}

其中check.py实现如下

#!/usr/bin/python

def check(): 
    return 1

check()

exit(0)

退出返回0 代表check通过,退出返回1 或者非0 表示check失败.

HTTP check:

{
    "service":{
        "name":"iHome_name",
        "tags":["beego", "v1"],
        "port":9998,

        "check": {
            "id": "iHome_id",
            "name": "iHome-go",
            "tcp": "101.200.170.171:9998",
            "interval": "10s",
            "timeout": "1s"
        }
    }
}

101.200.170.171:9998 返回200 代表check成功,否则失败.

TCP check:

{
    "service":{
        "name":"redis_name",
        "tags":["redis", "v1"],
        "port":6379,

        "check": {
            "id": "redis_id",
            "name": "redis_check_name",
            "tcp": "127.0.0.1:6379",
            "interval": "10s",
            "timeout": "1s"
        }
    }
}

127.0.0.1:6379 可以connect成功,则check成功,否则失败.

启动consul来监控

consul agent -dev -enable-script-checks -bind=101.200.170.171 -config-dir ./consul.d/ -client 101.200.170.171

详细 参考:

http://blog.csdn.net/younger_china/article/details/52243759

results matching ""

    No results matching ""