您当前的位置:首页 > 网站建设 > 网站维护
| php | asp | css | H5 | javascript | Mysql | Dreamweaver | Delphi | 网站维护 | 帝国cms | React | 考试系统 | ajax | jQuery |

搭建Consul服务发现与服务网格

51自学网 2022-07-22 18:49:22
  网站维护

第一部分:Consul 基础

1,Consul 介绍

官网文档描述:Consul 是一个网络工具,提供功能齐全的服务网格和服务发现。

它可以做什么:自动化网络配置,发现服务并启用跨任何云或运行时的安全连接。

那么,我们对 Consul 的理解,就是服务网格、服务发现,官网文档说的这两个特征,到底是啥意思?跨什么云?

下面,我们将通过实践操作,逐渐了解 Consul,搭建出一个真实的 Consul 服务来体验。

2,安装 Consul

两台服务器上都需要安装 Consul,具体步骤可以参考下面的说明。

Ubuntu/Debian 系统

# 添加 GPG keycurl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -# 添加 仓库# 如果执行后提示  apt-add-repository: command not found# 可先安装: apt-get install software-properties-commonsudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"# 更新源以及安装 consulsudo apt-get update && sudo apt-get install consul

Centos/RHEL 系统

# 使用 yum-config-manager 管理仓库sudo yum install -y yum-utils# 连接仓库sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo# 安装sudo yum -y install consul

检查安装

可输入 consul 检查是否安装成功,如果有信息输出即说明安装成功。

root@50skbjiynxyxkcfh:~# consulUsage: consul [--version] [--help] <command> [<args>]Available commands are:    acl            Interact with Consul's ACLs    agent          Runs a Consul agent    catalog        Interact with the catalog    config         Interact with Consul's Centralized Configurations    connect        Interact with Consul Connect    debug          Records a debugging archive for operators    event          Fire a new event    exec           Executes a command on Consul nodes... ...

3,运行 Consul Agent

文章一般都会说一个 Consul 服务或者一个 Consul 实例,官网文档称为 Agent,这个要记住。为了避免误解,本文提到的代理指 proxy,一般使用 proxy 和 agent 单词说明。

Agent 可以以服务器模式(server mode)或客户端模式(client mode)运行,多个Agent 组成一个 Consul datacenter,每个 Consul datacenter 至少有一个 Agent 属于 服务器模式。

官方不建议单服务器部署。

启动 agent

前面说到过,agent 表示一个 Consul 实例。

因为现在处于探索实践阶段,为了避免各种加密安全问题等,我们需要使用 -dev 参数,以开发模式启动。

# $> consul agent# Runs a Consul agentconsul agent -dev

执行这个命令后,consul 会被启动起来,并且占用终端。

启动过程中注意留意信息,如果启动失败,需要自行根据提示解决问题。如端口冲突:

发现数据中心成员

执行 consul members 命令可以发现数据中心成员。

root@50skbjiynxyxkcfh:~# consul membersNode              Address          Status  Type    Build  Protocol  DC   Segment50skbjiynxyxkcfh  172.31.0.6:8301  alive   client  0.5.2  2         dc1  <default>

意思是检查当前 Consul 服务的成员组成,目前是单服务器,所以只有一个成员。

这里不需要留意有什么用途,只要记得这个命令就行,后面我们会使用到这个命令查看信息。

查看 UI

假如服务器 IP 是 172.31.0.6 ,则可以通过 http://172.31.0.6:8500 访问 consul 的 UI服务(http apis)。

4,在 Consul Service Discovery 中注册服务

本小节将介绍 Consul 中的一些网络知识,端口与dns的说明;

然后通过实例讲解如何定义服务以及注册服务到 Consul 中 -- Consul 服务发现。

端口

这里先说明一些 Consul 的端口。

官网文档:Before running Consul, you should ensure the following bind ports are accessible.

翻译:在运行 Consul 之前,需要确保以下端口都是可以访问的。

文档地址:https://www.consul.io/docs/install/ports.html

对于一些重要的配置,要查看官方文档原版,别百度,很多文章只是机器翻译或者 copy 命令,会让你进坑的。

UseDefault Ports
DNS: The DNS server (TCP and UDP)8600
HTTP: The HTTP API (TCP Only)8500
HTTPS: The HTTPs APIdisabled (8501)*
gRPC: The gRPC APIdisabled (8502)*
LAN Serf: The Serf LAN port (TCP and UDP)8301
Wan Serf: The Serf WAN port (TCP and UDP)8302
server: Server RPC address (TCP Only)8300
Sidecar Proxy Min: Inclusive min port number to use for automatically assigned sidecar service registrations.21000
Sidecar Proxy Max: Inclusive max port number to use for automatically assigned sidecar service registrations.21255

*For HTTPS and gRPC the ports specified in the table are recommendations.

  • 8500(http)、8501(https)、8502(gRPC) 三个接口可以通过远程请求调用相关的服务,或者直接访问。

  • 8501,8502 两个端口都是 disabled,所以我们可以先看一下 8500 端口的作用,其他端口后面慢慢用到再解释。


下载地址:
iSCSI服务器CHAP双向认证配置及创建步骤
Kubernetes部署实例并配置Deployment、网络映射、副本集

51自学网,即我要自学网,自学EXCEL、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。
京ICP备13026421号-1