Consul - studiofu/brain GitHub Wiki
start consul server in dev mode
./consul agent -dev -ui -bind=192.168.1.88 -client=0.0.0.0
start consul server in single machine
consul agent -server -bootstrap-expect=1 -data-dir=consul-data -ui -bind=127.0.0.1consul config sample config.json
{
"bootstrap_expect": 3,
"client_addr": "0.0.0.0",
"datacenter": "Us-Central",
"data_dir": "consul-data",
"domain": "consul",
"enable_script_checks": true,
"dns_config": {
"enable_truncate": true,
"only_passing": true
},
"enable_syslog": true,
"encrypt": "DLsT2sQlPjT34VUeeNXeBA==",
"leave_on_terminate": true,
"log_level": "INFO",
"rejoin_after_leave": true,
"server": true,
"start_join": [
"192.168.1.88"
],
"ui": true
}
start consul in clustering mode
/consul agent -config-dir consul.d -ui -bind=192.168.1.88 -client=0.0.0.0
Build the spring boot application service, and set the environment variable CONSUL_PRODUCER which will be used in the demo-consul-producer application and then start more than one instance for services load balancing testing
the service will be registered to the consul
build the client for the testing
build the zuul api gateway
https://github.com/quantificial/demo-consul-api-gateway.git http://www.manongjc.com/article/8181.html
Consul 搭建集群 - use vagrant to provision the machine
start consul server in docker
also use fabio as gateway
docker run -d -t -p 8300:8300 -p 8301:8301 -p 8302:8302 -p 8500:8500 -p 8600:8600 --name test-consul consul:1.3.0
docker pull fabiolb/fabio:1.5.5-go1.9.2
docker run -d -t -p 9998:9998 -p 9999:9999 --link test-consul:consul -e 'registry_consul_addr=consul:8500' fabiolb/fabio:1.5.5-go1.9.2start consul in windows / linux and in default consul will use port 9500
consul agent -server -bootstrap-expect=1 -data-dir=consul-data -ui -bind=127.0.0.1
consul agent -server -bootstrap-expect=1 -data-dir consul-data -node n1 -u1
consul agent -server -bootstrap-expect=1 -data-dir consul-data -node=n1 -datacenter=dc1 -ui -bind=127.0.0.1
consul members
try register services and perform query
curl -X PUT -d '{"Datacenter": "sz-1", "Node": "mysql-1", "Address": \
"mysql-1.node.consul","Service": {"Service": "mysql", "tags": ["master","v1"], \
"Port": 3306}}' http://127.0.0.1:8500/v1/catalog/register
curl -X PUT -d '{"Datacenter": "sz-1", "Node": "mysql-2", "Address": \
"mysql-2.node.consul","Service": {"Service": "mysql", "tags": ["slave","v1"],\
"Port": 3306}}' http://127.0.0.1:8500/v1/catalog/register
curl http://127.0.0.1:8500/v1/catalog/service/mysqluse consul join to form the cluster
consul join [ip address]
<dependency>
<groupId>com.orbitz.consul</groupId>
<artifactId>consul-client</artifactId>
<version>0.12.3</version>
</dependency>
Consul client = Consul.builder().build();
String serviceName = UUID.randomUUID().toString();
String serviceId = UUID.randomUUID().toString();
client.agentClient().register(8080, new URL("http://localhost:1337/health"), 1000L, serviceName, serviceId);
HealthClient healthClient = Consul.newClient().healthClient();
ConsulResponse<List<ServiceHealth>> response = client2.healthClient().getHealthyServiceInstances(serviceName);//获取健康的服务
ServiceHealthCache svHealth = ServiceHealthCache.newCache(healthClient, serviceName);//创建今天服务
svHealth.start();//开始监听服务
dns method for the service lookup, set the dns server as consul server in the docker
frontend-1:
image: josdirksen/demo-service
container_name: Frontend1
ports:
- 8090:8090
environment:
- "constraint:node==nb1"
- SERVER_ID=1
- SERVERNAME=Server1
- PORT=8090
command: /entrypoint.sh --type frontend
dns: 192.168.99.106
dns_search: service.consul
# 从容器外部检查被调用的后端服务所注册的IP地址
$ dig @nb-consul.local backend-service.service.consul +short
10.0.9.7
10.0.9.8
10.0.9.6
# 如果从容器内部的话,我们可以单纯的只做这一件事情
docker exec -ti nb2/Frontend2 ping backend-service
PING backend-service.service.consul (10.0.9.8): 56 data bytes
64 bytes from 10.0.9.8: icmp_seq=0 ttl=64 time=0.809 ms
API Gateway with Zuul
https://medium.com/@jegasingamjeyanthasingam/api-gateway-with-zuul-63b8338b4071
spring cloud: 使用consul来替换eureka
https://www.cnblogs.com/yjmyzz/p/replace-eureka-with-consul.html
Eureka 2.X停止开发,注册中心Consul使用详解
https://zhuanlan.zhihu.com/p/40176945
Spring Cloud Eureka Consul使用和对比
https://blog.csdn.net/ZYC88888/article/details/81453647
Keep your secrets away from code (Consul + Spring boot)
https://blog.imaginea.com/integrate-consul-with-spring-boot-2-0-5-release/
Consul Service Registration and Discovery Example
https://howtodoinjava.com/spring-cloud/consul-service-registration-discovery/
springcloud(十三):注册中心 Consul 使用详解
http://www.ityouknow.com/springcloud/2018/07/20/spring-cloud-consul.html
使用consul实现分布式服务注册和发现
https://tonybai.com/2015/07/06/implement-distributed-services-registery-and-discovery-by-consul/
使用Consul做服务发现的若干姿势
https://cloud.tencent.com/developer/article/1368802
深入学习consul
https://blog.csdn.net/qq_15037231/article/details/79804269
Docker结合Consul实现的服务发现(一)
https://www.open-open.com/lib/view/open1464481918133.html
Api Gateway Part 3: Zuul & Consul
https://medium.com/@nepalBrothers/api-gateway-part-3-zuul-consul-1ae5824126ff
Load Balancing Microservices using Zuul and Consul
https://taagung.com/load-balancing-microservices-zuul-consul/