当前位置: 首页 > news >正文

内容转载的网站怎么做公司网站开发

内容转载的网站怎么做,公司网站开发,前端线下培训,wordpress创建公告前言 Docker Compose 则进一步简化了多个容器应用的编排与管理。另一方面#xff0c;Consul 作为一款先进的服务发现工具#xff0c;为分布式和微服务架构提供了可靠的服务注册与发现机制。本文将探讨 Docker Compose 和 Consul 在容器化环境中的协同作用#xff0c;以及它…前言 Docker Compose 则进一步简化了多个容器应用的编排与管理。另一方面Consul 作为一款先进的服务发现工具为分布式和微服务架构提供了可靠的服务注册与发现机制。本文将探讨 Docker Compose 和 Consul 在容器化环境中的协同作用以及它们如何共同帮助开发人员更高效地构建、部署和管理其应用程序。 Docker Compose相关介绍请参考 Docker-Compose单机多容器应用编排与管理-CSDN博客 目录 一、概述 1. 服务注册与发现 2. 什么是 consul 3. 服务架构 3.1 传统架构 3.2 consul 架构 4. 关键特性 二、Consul 部署 1. 容器服务更新与发现拓扑图 2. 部署信息 3. consul 服务器 3.1 建立 consul 服务 3.2 查看集群信息 3.3 通过 http api 获取集群信息 4. registrator 服务器 4.1 安装 Gliderlabs/Registrato 4.2 测试服务发现功能是否正常 4.3 验证 http 和 nginx 服务是否注册到 consul  5. consul-template  5.1 准备 template nginx 模板文件 5.2 安装配置 nginx 服务 5.3 配置并启动 template 5.4 访问 template-nginx 5.5 增加一个 nginx 容器节点 6. consul 多节点 6.1 安装 docker  6.2 拷贝 consul 相关服务文件启动 consul 服务 6.3 查看集群信息 一、概述 1. 服务注册与发现 ① 服务注册在Docker中运行的应用程序可以通过Consul客户端向Consul服务注册自己的信息包括服务名称、IP地址、端口号等。这样Consul就会维护一个服务目录记录着所有可用的服务实例及其位置信息。 ② 服务发现其他Docker容器或应用程序可以通过Consul客户端查询Consul服务注册中心动态地发现和连接到需要的服务。Consul根据服务名称、标签、健康状态等条件来选择合适的服务实例实现服务间的通信和协作。 2. 什么是 consul Consul 是一种开源的服务发现和配置管理工具由 HashiCorp 开发。它提供了一系列功能包括服务注册、服务发现、健康检查、KV存储等旨在简化构建和管理分布式系统的过程。 ① 服务注册与发现Consul 允许服务实例向 Consul 注册其信息包括服务名称、网络位置IP地址和端口号、健康状态等。其他服务或客户端可以通过 Consul 查询服务注册中心动态地发现和连接到需要的服务从而实现服务间的通信。 ② 健康检查Consul 可以定期对服务实例进行健康检查以确保服务的可用性。如果一个服务实例不健康Consul 会将其标记为不可用同时通知其他服务实例进行相应的调整保证系统的稳定性。 ③ KV 存储Consul 提供了一个分布式的键值存储系统允许用户存储和检索配置信息、应用程序状态等。这个功能对于动态配置和共享状态在分布式系统中是非常有用的。 ④ 多数据中心支持Consul 支持多数据中心部署可以轻松地在不同地理位置的数据中心中管理和发现服务提高系统的可用性和容错性。 3. 服务架构 3.1 传统架构 在 upstream 块中需要指定后端服务器的 IP 地址和端口号即 ip:port在proxy_pass指令中需要指定转发请求的目标 当需要添加新的后端服务器时需要修改代理端配置文件且需要重启服务才可以生效有一定的局限性。 3.2 consul 架构 后端服务 A-N 可以把当前自己的网络位置注册到服务发现模块服务发现就以 K-V 的方式记录下来K 一般是服务名V 就是 ip:port。服务发现模块定时的进行健康检查轮询查看这些后端服务能不能访问的了。前端在调用后端服务 A-N 的时候会先询问服务发现模块后端服务的网络位置然后再调用它们的服务。  4. 关键特性 服务注册与发现consul通过DNS或者HTTP接口使服务注册和服务发现变的很容易一些外部服务例如saas提供的也可以一样注册健康检查健康检测使consul可以快速的告警在集群中的操作。和服务发现的集成可以防止服务转发到故障的服务上面Key/Value存储一个用来存储动态配置的系统。提供简单的HTTP接口可以在任何地方操作。多数据中心无需复杂的配置即可支持任意数量的区域。 二、Consul 部署 1. 容器服务更新与发现拓扑图 Consul Template Consul Template守护进程是Consul Template工具的一部分用于监视Consul中的键值存储KV中的变化并根据这些变化来更新本地的配置文件。它可以在后台运行并定期检查Consul中的数据以确保生成的配置文件与最新的配置信息保持同步是一个配置文件模板可以获取注册中心所有的服务发现然后将服务发现的名称:端口号转发给 Nginx并且更新 nginx.conf 文件。 Consul Server 作为注册中心Consul Server 负责维护服务目录记录当前可用的服务实例及其位置信息负责执行健康检查来确保服务的可用性定期检查服务实例的健康状态如果某个服务实例出现故障或不可用Consul会将其标记为不健康并从服务目录中移除同时服务实例新增或者恢复Consul会将其加入到服务目录中提供了KV存储用于存储配置信息、应用程序状态等。这个分布式键值存储可以用于共享配置、动态更新应用程序参数等场景支持事件处理机制可以发布和订阅各种事件例如服务状态变更、健康检查结果等。 Consul Agent 是一个轻量级的代理程序用于运行在每个部署了服务的节点上。它负责与Consul集群通信并执行各种任务包括服务注册、健康检查、服务发现和处理来自其他节点的RPC请求等。  Registrator 是一个服务注册器它是一个独立的进程运行在容器编排环境中它的主要作用是监视运行中的服务实例并将它们注册到服务发现系统中例如Consul或etcd。通过这种注册其他服务可以发现并与这些服务进行通信而无需事先知道它们的位置或IP地址。 2. 部署信息 服务节点ip安装运行服务docker版本consul 服务器192.168.190.107运行consul服务、nginx服务、consul-template守护进程26.0.2registrator 服务器192.168.190.108运行registrator容器、运行nginx容器20.10.17consul 服务器192.168.190.106运行consul服务26.0.2 3. consul 服务器 3.1 建立 consul 服务 ① 二进制包直接安装 [rootconsul ~]# mkdir /opt/consul [rootconsul ~]# cd /opt/consul/ [rootconsul consul]# ls consul_0.9.2_linux_amd64.zip # 准备二进制包 [rootconsul consul]# unzip consul_0.9.2_linux_amd64.zip [rootconsul consul]# mv consul /usr/local/bin/ ② 设置代理后台启动 consul 服务端 [rootconsul consul]# consul agent \-server \-bootstrap \-ui \-data-dir/var/lib/consul-data \-bind192.168.190.107 \-client0.0.0.0 \-nodeconsul-server01 /var/log/consul.log [1] 7694③ 启动 consul 后默认会监听5个端口 [rootconsul consul]# netstat -natp | grep consul tcp 0 0 192.168.190.107:8300 0.0.0.0:* LISTEN 37870/consul tcp 0 0 192.168.190.107:8301 0.0.0.0:* LISTEN 37870/consul tcp 0 0 192.168.190.107:8302 0.0.0.0:* LISTEN 37870/consul tcp6 0 0 :::8500 :::* LISTEN 37870/consul tcp6 0 0 :::8600 :::* LISTEN 37870/consul # 8300replication、leader farwarding的端口 # 8301lan cossip的端口 # 8302wan gossip的端口 # 8500web ui界面的端口 # 8600使用dns协议查看节点信息的端口 3.2 查看集群信息 ① 查看members状态 [rootconsul consul]# consul members Node Address Status Type Build Protocol DC consul-server01 192.168.190.107:8301 alive server 0.9.2 2 dc1② 查看集群状态 [rootconsul consul]# consul operator raft list-peers # 获取Consul集群中Raft协议的节点列表 Node ID Address State Voter RaftProtocol consul-server01 192.168.190.107:8300 192.168.190.107:8300 leader true 2 [rootconsul consul]# consul info | grep leaderleader trueleader_addr 192.168.190.107:8300 3.3 通过 http api 获取集群信息 [rootconsul consul]# curl 127.0.0.1:8500/v1/status/peers [192.168.190.107:8300] # 查看集群server成员 [rootconsul consul]# curl 127.0.0.1:8500/v1/status/leader 192.168.190.107:8300 # 集群 server-leader [rootconsul consul]# curl 127.0.0.1:8500/v1/catalog/services {consul:[]} # 注册的所有服务 [rootconsul consul]# curl 127.0.0.1:8500/v1/catalog/nginx # 查看 nginx 服务信息 [rootconsul consul]# curl 127.0.0.1:8500/v1/catalog/nodes [{ID:f17caaee-ff27-b4e8-c592-afcdad3a2e47,Node:consul-server01,Address:192.168.190.107,Datacenter:dc1,TaggedAddresses:{lan:192.168.190.107,wan:192.168.190.107},Meta:{},CreateIndex:5,ModifyIndex:6}] # 集群节点详细信息 4. registrator 服务器 4.1 安装 Gliderlabs/Registrato Gliderlabs/Registrator 可检查容器运行状态自动注册还可注销 docker 容器的服务到服务配置中心。目前支持 Consul、Etcd 和 SkyDNS2。运行一个 Registrator 容器开启自动发现服务 [rootregistrator ~]# docker run -d \ # 运行Docker容器并将其设置为后台运行--nameregistrator \ # 指定名称为registrator--nethost \ # 使用主机网络模式-v /var/run/docker.sock:/tmp/docker.sock \ # 将主机的Docker守护进程的Unix套接字映射到容器内的/tmp/docker.sock这样Registrator容器就可以与 Docker守护进程通信--restartalways \ # 容器遇到错误或意外退出时自动重启gliderlabs/registrator:latest \ # 使用镜像gliderlabs/registrator来运行容器:latest表示使用最新版本的镜像--ip192.168.190.108 \ # 设置Registrator容器的IP地址为192.168.10.13consul://192.168.190.107:8500 # 192.168.190.107:8500是Consul的地址和端口 4.2 测试服务发现功能是否正常 [rootregistrator ~]# docker run -itd -p:1080:80 --name nginx-01 -h nginx1 nginx [rootregistrator ~]# docker run -itd -p:1081:80 --name nginx-02 -h nginx2 nginx [rootregistrator ~]# docker run -itd -p:1082:80 --name apache-01 -h apache1 httpd [rootregistrator ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3004e92d23e4 httpd httpd-foreground 8 seconds ago Up 7 seconds 0.0.0.0:1082-80/tcp, :::1082-80/tcp apache-01 108612e81495 nginx /docker-entrypoint.… 2 minutes ago Up 2 minutes 0.0.0.0:1081-80/tcp, :::1081-80/tcp nginx-02 dfbfe87308ed nginx /docker-entrypoint.… 2 minutes ago Up 2 minutes 0.0.0.0:1080-80/tcp, :::1080-80/tcp nginx-01 53166bf2c442 gliderlabs/registrator:latest /bin/registrator --… 23 minutes ago Up 23 minutes registrator # 一个发现服务两个容器服务 4.3 验证 http 和 nginx 服务是否注册到 consul  [rootconsul consul]# curl 127.0.0.1:8500/v1/catalog/services {consul:[],httpd:[],nginx:[]} 5. consul-template  Consul-Template是基于Consul的自动替换配置文件的应用。Consul-Template是一个守护进程用于实时查询Consul集群信息并更新文件系统上任意数量的指定模板生成配置文件。更新完成以后可以选择运行 shell 命令执行更新操作重新加载 Nginx。 Consul-Template可以查询Consul中的服务目录、Key、Key-values 等。这种强大的抽象功能和查询语言模板可以使 Consul-Template 特别适合动态的创建配置文件。例如创建Apache/Nginx Proxy Balancers 、 Haproxy Backends等。 5.1 准备 template nginx 模板文件 在consul服务器上操作 [rootconsul consul]# vim /opt/consul/nginx.ctmpl upstream http_backend {{{range service nginx}}server {{.Address}}:{{.Port}};{{end}} } # 定义nginx upstream一个模板server {listen 8000;server_name localhost 192.168.190.107;access_log /var/log/nginx/kgc.com-access.log; index index.html index.php;location / {proxy_set_header HOST $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header Client-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://http_backend;} } # 定义一个server监听8000端口反向代理到upstream5.2 安装配置 nginx 服务 在 consul 节点安装  [rootconsul consul]# yum install -y epel-release.noarch [rootconsul consul]# yum install -y nginx [rootconsul consul]# vim /etc/nginx/nginx.conf http {include vhost/*.conf; # 添加虚拟主机目录创建虚拟主机目录 [rootconsul consul]# cd /etc/nginx/ [rootconsul nginx]# mkdir vhost 启动nginx服务 [rootconsul nginx]# systemctl start nginx.service 5.3 配置并启动 template 在 consul 节点操作  [rootconsul opt]# ls consul-template_0.19.3_linux_amd64.zip # 准备安装包 [rootconsul opt]# unzip consul-template_0.19.3_linux_amd64.zip [rootconsul opt]# mv consul-template /usr/local/bin/在前台启动template服务启动后不要按ctrlc中止consul-template进程 consul-template --consul-addr 192.168.190.107:8500 \ --template /opt/consul/nginx.ctmpl:/etc/nginx/vhost/fqlnginx.conf:/usr/sbin/nginx -s reload \ --log-levelinfo另外打开一个终端查看生成配置文件 [rootconsul opt]# cd /etc/nginx/vhost/ [rootconsul vhost]# ls fqlnginx.conf [rootconsul vhost]# cat fqlnginx.conf upstream http_backend {server 192.168.190.108:1080;server 192.168.190.108:1081;}server {listen 8000;server_name localhost 192.168.190.107;access_log /var/log/nginx/kgc.com-access.log;index index.html index.php;location / {proxy_set_header HOST $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header Client-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://http_backend;} }5.4 访问 template-nginx 在 registrator 节点操作  [rootregistrator ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3004e92d23e4 httpd httpd-foreground 15 hours ago Up 15 hours 0.0.0.0:1082-80/tcp, :::1082-80/tcp apache-01 108612e81495 nginx /docker-entrypoint.… 15 hours ago Up 15 hours 0.0.0.0:1081-80/tcp, :::1081-80/tcp nginx-02 dfbfe87308ed nginx /docker-entrypoint.… 15 hours ago Up 15 hours 0.0.0.0:1080-80/tcp, :::1080-80/tcp nginx-01 53166bf2c442 gliderlabs/registrator:latest /bin/registrator --… 15 hours ago Up 15 hours registrator[rootregistrator ~]# docker exec -it nginx-01 /bin/bash rootnginx1:/# echo this is web1 nginx_01 /usr/share/nginx/html/index.html rootnginx1:/# exit [rootregistrator ~]# docker exec -it nginx-02 /bin/bash rootnginx2:/# echo this is web2 nginx_02 /usr/share/nginx/html/index.html rootnginx2:/# exit 访问 192.168.190.107:8000/ 查看轮询结果 [rootregistrator ~]# curl http://192.168.190.107:8000 this is web1 nginx_01 [rootregistrator ~]# curl http://192.168.190.107:8000 this is web2 nginx_02 [rootregistrator ~]# curl http://192.168.190.107:8000 this is web1 nginx_01 [rootregistrator ~]# curl http://192.168.190.107:8000 this is web2 nginx_02 5.5 增加一个 nginx 容器节点 ① 增加一个 nginx 容器节点测试服务发现及配置更新功能 [rootregistrator ~]# docker run -itd -p:1083:80 --name nginx-03 -h nginx3 nginx # 观察template服务会从模板更新/usr/local/nginx/conf/vhost/kgc.conf文件内容并且重载nginx服务 ② 查看 cousul 节点 template 更新的配置文件内容 [rootconsul vhost]# pwd /etc/nginx/vhost [rootconsul vhost]# ls fqlnginx.conf [rootconsul vhost]# cat fqlnginx.conf upstream http_backend {server 192.168.190.108:1080;server 192.168.190.108:1081;server 192.168.190.108:1083; # 新增了一个nginx服务} …… ③ 访问 192.168.190.107:8000/ 查看轮询结果 [rootregistrator ~]# docker exec -it nginx-03 /bin/bash rootnginx3:/# echo this is web3 nginx_03 /usr/share/nginx/html/index.html rootnginx3:/# exit[rootregistrator ~]# curl http://192.168.190.107:8000 this is web1 nginx_01 [rootregistrator ~]# curl http://192.168.190.107:8000 this is web2 nginx_02 [rootregistrator ~]# curl http://192.168.190.107:8000 this is web3 nginx_03 [rootregistrator ~]# curl http://192.168.190.107:8000 this is web2 nginx_02 [rootregistrator ~]# curl http://192.168.190.107:8000 this is web3 nginx_03 [rootregistrator ~]# curl http://192.168.190.107:8000 this is web1 nginx_01 ④ 停用 nginx-01 服务查看 template 更新的配置文件内容以及轮询结果 [rootregistrator ~]# docker stop nginx-01 nginx-01 [rootregistrator ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a9814459efac nginx /docker-entrypoint.… 6 minutes ago Up 6 minutes 0.0.0.0:1083-80/tcp, :::1083-80/tcp nginx-03 108612e81495 nginx /docker-entrypoint.… 15 hours ago Up 9 minutes 0.0.0.0:1081-80/tcp, :::1081-80/tcp nginx-02 53166bf2c442 gliderlabs/registrator:latest /bin/registrator --… 15 hours ago Up 9 minutes registrator[rootconsul vhost]# cat fqlnginx.conf upstream http_backend {server 192.168.190.108:1081;server 192.168.190.108:1083;} ……[rootregistrator ~]# curl http://192.168.190.107:8000 this is web2 nginx_02 [rootregistrator ~]# curl http://192.168.190.107:8000 this is web3 nginx_03 [rootregistrator ~]# curl http://192.168.190.107:8000 this is web2 nginx_02 [rootregistrator ~]# curl http://192.168.190.107:8000 this is web3 nginx_036. consul 多节点 添加一台 docker 环境的服务器 192.168.190.106/24 加入已有的群集中实际是为了扩展 consul 集群的规模和容量以提高系统的可用性和可靠性。 6.1 安装 docker  安装依赖包 yum install -y yum-utils device-mapper-persistent-data lvm2 设置阿里云镜像源 yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 安装最新版本 yum install -y docker-ce docker-ce-cli containerd.io systemctl start docker.service systemctl enable docker.service 6.2 拷贝 consul 相关服务文件启动 consul 服务 192.168.190.107: [rootconsul vhost]# scp /usr/local/bin/consul 192.168.190.106:/usr/local/bin/ 192.168.190.106: [rootha02 ~]# consul agent \-server \-ui \-data-dir/var/lib/consul-data \-bind192.168.190.106 \ # 指定Consul agent监听的IP地址用于节点间通信-client0.0.0.0 \-nodeconsul-server02 \ # 指定当前节点的名称为consul-server02-enable-script-checkstrue \-datacenterdc1 \ # 指定Consul集群所属的数据中心名称为dc1-join 192.168.190.107 /var/log/consul.log # 加入已知的Consul节点这里指定加入IP地址为192.168.190.107的节点 [1] 31716.3 查看集群信息 查看members状态 [rootha02 ~]# consul members Node Address Status Type Build Protocol DC consul-server01 192.168.190.107:8301 alive server 0.9.2 2 dc1 consul-server02 192.168.190.106:8301 alive server 0.9.2 2 dc1 查看集群状态 [rootha02 ~]# consul operator raft list-peers Node ID Address State Voter RaftProtocol consul-server01 192.168.190.107:8300 192.168.190.107:8300 leader true 2 consul-server02 192.168.190.106:8300 192.168.190.106:8300 follower true 2 # 192.168.190.106状态为follower
http://www.hkea.cn/news/14293270/

