如何在 OpsWorks 上升级 HAProxy

How to upgrade HAProxy on OpsWorks

我们将 AWS OpsWorks 堆栈与 Chef 版本 11.10 结合使用。与default HAProxy Layer。我们想将 HAProxy 升级到最新版本 1.6-stable(从默认的 1.4-stable)。 我们的 Ubuntu 版本似乎有一个 dedicated PPA

但是我们在哪里可以让 OpsWorks 使用这个 PPA 安装 HAProxy?

default cookbook there is a default attributes file中有如下几行:

default[:haproxy][:version] = '1.4.22'
default[:haproxy][:patchlevel] = '1'
default[:haproxy][:rpm] = "haproxy-#{node[:haproxy][:version]}-#{node[:haproxy][:patchlevel]}.#{rhel_arch}.rpm"
default[:haproxy][:rpm_url] = "#{node[:opsworks_commons][:assets_url]}/packages/#{node[:platform]}/#{node[:platform_version]}/#{node[:haproxy][:rpm]}"

在我们的食谱中覆盖文件并天真地更改版本号并没有达到预期的效果。

我们最终像这样覆盖了食谱 haproxy/recipes/default.rb

#Install software-properties-common if not installed
package 'software-properties-common' do
  action :install
end

#Add PPA for haproxy 1.6 and update repo
execute "add-ppa-update" do
  command "add-apt-repository ppa:vbernat/haproxy-1.6 && apt-get update -y"
  action :run
end

package "haproxy" do
  retries 3
  retry_delay 5

  version '1.6.4-3ppa1~trusty'
  action  :install
end

if platform?('debian','ubuntu')
  template '/etc/default/haproxy' do
    source 'haproxy-default.erb'
    owner 'root'
    group 'root'
    mode 0644
  end
end

include_recipe 'haproxy::service'

template '/etc/haproxy/haproxy.cfg' do
  source 'haproxy.cfg.erb'
  owner 'root'
  group 'root'
  mode 0644
  notifies :restart, "service[haproxy]"
end

template "/etc/haproxy/server.pem" do
  source    "server.pem.erb"
  owner     'root'
  group     'root'
  mode      0600
  notifies  :restart, "service[haproxy]"
end

service 'haproxy' do
  action [:enable, :start]
end

此外,我们需要更新 haproxy.conf 以使用新版本。

现在一切都运行得很漂亮。