动态负载均衡(Nginx+Consul+UpSync)环境搭建
首先 安装好 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)环境搭建的更多相关文章
- Consul+upsync+Nginx 动态负载均衡
1,动态负载均衡 传统的负载均衡,如果修改了nginx.conf 的配置,必须需要重启nginx 服务,效率不高.动态负载均衡,就是可配置化,动态化的去配置负载均衡. 2,实现方案 1. Consul ...
- Consul+upsync+Nginx实现动态负载均衡 摘自https://blog.csdn.net/qq_29247945/article/details/80787014
传统感念:每次修改完nginx配置文件,要重启nginx 动态感念:每次修改完nginx配置信息,不需要重启,nginx实时读取配置信息. Nginx: 反向代理和负载均衡 Consul:是用go编写 ...
- 基于Consul+Upsync+Nginx实现动态负载均衡
基于Consul+Upsync+Nginx实现动态负载均衡 1.Consul环境搭建 下载consul_0.7.5_linux_amd64.zip到/usr/local/src目录 cd /usr/l ...
- 【Nginx】基于Consul+Upsync+Nginx实现动态负载均衡
一.Http动态负载均衡 什么是动态负载均衡 动态负载均衡实现方案 常用服务器注册与发现框架 二.Consul快速入门 Consul环境搭建 三.nginx-upsync-module nginx-u ...
- 通过Nginx、Consul、Upsync实现动态负载均衡和服务平滑发布
前提 前段时间顺利地把整个服务集群和中间件全部从UCloud迁移到阿里云,笔者担任了架构和半个运维的角色.这里详细记录一下通过Nginx.Consul.Upsync实现动态负载均衡和服务平滑发布的核心 ...
- 动态负载均衡(Nginx+Consul+UpSync)
Http动态负载均衡 什么是动态负载均衡 传统的负载均衡,如果Upstream参数发生变化,每次都需要重新加载nginx.conf文件, 因此扩展性不是很高,所以我们可以采用动态负载均衡,实现Upst ...
- Nginx(四) nginx+consul+upasync 在ubnutu18带桌面系统 实现动态负载均衡
1.1 什么是动态负载均衡 传统的负载均衡,如果Upstream参数发生变化,每次都需要重新加载nginx.conf文件,因此扩展性不是很高,所以我们可以采用动态负载均衡,实现Upstream可配置化 ...
- Nginx 实现动态负载均衡(Nginx-1.10.1 + Consul v0.6.4)
一直也没有找到合适的类似Socat + Haproxy 的组合能用在Nginx,后来发现了Nginx的几个模块,但是也存在各种不足. 而且Nginx 在大流量的情况下nginx -s reload 是 ...
- 《nginx 三》实现nginx的动态负载均衡——实战
Http动态负载均衡 什么是动态负载均衡 传统的负载均衡,如果Upstream参数发生变化,每次都需要重新加载nginx.conf文件, 因此扩展性不是很高,所以我们可以采用动态负载均衡,实现Upst ...
随机推荐
- 2012-2013 ACM-ICPC, NEERC, Central Subregional Contest
A Hanoi Tower 递归 题意: 大家都很熟悉汉诺塔的递归程序,现在给你一个组合,询问你这个组合是否会出现在汉诺塔的递归过程中. 题解: 将汉诺塔的递归程序反过来思考,考虑当前最大的那个盘,我 ...
- 支持C++11标准
设置CB下的GCC. Settings->Compiler->Compiler Settings勾选Have g++ follow the C++11 ISO C++ language s ...
- SQL SERVER 跟踪调优书籍
SQLServer监控和诊断 SQL SERVER 性能优化的艺术
- Unix domain socket
转载:http://www.cnblogs.com/chekliang/p/3222950.html socket API原本是为网络通讯设计的,但后来在socket的框架上发展出一种IPC机制,就是 ...
- jsp、freemarker、velocity 的区别
在java领域,表现层技术主要有三种:jsp.freemarker.velocity. 一.jsp是大家最熟悉的技术:优点:1.功能强大,可以写java代码2.支持jsp标签(jsp tag)3.支持 ...
- python 工具 二进制文件处理之——去掉指定长度数据包头
包头48bit 数据98464 ...如此循环: piece_size = 48 piece_size1 = 98464 with open("C:\\Users\\Administrato ...
- SPFA 求带负权的单源最短路
int spfa_bfs(int s) { ///s表示起点. queue <int> q; memset(d,0x3f,sizeof(d)); ///d数组中存下的就是最短路径(存在的话 ...
- Host Controller transport layer and AMPs
The logical Host Controller Interface does not consider multiplexing/routing over the Host Controlle ...
- C++11 并发指南四(<future> 详解三 std::future & std::shared_future)(转)
上一讲<C++11 并发指南四(<future> 详解二 std::packaged_task 介绍)>主要介绍了 <future> 头文件中的 std::pack ...
- linux遍历目录源代码
<pre code_snippet_id="1622396" snippet_file_name="blog_20160324_1_744516" nam ...