如何使用Puppet或MCollective部署滚动式OS升级和重启?


8

我正在寻找对我的基础架构进行定期滚动升级的最佳方法。

通常,这涉及到在每台主机上一次执行一次:

sudo yum update -y && sudo reboot

但是,我达到了可扩展性的极限。

我只想一次在每个角色中一次重新引导一个节点,所以,例如,我不会同时删除所有的负载平衡器或数据库集群成员。

理想情况下,我想执行以下操作:

for role in $(< roles_list.txt) ; do
    mco package update_all_and_reboot \
        --batch 1 --batch-sleep 90 \
        -C $role -F environment=test
done

但是,这似乎并不存在。我不确定使用“ shell”代理是否是最佳方法?

mco shell run 'yum update -y && reboot' \
    --batch 1 --batch-sleep 90

但是,我只是在寻找错误的工具来完成这项工作吗?有什么更好的方法来管理这种滚动重启,但是我可以以某种方式链接到我分配给Puppet的角色,这样我就不会因为一次不删除任何重要信息而感到自在,但我仍然可以做一些并行更新和重启?


为什么要重启(unix.stackexchange.com/a/28162/65367)?是否需要伪造或也允许其他解决方案?
030

由于最近有频繁的Linux内核更新,因此确实需要重新启动。
pioto

好。我已经对其进行了测试,并且可以在我的系统上运行。您也可以在系统上检查它吗?
030

Answers:


2

组态

部署

cd /usr/share/ruby/vendor_ruby/mcollective/application
wget https://raw.githubusercontent.com/arnobroekhof/mcollective-plugin-power/master/application/power.rb

cd /usr/libexec/mcollective/mcollective/agent
wget https://raw.githubusercontent.com/arnobroekhof/mcollective-plugin-power/master/agent/power.ddl
wget https://raw.githubusercontent.com/arnobroekhof/mcollective-plugin-power/master/agent/power.rb

在两个主机上,即test-server1test-server2

服务

在两个服务上重新启动mcollective:

[vagrant@test-server1 ~]# sudo service mcollective restart

[vagrant@test-server2 ~]# sudo service mcollective restart

指令

在mcollective服务器节点上运行以下命令:

主持人test-server2正在监听:

[vagrant@test-server1 ~]$ mco ping
test-server2                             time=25.32 ms
test-server1                             time=62.51 ms


---- ping statistics ----
2 replies max: 62.51 min: 25.32 avg: 43.91

重新启动test-server2

[vagrant@test-server1 ~]$ mco power reboot -I test-server2

 * [ ============================================================> ] 1 / 1

test-server2                             Reboot initiated

Finished processing 1 / 1 hosts in 123.94 ms

test-server2是重新启动:

[vagrant@test-server1 ~]$ mco ping
test-server1                             time=13.87 ms


---- ping statistics ----
1 replies max: 13.87 min: 13.87 avg: 13.87

并已重新启动:

[vagrant@test-server1 ~]$ mco ping
test-server1                             time=22.88 ms
test-server2                             time=54.27 ms


---- ping statistics ----
2 replies max: 54.27 min: 22.88 avg: 38.57

请注意,也可以关闭主机:

[vagrant@test-server1 ~]$ mco power shutdown -I test-server2

 * [ ============================================================> ] 1 / 1

test-server2                             Shutdown initiated

Finished processing 1 / 1 hosts in 213.18 ms

原始码

/usr/libexec/mcollective/mcollective/agent/power.rb

module MCollective
  module Agent
    class Power<RPC::Agent

      action "shutdown" do
  out = ""
  run("/sbin/shutdown -h now", :stdout => out, :chomp => true )
  reply[:output] = "Shutdown initiated"
      end

      action "reboot" do
  out = ""
  run("/sbin/shutdown -r now", :stdout => out, :chomp => true )
  reply[:output] = "Reboot initiated"
      end

    end
  end
end

# vi:tabstop=2:expandtab:ai:filetype=ruby

/usr/libexec/mcollective/mcollective/agent/power.ddl

metadata    :name        => "power",
            :description => "An agent that can shutdown or reboot them system",
            :author      => "A.Broekhof",
            :license     => "Apache 2",
            :version     => "2.1",
            :url         => "http://github.com/arnobroekhof/mcollective-plugins/wiki",
            :timeout     => 5

action "reboot", :description => "Reboots the system" do
    display :always

    output :output,
           :description => "Reboot the system",
           :display_as => "Power"
end

action "shutdown", :description => "Shutdown the system" do
    display :always

    output :output,
           :description => "Shutdown the system",
           :display_as  => "Power"
end

/usr/share/ruby/vendor_ruby/mcollective/application/power.rb

class MCollective::Application::Power<MCollective::Application
  description "Linux Power broker"
  usage "power [reboot|shutdown]"

  def post_option_parser(configuration)
    if ARGV.size == 1
      configuration[:command] = ARGV.shift
    end
  end

  def validate_configuration(configuration)
    raise "Command should be one of reboot or shutdown" unless configuration[:command] =~ /^shutdown|reboot$/

  end

  def main
    mc = rpcclient("power")

    mc.discover :verbose => true
    mc.send(configuration[:command]).each do |node|
      case configuration[:command]
      when "reboot"
        printf("%-40s %s\n", node[:sender], node[:data][:output])
      when "shutdown"
        printf("%-40s %s\n", node[:sender], node[:data][:output])
      end 
    end

    printrpcstats

    mc.disconnect

  end

end

# vi:tabstop=2:expandtab:ai

修改后的代码

/usr/libexec/mcollective/mcollective/agent/power.ddl

metadata    :name        => "power",
            :description => "An agent that can shutdown or reboot them system",
            :author      => "A.Broekhof",
            :license     => "Apache 2",
            :version     => "2.1",
            :url         => "http://github.com/arnobroekhof/mcollective-plugins/wiki",
            :timeout     => 5

action "update-and-reboot", :description => "Reboots the system" do
    display :always

    output :output,
           :description => "Reboot the system",
           :display_as => "Power"
end

/usr/libexec/mcollective/mcollective/agent/power.rb

module MCollective
  module Agent
    class Power<RPC::Agent    
      action "update-and-reboot" do
        out = ""
        run("yum update -y && /sbin/shutdown -r now", :stdout => out, :chomp => true )
        reply[:output] = "Reboot initiated"
      end
    end
  end
end

# vi:tabstop=2:expandtab:ai:filetype=ruby

命令

[vagrant@test-server1 ~]$ mco power update-and-reboot -I test-server2

 * [ ============================================================> ] 1 / 1


Finished processing 1 / 1 hosts in 1001.22 ms

非常详细,谢谢。我正在寻找一个可以一次执行更新和重新引导的命令,例如mco power update-and-reboot -I test-servers。然后,mco将更新和重新引导应用于一台服务器,等待其恢复,然后再应用于第二台。
本杰明·古德克里
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.