https://hub.docker.com/_/consul

https://hub.docker.com/r/hashicorp/consul-template

https://github.com/hashicorp/consul-template

https://abc.htmltoo.com/thread-45674.htm

Consul是什么

Consul是一个服务网格(微服务间的 TCP/IP,负责服务之间的网络调用、限流、熔断和监控)解决方案,它是一个一个分布式的,高度可用的系统,而且开发使用都很简便。它提供了一个功能齐全的控制平面,主要特点是:服务发现、健康检查、键值存储、安全服务通信、多数据中心。


应用: api -> 添加服务: consul

consul:latest

命令:

agent -server -bootstrap-expect 2 -ui -bind=0.0.0.0 -client=0.0.0.0

卷:

/etc/localtime:/etc/localtime:ro

/data/file:/data/file


consul2

consul:latest

命令:

agent -server -bootstrap-expect 2 -ui -bind=0.0.0.0 -client=0.0.0.0 -join consul

卷:

/etc/localtime:/etc/localtime:ro

/data/file:/data/file


consul3

consul:latest

命令:

agent -server -bootstrap-expect 2 -ui -bind=0.0.0.0 -client=0.0.0.0 -join consul

卷:

/etc/localtime:/etc/localtime:ro

/data/file:/data/file


Consul:服务注册、服务发现、键值存储、及健康检查


Nginx四层负载均衡—《亿级流量网站架构核心技术》 

我们配置HTTP负载均衡时,都是配置在http指令下,而四层负载均衡是配置在stream指令下。


Consul

Docker image:https://hub.docker.com/r/library/consul/
Consul 配置:https://www.consul.io/docs/agent/options.html
Consul Service配置:https://www.consul.io/docs/agent/services.html
Consul HTTP API:https://blog.csdn.net/u010246789/article/details/51871051
Consul 填坑:https://my.oschina.net/u/553243/blog/1634206?p=1&temp=1526522296342#blog-comments-list
博客参考:
http://www.cnblogs.com/cuishuai/p/8194345.html
https://blog.csdn.net/mn960mn/article/details/51753893
https://kevinguo.me/2017/09/01/docker-consul-consul-template-registrator-nginx/#consul
https://www.jianshu.com/p/d8ac9ad495a7
https://blog.csdn.net/socho/article/details/75434733

# 动态地修改后端服务器属性(权重,max_FILES,down.),不需要重新加载nginx

https://github.com/weibocom/nginx-upsync-module/         

https://github.com/CallMeFoxie/nginx-stream-upsync-module

https://github.com/CallMeFoxie/nginx-upsync

https://www.sohu.com/a/131247638_494947

https://blog.csdn.net/aixiaoyang168/article/details/10302234

https://www.jianshu.com/p/085edb535070

https://www.hi-linux.com/posts/36431.html

https://www.jianshu.com/p/085edb535070


https://www.centos.bz/2018/02/%E5%9F%BA%E4%BA%8Econsul%E5%AE%9E%E7%8E%B0nginx%E7%9A%84%E5%8A%A8%E6%80%81upstream/


Consul Template

GitHub(包涵启动及配置):https://github.com/hashicorp/consul-template
配置参考:https://blog.csdn.net/lizhenhe/article/details/80030051
博客参考:https://www.hi-linux.com/posts/36431.html

=================

1. 例子

file.htmltoo.com:8500/ui/dc1/kv  -> Key / Value   ->  Create  -> upstreams/test

server 127.0.0.1:81 weight=1 fail_timeout=10 max_fails=3;

server 127.0.0.1:82 weight=1 fail_timeout=10 max_fails=3;

server 127.0.0.1:83 weight=1 fail_timeout=10 max_fails=3;


file.htmltoo.com:8500/v1/catalog/nodes

file.htmltoo.com:8500/v1/kv/upstreams/test


从Consul添加上游服务器

curl -X PUT  -d "{"weight":1, "max_fails":2, "fail_timeout":10}"  http://1270.0.1:8500/v1/kv/upstreams/accounting/127.0.0.1:81

curl -X PUT  -d "{"weight":1, "max_fails":2, "fail_timeout":10}"  http://1270.0.1:8500/v1/kv/upstreams/accounting/127.0.0.1:82

curl -X DELETE  http://1270.0.1:8500/v1/kv/upstreams/accounting/127.0.0.1:81

curl -X DELETE  http://1270.0.1:8500/v1/kv/upstreams/accounting/127.0.0.1:82

------------------------------

stream # nginx-stream-upsync-module;     nginx-upsync-module: http

    upstream test {

        least_conn; //hash $uri consistent;

        upsync 127.0.0.1:8500/v1/kv/upstreams/test/ upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;

        upsync_dump_path /usr/local/nginx/conf/servers/servers_test.conf;

        upsync_lb least_conn; //hash_ketama;

        include /usr/local/nginx/conf/servers/servers_test.conf;

    }

......

upsync指令指定从consul哪个路径拉取上游服务器配置;

upsync_timeout配置从consul拉取上游服务器配置的超时时间;

upsync_interval配置从consul拉取上游服务器配置的间隔时间;

upsync_type指定使用consul配置服务器;

strong_dependency配置nginx在启动时是否强制依赖配置服务器,

如果配置为on,则拉取配置失败时nginx启动同样失败。

upsync_dump_path指定从consul拉取的上游服务器后持久化到的位置,

这样即使consul服务器出问题了,本地还有一个备份。

.............

    server {

        listen 12345;

        proxy_connect_timeout 1s;

        proxy_timeout 3s;

        proxy_pass test;

    }

    server {

        listen 2345;

        upstream_show

    }

......

配置upstream_show指令后,

可以通过curl http://127.0.0.1:1234/upstream_show来查看当前动态负载均衡上游服务器列表。

------------------------------------------------

# consul 剔除多个服务的脚本

#!/bin/bash
clear 
echo "node_exporter注销工具"
read -p "请输入要踢掉的节点IP,如果有多个IP,请使用英文格式 ',' 隔开: " IP_LIST
for IP in `echo "${IP_LIST}"|awk -F, 'BEGIN{OFS=" "}{$1=$1;printf("%s",$0);}'`
do 
   curl -XPUT http://10.100.x.x:8500/v1/agent/service/deregister/node-${IP}
   echo "${IP}节点已剔除!"
done
echo "${IP_LIST}完成剔除"

# 注册多个服务到consul的脚本:

#!/bin/bash 
all_IP=`cat  /opt/ip`
name=cadvisor
port=9100
for  I  in $all_IP
do
        curl -X PUT -d '{"id": "'$I'","name": "'$name'","address": "'$I'","port": '$port',"tags": ["cadvisor"], "checks": [{"http": "http://'$I':'$port'/","interval": "5s"}]}'     http://172.17.0.4:8500/v1/agent/service/register
done


签名:这个人很懒,什么也没有留下!
最新回复 (0)
返回