相关文章:

  • 购物网站最重要的功能北京装饰公司前十名
  • 保险代理做的比较好的网站网站 域名空间 调试
  • 如何上传ftp网站程序珠海网站建设专业设计
  • 龙门城乡规划建设局网站wordpress底部自豪
  • 深圳招聘网站开发wordpress 主页修改
  • 山东省专业群建设网站网站建设公司ejiew
  • 做虚拟货币交易网站一级A做爰片安全网站
  • 自己电脑做服务器网站吗pda智能巡检系统
  • 南京网站制作百家号商务网站建设与维护 课件
  • 奉化网站建设报价用c 实现网站开发
  • 英文网站标题字体科技公司网站制作模板
  • 甘肃省网站备案优化大师怎么强力卸载
  • 网站建设公司推广方式科技软件公司网站模板
  • 网站流量团队房地产客户管理系统有哪些
  • 网络服务的重要性网站优化营销
  • 网站域名收费吗域名购买推荐
  • 专注苏州网站优化热门页游排行榜前十名
  • 网站建设东莞海南网站优化公司
  • 计算机网站开发是那个语言如何还原wordpress
  • 备案的网站如何访问炫酷网站欣赏
  • 公司网站开发维护06628 网页制作与网站建设
  • 网站建设遇到问题解决方案站内免费推广
  • wordpress 中文版下载网站关键词优化哪家正规
  • 网站百度关键词排名软件wordpress 脚本慢
  • 我和你99谁做的网站163企业邮箱怎么开通注册账号
  • 人力资源网站建设方案目前主流搜索引擎是哪种
  • 品牌网站建设毛尖2租房网 wordpress
  • 怎么用lofter做网站餐饮营销方案
  • 单页网站 开元wordpress博客小工具标签
  • 织梦网站管理安装婚纱摄影网页制作