简体   繁体   English

木偶:不同节点上资源之间的关系

[英]Puppet: relationship between resources on different nodes

I know that we can specify relationship between resources, which determines the deployment order. 我知道我们可以指定资源之间的关系,从而确定部署顺序。 But is it possible to create relationship between resources on different nodes in Puppet? 但是有可能在Puppet中不同节点上的资源之间创建关系吗?

For example, I have apache web server in node A and mysql server in node B. I want to start mysql first before starting apache web server. 例如,我在节点A中有apache Web服务器,在节点B中有mysql服务器。我想先启动mysql,然后再启动apache web服务器。 How could I express this in Puppet language? 我该如何用人偶语言表达?


I have tried the following codes: 我尝试了以下代码:

node ‘host1’ {
  @@service { ‘mysql’:
    ensure => running,
    tag => ‘host1-mysql’,
  }
}
node ‘host2’ {
  service { ‘apache2’:
    ensure => running,
  }
  Service<<| tag == ‘host1-mysql’ |>> -> Service[‘apache2’]
}

But it didn't work - produced a compile error. 但这没有用-产生了编译错误。 Any other solution? 还有其他解决方案吗?

In a distributed "puppet" setup, the apply order isn't guaranteed. 在分布式“人偶”设置中,不能保证申请顺序。

Puppet don't do orchestration across multiple nodes. 木偶跨多个节点进行编排 At best, your changes will get applied multiple times on the machines and finally will converge to the desired state . 充其量,您的更改将在计算机上多次应用, 最后收敛到所需的状态

Dependencies only work in a same node. 依赖项仅在同一节点上工作。 You can actually get values of resources exported by others nodes (for eg to configure the firewall of your db to allow the web server to do sql) Or cheat with hiera to know who have the "db" and "app" roles. 实际上,您可以获取由其他节点导出的资源的值(例如,配置数据库的防火墙以允许Web服务器执行sql),或者通过hiera作弊以了解谁具有“ db”和“ app”角色。

For orchestration see tools like mcollective , capistrano, ansible ,... 对于编排,请参见mcollective ,capistrano, ansible ,...之类的工具。

Whenever a resource depends on another resource, use the before or require metaparameter or chain the resources with -> . 每当资源依赖于另一资源时,请使用before或require元参数,或使用->链接资源。 Whenever a resource needs to refresh when another resource changes, use the notify or subscribe metaparameter or chain the resources with ~> . 每当另一个资源更改时需要刷新资源时,请使用notify或subscription元参数,或使用~>链接资源。 Some resources will autorequire other resources if they see them, which can save you some effort. 某些资源(如果看到)将自动要求其他资源,这可以节省您的精力。

Refer to link for more precision. 请参阅链接以获取更多精度。

In init.pp where you declare/instantiate these classes, replace the include statements with parameterized class syntax: 在声明/实例化这些类的init.pp中,用参数化类语法替换include语句:

class {"taskname":} -> class {"taskname2":}
This will ensure taskname is invoked before taskname2. 这将确保在taskname2之前调用taskname。

Check link 检查链接

A bit of googling for puppet node dependency turns up some links about exported resources, which seems like the way to go. puppet node dependency进行一些谷歌搜索会发现有关导出资源的一些链接,这似乎是可行的方法。

According to http://docs.puppetlabs.com/puppet/latest/reference/lang_exported.html 根据http://docs.puppetlabs.com/puppet/latest/reference/lang_exported.html

Exported resources allow nodes to share information with each other. 导出的资源允许节点彼此共享信息。

Basically you export a resource in the node which it belongs to, and collect it in the node that requires it and use dependency arrows as usual. 基本上,您将资源导出到其所属的节点中,并在需要该资源的节点中进行收集,并照常使用依赖项箭头。

MCollective also appears to be an alternative, but seems to be a whole new framework. MCollective似乎也可以替代,但似乎是一个全新的框架。

You can't do that just using Puppet. 您不能仅使用Puppet来做到这一点。 Conceptually, with Puppet you generate a static description of a node configuration, and then you apply it. 从概念上讲,使用Puppet可以生成节点配置的静态描述,然后将其应用。 The exported resources system is convenient, but doesn't fundamentally changes the way Puppet works (you can convince yourself by noticing you could just hardcode the resources, and this would have the exact same effect). 导出的资源系统很方便,但是并没有从根本上改变Puppet的工作方式(您可以通过注意到您可以对资源进行硬编码来说服自己,这将产生完全相同的效果)。

For this reason, you need another kind of orchestration system, and you should not set enable => running on your services. 因此,您需要另一种业务流程系统,并且不应在服务上设置enable => running

Unfortunately, I do not have great recommendations : 不幸的是,我没有很好的建议:

  • I only used heartbeat, which in my experience was hard to configure, unreliable, and very limited (only a handful of nodes are supported). 我仅使用心跳,以我的经验,它很难配置,不可靠且非常有限(仅支持少数几个节点)。
  • Ubuntu has a juju tool that does exactly what you want and seems easy to use, but I have no experience with it. Ubuntu有一个juju工具,可以完全满足您的需求,并且似乎易于使用,但是我没有使用它的经验。
  • There is probably something equivalent in your distribution of choice. 您的选择分布中可能存在等同的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM