首先 安装好 Consul upsync

然后:

1、配置安装Nginx

需要做配置,包括分组之类的,创建目录,有些插件是需要存放在这些目录的

groupadd nginx

useradd -g nginx -s /sbin/nologin nginx

mkdir -p /var/tmp/nginx/client/

mkdir -p /usr/local/nginx

2、编译Nginx

cd  /home/nginx/nginx-1.9.0

./configure   --prefix=/usr/local/nginx   --user=nginx   --group=nginx   --with-http_ssl_module   --with-http_flv_module   --with-http_stub_status_module   --with-http_gzip_static_module   --with-http_realip_module   --http-client-body-temp-path=/var/tmp/nginx/client/   --http-proxy-temp-path=/var/tmp/nginx/proxy/   --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/   --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi   --http-scgi-temp-path=/var/tmp/nginx/scgi   --with-pcre --add-module=/home/upsync/nginx-upsync-module-master

解读:

注意,如果出现这个错误:

解决办法

yum -y install openssl openssl-devel

最后: make && make install


下面开始配置Nginx了

Upstream(上游服务器) 动态配置

##动态去consul 获取注册的真实反向代理地址

upstream toov5{

#自己虚拟出的 作为监听用的 端口号 固定死的
server 127.0.0.1:11111;

#连接consul server动态获取upstream配置负载均衡信息 间隔0.5秒读取一次  使用192.168.212.134:8500 原生的 他自己虚拟出来的 不要乱改!  读取的是toov5 这个分组的!!!
upsync 192.168.91.5:8500/v1/kv/upstreams/toov5 upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;

#动态拉取consulServer相关负载均衡配置信息持久化到硬盘上
upsync_dump_path /usr/local/nginx/conf/servers/servers_test.conf;
}
server {
listen 80;
server_name localhost;
location / {

#配置反向代理
proxy_pass http://toov5;
index index.html index.htm;

}

}

解读:

upsync指令指定从consul哪个路径拉取上游服务器配置;upsync_timeout配置从consul拉取上游服务器配置的超时时间;upsync_interval配置从consul拉取上游服务器配置的间隔时间;upsync_type指定使用consul配置服务器;strong_dependency配置nginx在启动时是否强制依赖配置服务器,如果配置为on,则拉取配置失败时nginx启动同样失败。upsync_dump_path指定从consul拉取的上游服务器后持久化到的位置,这样即使consul服务器出问题了,本地还有一个备份。

注意:替换 consul 注册中心地址

创建upsync_dump_path

mkdir /usr/local/nginx/conf/servers/

upsync_dump_path指定从consul拉取的上游服务器后持久化到的位置,这样即使consul服务器出问题了,本地还有一个备份。

配置时候的状态:

#user  nobody;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; ##动态去consul 获取注册的真实反向代理地址 upstream toov5{ #自己虚拟出的 作为监听用的 端口号 固定死的
server 127.0.0.1:11111; #连接consul server动态获取upstream配置负载均衡信息 间隔0.5秒读取一次
upsync 192.168.91.5:8500/v1/kv/upstreams/toov5 upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off; #动态拉取consulServer相关负载均衡配置信息持久化到硬盘上
upsync_dump_path /usr/local/nginx/conf/servers/servers_test.conf;
} server {
listen 80;
server_name localhost; location / {
#配置反向代理
proxy_pass http://toov5;
index index.html index.htm; } } # server {
# listen 80;
# server_name localhost; # #charset koi8-r; # #access_log logs/host.access.log main; # location / {
# root html;
# index index.html index.htm;
# }
#
#error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# root html;
# }
#
# } }

  

  

然后启动consul :  ./consul agent -dev -ui -node=consul-dev -client=192.168.91.5

启动 Nginx    ./nginx

本地启动三台:8080 8081 8082

 然后开始做动态负载均衡了!添加nginx  Upstream服务开始:

1.使用linux命令方式发送put请求  添加这个 192.168.8.159:8081 到上游服务

curl -X PUT http://192.168.91.5:8500/v1/kv/upstreams/toov5/192.168.8.159:80812\

2、 使用postman方式

然后图形化界面:

访问:

看看Nginx的本地:

成功了哦

配置权重:

{"weight":2, "max_fails":2, "fail_timeout":10, "down":0}

他可以实现轮训,故障转移哦。默认的~

看这里:

被同步过来了额

