Chef中收敛性和幂等性的区别 [英] Difference between convergence and idempotence in Chef

查看:83
本文介绍了Chef中收敛性和幂等性的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Chef的收敛性和幂等性之间的基本区别是什么?

What is the basic difference between convergence and idempotence in Chef?

推荐答案

收敛性和幂等性不是Chef特定的。它们通常归因于配置管理理论,尽管在其他领域也有应用,尤其是在数学上。

Convergence and idempotence are not Chef-specific. They're generally attributed to configuration management theory, though have use in other fields, notably mathematics.

让我们从更基本的幂等开始。我们将忽略幂等的数学用法,而将重点放在人们谈论配置管理时的意义。也就是说:同一动作的多个应用程序不会对系统状态产生副作用。一个幂等运算的简单示例是 mkdir -p

Let's start with the more basic, idempotent. We're going to ignore the mathematic use of idempotent, and focus instead on what configuration management people mean when they talk about it. That is: "multiple applications of the same action do not have side effects on the system state." A simple example of an idempotent operation is mkdir -p:

mkdir -p /var/lib/statedir/myapp

无论我们运行此命令多少次,它将导致创建该树。表示幂等运算的另一种方法是,一遍又一遍地运行该工具不会在第一次之后更改系统。

No matter how many times we run this command, it will result in that tree being created. Another way of stating this about idempotent operations is, "running the tool over and over doesn't change the system after the first time."

现在,与收敛性进行对比。通常,融合意味着将[人或物]聚集在一起。在配置管理中,融合意味着使系统状态与定义的策略保持一致。也就是说,仅在需要进行更改时才在系统上进行更改。收敛操作的一个简单示例是:

Now to contrast that with convergence. Generically, to converge means to bring [people or] things together. In configuration management, convergence means to bring the system state in line with a defined policy. That is, changes are made on the system only if they need to be made. A simple example of a convergent operation is:

if [ ! -d /var/lib/statedir/myapp ]; then
  mkdir -p /var/lib/statedir/myapp
fi

这是收敛的,因为我们仅在所需目录不存在时才执行mkdir命令。我们也将其称为测试和修复操作。也就是说,我们测试正在管理的特定事物的当前状态,如果状态不是特定的,则使用特定的命令或操作对其进行修复。这就是Chef在幕后使用如下资源进行的操作:

This is convergent because we're only executing the mkdir command if the desired directory does not exist. We also call this a "test and repair" operation. That is, we test the current state of the specific thing we're managing, and then repair it with a specific command or operation if it is not in that state. That is what Chef does behind the scenes with a resource like this:

directory '/var/lib/statedir/myapp' do
  recursive true
end

我们(厨师)谈论此问题的方式是Chef采取幂等操作将系统收敛到各种资源声明的状态。 Chef中的每个资源都是声明性的,并对资源的当前状态执行测试,然后修复系统以使其匹配。

The way we (Chef) talk about this is that Chef takes idempotent actions to converge the system to the state declared by the various resources. Every resource in Chef is declarative, and performs a test about the current state of the resource, and then repairs the system to match that.

深入了解有关Chef的工作方式,在Chef运行中有一个编译阶段和一个收敛阶段。在编译阶段,它评估节点上的Ruby配方,并正在寻找添加到资源集合中的资源对象。对所有配方进行评估后,便会进入收敛阶段,在该阶段对资源集合进行迭代,并采取适当的措施将资源置于所需状态,从而创建用户,编写文件,安装软件包,等等。

To get deeper into the weeds about how Chef works, it has a "compile" phase and a "converge" phase in a Chef run. In the "compile" phase, it evaluates the Ruby recipes on the node, and it is looking for resource objects that it adds to a "resource collection." Once it has evaluated all the recipes, it then enters the "converge" phase where it iterates over the resource collection, taking the appropriate action to put the resources into the desired state, whereby users are created, files are written, packages are installed, and so forth.

这篇关于Chef中收敛性和幂等性的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