./etcdctl ls / --recursivenode
/name
/name1
/name1/wyc
/name1/wu
/name1/chao
/name1/chao/age
--------
./etcdctl -o extended get /name1/wycweb
Key: /name1/wyc
Created-Index: 8
Modified-Index: 8
TTL: 0
Index: 9json
./etcdctl watch /name1/wycbootstrap
当修改这个键的时候,watch就会输出最新的值并退出
--forever 一直监测直到用户按CTRL+C退出后端
curl -L http://localhost:2379/v2/keys/nameapi
=========服务器
1.基于dns的负载均衡,后端服务的注册在kong以外完成,kong只接收来自dns服务器的更新。dns的ttl(time to live)决定了信息被刷新的频率,负载均衡
kong with consul:curl
use consul as a dns server, then you'll have to live with TTL expiry times. Alternatively run a script on changes (services added/removed) to add a target entity through the Kong management api。ui
consul角色
1.agent是在consul集群中每一个机器成员中运行的一个常驻进程。能够当作server或者server的身份运行。全部agent均可以运行dns或者http接口,而且执行健康检查和保持服务信息的同步。
2.client是一个agent,将rpc调用转向对应的服务。client是无状态的。惟一的在后台执行的逻辑就是加入Gossip同步池。
3.server一样是一个agent,职责包括实现集群的一致性,维护集群状态,响应rpc请求,与其余数据中心交换数据。
consul发现服务
consul提供了dns和http两种查询服务的方式。DNS 服务的默认端口设置为8600。Consul 服务被放置在 .consul 的命名空间下,DNS 查询的基础规则为 SERVICENAME.service.consul。其中 service 子域表示查询服务,SERVICENAME正是查询服务的名称。除了经过 DNS API,HTTP 服务也可用于服务查询。
consul使用
{
"service": {
"name": "my-svc",
"tags": [
"microservice"
],
"port": 8045,
"check": {
"script": "curl localhost:8045/status | grep OK || exit 2",
"interval": "5s"
}
}
}
-------
{
"service": {
"name": "web3",
"tags": ["master"],
"address": "127.0.0.1",
"port": 10000,
"checks": [
{
"http": "http://localhost:10000/health",
"interval": "10s"
}
]
}
}
4.机器节点,用于查看集群状态 consul agent -client=172.0.0.12 -ui-dir /vagrant/web/ -data-dir /tmp/consul -node=status -bind 172.0.0.12 -join 172.0.0.10