Consul+Nginx部署高可用
1. Consul Server
创建consul server虚拟主机
docker-machine create consul
出现如下内容即创建成功
Running pre-create checks...
Creating machine...
(consul) Copying /Users/enoch/.docker/machine/cache/boot2docker.iso to /Users/enoch/.docker/machine/machines/consul/boot2docker.iso...
(consul) Creating VirtualBox VM...
(consul) Creating SSH key...
(consul) Starting the VM...
(consul) Check network to re-create if needed...
(consul) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env consul
创建工作目录consul
mkdir -p ~/workspace/consul && cd ~/workspace/consul
创建docker-compose.yml
version: "3"
services:
consul:
image: consul:latest
ports:
- 8500:8500
command: agent -server -bootstrap -ui -client=0.0.0.0 -node=server01
切换环境到consul
eval $(docker-machine env consul)
执行docker-compose.yml
docker-compose up -d
查看虚拟主机IP
docker-machine ip consul
# output 192.168.99.103
通过IP在浏览器访问8500端口,即可看到Consul的UI界面

2. Nginx + Consul Template
创建反向代理虚拟主机
docker-machine create reverseproxy
出现以下内容代表创建成功
Running pre-create checks...
Creating machine...
(reverseproxy) Copying /Users/enoch/.docker/machine/cache/boot2docker.iso to /Users/enoch/.docker/machine/machines/reverseproxy/boot2docker.iso...
(reverseproxy) Creating VirtualBox VM...
(reverseproxy) Creating SSH key...
(reverseproxy) Starting the VM...
(reverseproxy) Check network to re-create if needed...
(reverseproxy) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env reverseproxy
切换当前环境到虚拟主机
eval $(docker-machine env reverseproxy)
创建工作目录reverseproxy
mkdir -p ~/workspace/reverseproxy && cd ~/workspace/reverseproxy
创建docker-compose.yml
version: "3"
services:
nginx:
image: nginx:latest
ports:
- 8081:80
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./conf.d:/etc/nginx/conf.d
consul-template:
image: hashicorp/consul-template:alpine
volumes:
- ./conf.d:/etc/nginx/conf.d
command: consul-template --consul-addr 192.168.99.103:8500 --template "/etc/nginx/conf.d/nginx.ctmpl:/etc/nginx/conf.d/vhost.conf" --log-level=info
把容器跑起来
docker-compose up -d
查看IP
docker-machine ip reverseproxy
# output 192.168.99.102
浏览器访问reverseproxy的8081端口,出现如下内容代表启动成功

