Chef-在其他节点上触发重新启动服务 [英] Chef - Trigger reboot service on different node

查看:73
本文介绍了Chef-在其他节点上触发重新启动服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于要使用Chef管理的某些应用程序,我有一个主节点和一个客户端节点。它们都指向一个包含配置文件的共享文件夹,其中包含有关所有客户端和主服务器的信息。因此,每次安装客户端应用程序(在另一个客户端节点上)时,都应重新加载/重新启动主节点上的应用程序-并将其主机名添加到该共享文件中。

I have a master node and client nodes for some application that I want to manage with Chef. They all pointing to one shared folder with configuration file that contain info about all the clients and a master. Thus, app on master node should be reloaded/rebooted each time a client app (on another client node) is installed - and its hostname added to that one shared file.

有什么主意如何触发从客户端节点重新启动主节点上的主应用程序?

Any ideas how can I trigger restart of the Master app on Master node from a client node?

推荐答案

停止使用共享文件,这是您体系结构中的SPOF,并且会遇到非常非常高的并发问题。

Stop using a shared file, this is a SPOF in your architecture and subject to very very very much concurrency problems.

Chef有一个为此,它是搜索

Chef has a feature for this, it is search.

考虑到这一点,我将在您的my_app食谱中添加两个食谱,即master.rb和client.rb

With this in mind I would do something along the line of having two recipes in your my_app cookbook, named master.rb and client.rb

在client.rb中除了安装客户端之外,还可以在节点上添加标签。 (或使用角色定义哪些是客户,等等)

In client.rb in addition to installing the client, add a tag to the node. (or use a role to define which are clients, etc)

tag('my_app_client') if !tagged?('my_app_client')

master = search(:node, 'tag:my_app_master') 
slaves = search(:node, 'tag:my_app_client') 

#Tricky line to add current node to the list of slaves, as in first run it won't have been indexed by chef.
slaves[] << node if !slaves.any? { |n| n['hostname'] == node['hostname'] } 

return is master.empty? # to avoid trying to write a file without master

template '/local/path/to/conffile' do
  source 'config.erb' 
  variables({ 
    :master => master
    :slaves => slaves
  })
end

在master.rb中,重复搜索和模板化:

in master.rb, repeat the search and templating:

tag('my_app_master') if !tagged?('my_app_master')

master = search(:node, 'tag:my_app_master') 
slaves = search(:node, 'tag:my_app_client') 

#Tricky line to add current node as the master, as in first run it won't have been indexed by chef.
master = node if !master.any? { |n| n['hostname'] == node['hostname'] } 

template '/local/path/to/conffile' do
  source 'config.erb' 
  variables({ 
    :master => master
    :slaves => slaves
  })
  notify :restart,"service[my_app_service]", :immediately
end

在config.erb文件中,例如:

And in the config.erb file for example:

master_host: <%= @master['hostname'] %>
<%- @slaves.each_with_index do |s,i|
  slave_host<%= i %>: <%= s['hostname'] %>
<%- end %>

索引管理有些延迟,每个Macine上的文件可能有点不同步如果厨师计划的订单没有精心计划。

There's some indexing delay to manage, and probably the files on each macine could be a little out of sync if the chef-run order is not carefully planned.

如果让厨师定期运行,它将在整个运行间隔的两倍内收敛整个群集。

If you keep chef running periodically, it will converge your entire cluster within twice the run interval at maximum.

这篇关于Chef-在其他节点上触发重新启动服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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