动态负载均衡(Nginx+Consul+UpSync)环境搭建的更多相关文章

  1. Consul+upsync+Nginx 动态负载均衡

    1,动态负载均衡 传统的负载均衡,如果修改了nginx.conf 的配置,必须需要重启nginx 服务,效率不高.动态负载均衡,就是可配置化,动态化的去配置负载均衡. 2,实现方案 1. Consul ...

  2. Consul+upsync+Nginx实现动态负载均衡 摘自https://blog.csdn.net/qq_29247945/article/details/80787014

    传统感念:每次修改完nginx配置文件,要重启nginx 动态感念:每次修改完nginx配置信息,不需要重启,nginx实时读取配置信息. Nginx: 反向代理和负载均衡 Consul:是用go编写 ...

  3. 基于Consul+Upsync+Nginx实现动态负载均衡

    基于Consul+Upsync+Nginx实现动态负载均衡 1.Consul环境搭建 下载consul_0.7.5_linux_amd64.zip到/usr/local/src目录 cd /usr/l ...

  4. 【Nginx】基于Consul+Upsync+Nginx实现动态负载均衡

    一.Http动态负载均衡 什么是动态负载均衡 动态负载均衡实现方案 常用服务器注册与发现框架 二.Consul快速入门 Consul环境搭建 三.nginx-upsync-module nginx-u ...

  5. 通过Nginx、Consul、Upsync实现动态负载均衡和服务平滑发布

    前提 前段时间顺利地把整个服务集群和中间件全部从UCloud迁移到阿里云,笔者担任了架构和半个运维的角色.这里详细记录一下通过Nginx.Consul.Upsync实现动态负载均衡和服务平滑发布的核心 ...

  6. 动态负载均衡(Nginx+Consul+UpSync)

    Http动态负载均衡 什么是动态负载均衡 传统的负载均衡,如果Upstream参数发生变化,每次都需要重新加载nginx.conf文件, 因此扩展性不是很高,所以我们可以采用动态负载均衡,实现Upst ...

  7. Nginx(四) nginx+consul+upasync 在ubnutu18带桌面系统 实现动态负载均衡

    1.1 什么是动态负载均衡 传统的负载均衡,如果Upstream参数发生变化,每次都需要重新加载nginx.conf文件,因此扩展性不是很高,所以我们可以采用动态负载均衡,实现Upstream可配置化 ...

  8. Nginx 实现动态负载均衡(Nginx-1.10.1 + Consul v0.6.4)

    一直也没有找到合适的类似Socat + Haproxy 的组合能用在Nginx,后来发现了Nginx的几个模块,但是也存在各种不足. 而且Nginx 在大流量的情况下nginx -s reload 是 ...

  9. 《nginx 三》实现nginx的动态负载均衡——实战

    Http动态负载均衡 什么是动态负载均衡 传统的负载均衡,如果Upstream参数发生变化,每次都需要重新加载nginx.conf文件, 因此扩展性不是很高,所以我们可以采用动态负载均衡,实现Upst ...

随机推荐

  1. bitShark对Android版本的支持

    bitShark对Android版本的支持   bitShark是一款轻量级的Android数据抓包软件.使用该软件,可以随时随地抓取网络中的各种数据包,并进行各项分析.我们推出的bitShark手机 ...

  2. GRPC协议的相关原理

    GRPC的Client与Server,均通过Netty Channel作为数据通信,序列化.反序列化则使用Protobuf,每个请求都将被封装成HTTP2的Stream,在整个生命周期中,客户端Cha ...

  3. Java中判断String对象是否为空的方法

    Java原生的方法: String对象中有一个isEmpty的方法判断是否为空,其实isEmpty完全等同于string.length()==0,注意如果String本身是null,那么使用strin ...

  4. [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!

    一.背景 最近的项目在用maven 进行install的时候,发现老师在控制台输出警告:[WARNING] Using platform encoding (UTF-8 actually) to co ...

  5. 高通msm8994启动流程简单介绍

    处理器信息 8994包括例如以下子系统: 子系统 处理器 含义 APSS 4*Cortex-A53 应用子系统 APSS 4*Cortex-A57 应用子系统 LPASS QDSP6 v5.5A(He ...

  6. Linux文件内容查阅

    直接查阅一个文件的内容:cat/tac/nl命令 cat (concatenate) # cat [-AbEnTv] 选项与參数: -A  :相当於 -vET 的整合选项.可列出一些特殊字符而不是空白 ...

  7. angular md-toast 颜色

    How to show md-toast with background color https://codepen.io/neilkalman/pen/jWBqve <div ng-contr ...

  8. iOS实现提现类似的密码输入框

    最近一段时间,在网上不断看了一些技术人员写的代码demo,由于前段时间一直在写一个电商项目,记得有一个功能和看到的demo中类似,但是截然2种不同的处理方法,个人觉得我的这个方法更为简洁一些,所以我把 ...

  9. NHibernate剖析:Mapping篇之Mapping-By-Code(1):概览

    ModelMapper概述 NHibernate3.2版本号集成Mapping-By-Code(代码映射),其设计思想来源于ConfORM.代码总体构思基于"Loquacious" ...

  10. 怎样制作gif图片?怎样制作你项目的动态效果图到你的csdn?

    怎样制作gif图?怎样上传你项目的动态效果图到你的csdn? 这仅仅是笔者用的方法.有其它方法的欢迎分享. 一张或几张展示了你的项目的功能及效果的动态图放在博客文章开头会为你的文章润色不少. 相信非常 ...