3. Webserver搭建
创建虚拟主机webserver1
docker-machine create webserver1
eval $(docker-machine env webserver1)
mkdir webserver1 & cd webserver1
创建docker—compose.yml
version: "3"
services:
nginx1:
image: nginx:latest
ports:
- 81:80
nginx2:
image: nginx:latest
ports:
- 82:80
registrator:
image: shaharil/registrator:latest
volumes:
- /var/run/docker.sock:/tmp/docker.sock
command: consul://192.168.99.103:8500
跑起来
docker-compose up -d
打开reverseproxy/conf.d/vhost.conf可以看到webserver启动的nginxIP地址都被加了进去
upstream http_backend {
server 172.18.0.2:81;
server 172.18.0.3:82;
}
server {
listen 8000;
server_name localhost;
location / {
proxy_pass http://http_backend;
}
}
做个试验,现在将其中一台nginx容器关闭
eval $(docker-machine env webserver1)
docker stop webserver1_nginx2_1
此时可以看到vhost.conf中的IP被去掉了
upstream http_backend {
server 172.18.0.2:81;
}
server {
listen 8000;
server_name localhost;
location / {
proxy_pass http://http_backend;
}
}
再将nginx容器打开,该容器的IP地址随之也会被加进去
docker start webserver1_nginx2_1
//以下是文件内容
upstream http_backend {
server 172.18.0.2:81;
}
server {
listen 8000;
server_name localhost;
location / {
proxy_pass http://http_backend;
}
}
Consul+Nginx部署高可用的更多相关文章
- consul-template + nginx部署高可用负载均衡
一.Consul-Template简介 Consul-Template是基于Consul的自动替换配置文件的应用.在Consul-Template没出现之前,大家构建服务发现系统大多采用的是Zooke ...
- 使用Ansible实现nginx+keepalived高可用负载均衡自动化部署
本篇文章记录通过Ansible自动化部署nginx的负载均衡高可用,前端代理使用nginx+keepalived,端web server使用3台nginx用于负载效果的体现,结构图如下: 部署前准备工 ...
- 008.Kubernetes二进制部署Nginx实现高可用
一 Nginx代理实现kube-apiserver高可用 1.1 Nginx实现高可用 基于 nginx 代理的 kube-apiserver 高可用方案. 控制节点的 kube-controller ...
- 013.Kubernetes二进制部署worker节点Nginx实现高可用
一 Nginx代理实现kube-apiserver高可用 1.1 Nginx实现高可用 基于 nginx 代理的 kube-apiserver 高可用方案. 控制节点的 kube-controller ...
- 基于Consul的数据库高可用架构
几个月没有更新博客了,已经长草了,特意来除草.本次主要分享如何利用consul来实现redis以及mysql的高可用.以前的公司mysql是单机单实例,高可用MHA加vip就能搞定,新公司mysql是 ...
- [转]搭建Keepalived+Nginx+Tomcat高可用负载均衡架构
[原文]https://www.toutiao.com/i6591714650205716996/ 一.概述 初期的互联网企业由于业务量较小,所以一般单机部署,实现单点访问即可满足业务的需求,这也是最 ...
- 基于Consul的数据库高可用架构【转】
几个月没有更新博客了,已经长草了,特意来除草.本次主要分享如何利用consul来实现redis以及mysql的高可用.以前的公司mysql是单机单实例,高可用MHA加vip就能搞定,新公司mysql是 ...
- Nginx入门篇(七)之Nginx+keepalived高可用集群
一.keepalived介绍 keepalived软件最开始是转为负载均衡软件LVS而设计,用来管理和监控LVS集群系统中各个服务节点的状态,后来又加入了可实现高可用的VRRP功能.所以Keepali ...
- kubernetes部署高可用Harbor
前言 本文Harbor高可用依照Harbor官网部署,主要思路如下,大家可以根据具体情况选择搭建. 部署Postgresql高可用集群.(本文选用Stolon进行管理,请查看文章<kuberne ...
随机推荐
- Python——9函数式编程②
*/ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...
- 如何优化自己的JS代码
尽管接触大大小小项目N多个,但是刚入行两年, 撸码还是没有完全成一定的规律:最近受到很多启发,打算沉淀沉淀自己的代码: 之前很多页面的很多js脚本本分代码,更注重效果,事件久后没有发展 性能也是很关键 ...
- PHP时区转换(默认中国时区<Asia/Shanghai>转意大利时区<Europe/Rome>)
<?php function changeTimeZone($date_time, $format = 'Y-m-d H:i:s', $to = 'Europe/Rome', $from = ' ...
- 【DirectX 11学习笔记】世界矩阵的理解-运动合成
最近在看龙书,写一下自己的学习理解,主要是物体运动的合成. 物体于局部坐标系内构建,每个物体拥有自己的局部坐标系以及相应的顶点矩阵A,并通过世界矩阵变换到唯一的世界坐标系. 物体在某时刻发生了位移和旋 ...
- 【技巧】歪脑筋优化flexbox瀑布流布局方案
效果先行 需求 在大量"不定宽"元素并排的布局模式下,上图是我们想要的最佳布局但是FlexBox布局虽然枪弹但并不能完全呈现以上布局,于是我们需要结合FlexBox作下小的改动即可 ...
- leetcode 219
固定长度的滑动窗口+set class Solution { public: bool containsNearbyDuplicate(vector<int>& nums, int ...
- RestTemplate 负载均衡原理
RestTemplate 是通过拦截器改变请求的URI的方式来指定服务器的,此处将通过一个自定义LoadBalanced的方式来进行说明 1.导入jar包 <parent> <gro ...
- Resource interpreted as Stylesheet but transferred with MIME type text/html: css失效
异常信息: Resource interpreted as Stylesheet but transferred with MIME type text/html: 可能原因 过滤器或者某个地方对所有 ...
- qtp10安装步骤(比较完整)
在安装qtp之前,要提前安装软件(不知道是干嘛的,反正安装就完了),右键--管理员运行完成安装,如下图: 解压qtp镜像: 双击setup: 第一步,点击第一排 第二步, 注:安装QTP系统提示“ 计 ...
- CTR学习笔记&代码实现1-深度学习的前奏LR->FFM
CTR学习笔记系列的第一篇,总结在深度模型称王之前经典LR,FM, FFM模型,这些经典模型后续也作为组件用于各个深度模型.模型分别用自定义Keras Layer和estimator来实现,哈哈一个是 ...