是否可以只有一个领事服务器为 rails 应用程序提供密钥对?

Is it possible to have only one consul server to serve key-pairs for rails app?

我想知道是否可以只使用一台 consul 服务器来处理 consul 服务器键值对。

我正在尝试将领事服务器设置为仅存储我的 rails 应用程序的键值对。我只设置了一个将充当代理的领事服务器。但是在设置领事的 web-ui 时遇到问题。

我尝试运行一个物理实例作为consul服务器来服务consului的web-

consul agent -server -data-dir /tmp/consul -ui-dir /home/ubuntu/dist/

比访问consul web-ui 在public ip 我运行下面的命令

consul members -rpc-addr=X.X.X.X:8400

出现以下错误

Error connecting to Consul agent: dial tcp X.X.X.X:8400: connection refused

其中X.X.X.X是实例的私有ip

默认情况下代理在本地主机上启动客户端,由于文档:

Client Addr: This is the address used for client interfaces to the agent. This includes the ports for the HTTP, DNS, and RPC interfaces. The RPC address is used by other consul commands (such as consul members, consul join, etc) which query and control a running agent. By default, this binds only to localhost. If you change this address or port, you'll have to specify a -rpc-addr whenever you run commands such as consul members to indicate how to reach the agent. Other applications can also use the RPC address and port to control Consul.

所以你需要设置一个标志-client=X.X.X.X来设置远程访问客户端的IP地址。尝试使用此命令启动您的服务器:

consul agent -server -bootstrap -data-dir /tmp/consul -ui-dir /home/ubuntu/dist/ -client=X.X.X.X

其中 X.X.X.X 您的 IP 地址。要检查该选项是否被接受,请检查服务器输出,它包含如下一行:

 Client Addr: X.X.X.X(HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)

要访问 WebUI,请在您的网络浏览器中打开此 link:http://X.X.X.X:8500/ui

至于consul members命令,它只是打印给你这个代理已知成员的列表,所以不需要执行它,使用WebUI。

是的,这是可能的,但这不是一个好主意。 Consul 经过优化以在分布式架构中运行,其中对网络分区的容忍度是主要关注点。只有一个节点,你会更好地与像 Redis 这样的东西分开。它会更快并且可以扩展到更大的客户群。继续阅读 CAP Theorum

  • Redis 针对一致性和可用性进行了优化。
  • Consul 针对可用性和分区容错性进行了优化(如果 运行 作为集群)。

对于单个节点,没有理由为 K/V 使用 Consul,但如果您还想要它的服务发现、DNS、事件和锁定功能,那么这是有原因的。