远程执行(Remote Execution)

如果要对consul集群进行统一的管理,如打安全补丁、更新软件等,可以利用到Consul的Remote Execution特性,在consul集群上执行统一的命令:

image-20211016185807439

开启Remote Execution

默认Remote Execution是关闭状态,需要在每个node单独开启。

开启方式:在启动时加上参数

consul agent -hcl 'disable_remote_exec=false'

重新启动client,并以remote execution模式运行:

image-20211016190550839


在consul server上执行ping命令:

image-20211016190510492

在client ip上成功执行完成。

由于server运行在8080端口,所以要指定http-addr。

<code>-http-addr=</code> - Address of the Consul agent with the port. This can be an IP address or DNS address, but it must include the port. This can also be specified via the CONSUL_HTTP_ADDR environment variable. In Consul 0.8 and later, the default value is http://127.0.0.1:8500 , and https can optionally be used instead.


如果在server上也开启Remote Execution,运行consul exec时,会同时在server和client上执行命令:

image-20211016190902665

image-20211016190948667


执行consul exec命令时,不局限于server端,在client上也可以执行这个命令

image-20211016191127236