fixed several bugs at ha cookbooks
Change-Id: I2bb16dcb60a7b51d76a7337ce1be1fe5a6c8aabf
This commit is contained in:
parent
88e6bd9d54
commit
66177e0196
@ -79,12 +79,15 @@ default['haproxy']['source']['use_pcre'] = false
|
|||||||
default['haproxy']['source']['use_openssl'] = false
|
default['haproxy']['source']['use_openssl'] = false
|
||||||
default['haproxy']['source']['use_zlib'] = false
|
default['haproxy']['source']['use_zlib'] = false
|
||||||
|
|
||||||
|
default['haproxy']['enable_services'] = []
|
||||||
|
|
||||||
default['haproxy']['listeners'] = {
|
default['haproxy']['listeners'] = {
|
||||||
'listen' => {},
|
'listen' => {},
|
||||||
'frontend' => {},
|
'frontend' => {},
|
||||||
'backend' => {}
|
'backend' => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
default['haproxy']['services'] = {
|
default['haproxy']['services'] = {
|
||||||
"dashboard_http" => {
|
"dashboard_http" => {
|
||||||
"role" => "os-compute-single-controller",
|
"role" => "os-compute-single-controller",
|
||||||
@ -96,8 +99,9 @@ default['haproxy']['services'] = {
|
|||||||
"mode http", \
|
"mode http", \
|
||||||
"option forwardfor", \
|
"option forwardfor", \
|
||||||
"option httpchk", \
|
"option httpchk", \
|
||||||
"option httpclose", \
|
"option httpclose"
|
||||||
"rspidel ^Set-cookie:\ IP="]
|
# "rspidel ^Set-cookie:\ IP="
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"dashboard_https" => {
|
"dashboard_https" => {
|
||||||
"role" => "os-compute-single-controller",
|
"role" => "os-compute-single-controller",
|
||||||
|
@ -19,16 +19,19 @@
|
|||||||
|
|
||||||
package "haproxy"
|
package "haproxy"
|
||||||
|
|
||||||
directory node['haproxy']['conf_dir']
|
|
||||||
|
|
||||||
template "/etc/init.d/haproxy" do
|
case node['platform_family']
|
||||||
source "haproxy-init.erb"
|
when "debian"
|
||||||
owner "root"
|
directory node['haproxy']['conf_dir']
|
||||||
group "root"
|
template "/etc/init.d/haproxy" do
|
||||||
mode 00755
|
source "haproxy-init.erb"
|
||||||
variables(
|
owner "root"
|
||||||
:hostname => node['hostname'],
|
group "root"
|
||||||
:conf_dir => node['haproxy']['conf_dir'],
|
mode 00755
|
||||||
:prefix => "/usr"
|
variables(
|
||||||
)
|
:hostname => node['hostname'],
|
||||||
|
:conf_dir => node['haproxy']['conf_dir'],
|
||||||
|
:prefix => "/usr"
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,38 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
defaultbag = "openstack"
|
||||||
|
if !Chef::DataBag.list.key?(defaultbag)
|
||||||
|
Chef::Application.fatal!("databag '#{defaultbag}' doesn't exist.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
myitem = node.attribute?('cluster')? node['cluster']:"env_default"
|
||||||
|
|
||||||
|
if !search(defaultbag, "id:#{myitem}")
|
||||||
|
Chef::Application.fatal!("databagitem '#{myitem}' doesn't exist.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
mydata = data_bag_item(defaultbag, myitem)
|
||||||
|
|
||||||
|
if mydata['ha']['status'].eql?('enable')
|
||||||
|
node.set['haproxy']['incoming_address'] = mydata['ha']['haproxy']['vip']
|
||||||
|
mydata['ha']['haproxy']['roles'].each do |role, services|
|
||||||
|
services.each do |service|
|
||||||
|
node.set['haproxy']['services'][service]['role'] = role
|
||||||
|
unless node['haproxy']['enable_services'].include?(service)
|
||||||
|
node.set['haproxy']['enable_services'] << service
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
node['haproxy']['services'].each do |name, service|
|
node['haproxy']['services'].each do |name, service|
|
||||||
|
unless node['haproxy']['enable_services'].include?(name)
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
pool_members = search("node", "role:#{service['role']} AND chef_environment:#{node.chef_environment}") || []
|
pool_members = search("node", "role:#{service['role']} AND chef_environment:#{node.chef_environment}") || []
|
||||||
|
|
||||||
# load balancer may be in the pool
|
# load balancer may be in the pool
|
||||||
@ -44,7 +75,7 @@ node['haproxy']['services'].each do |name, service|
|
|||||||
pool = ["options httpchk #{node['haproxy']['httpchk']}"] if node['haproxy']['httpchk']
|
pool = ["options httpchk #{node['haproxy']['httpchk']}"] if node['haproxy']['httpchk']
|
||||||
pool = service[:options]
|
pool = service[:options]
|
||||||
servers = pool_members.uniq.map do |s|
|
servers = pool_members.uniq.map do |s|
|
||||||
"#{s[:hostrame]} #{s[:ipaddress]}:#{service[:backend_port]} check inter 2000 rise 2 fall 5"
|
"#{s[:hostname]} #{s[:ipaddress]}:#{service[:backend_port]} check inter 2000 rise 2 fall 5"
|
||||||
end
|
end
|
||||||
|
|
||||||
haproxy_lb name do
|
haproxy_lb name do
|
||||||
@ -72,4 +103,3 @@ service "haproxy" do
|
|||||||
supports :restart => true, :status => true, :reload => true
|
supports :restart => true, :status => true, :reload => true
|
||||||
action [:enable, :start]
|
action [:enable, :start]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
default['keepalived']['shared_address'] = false
|
default['keepalived']['shared_address'] = true
|
||||||
default['keepalived']['global']['notification_emails'] = 'admin@example.com'
|
default['keepalived']['global']['notification_emails'] = 'admin@example.com'
|
||||||
default['keepalived']['global']['notification_email_from'] = "keepalived@#{node['domain'] || 'example.com'}"
|
default['keepalived']['global']['notification_email_from'] = "keepalived@#{node['domain'] || 'example.com'}"
|
||||||
default['keepalived']['global']['smtp_server'] = '127.0.0.1'
|
default['keepalived']['global']['smtp_server'] = '127.0.0.1'
|
||||||
@ -18,20 +18,23 @@ default['keepalived']['check_scripts'] = {
|
|||||||
default['keepalived']['instance_defaults']['state'] = 'MASTER'
|
default['keepalived']['instance_defaults']['state'] = 'MASTER'
|
||||||
default['keepalived']['instance_defaults']['priority'] = 100
|
default['keepalived']['instance_defaults']['priority'] = 100
|
||||||
default['keepalived']['instance_defaults']['virtual_router_id'] = 10
|
default['keepalived']['instance_defaults']['virtual_router_id'] = 10
|
||||||
|
default['keepalived']['vip'] = {
|
||||||
|
"eth0" => "10.145.88.161"
|
||||||
|
}
|
||||||
default['keepalived']['instances'] = {
|
default['keepalived']['instances'] = {
|
||||||
"openstack" => {
|
"openstack" => {
|
||||||
"virtual_router_id" => "50",
|
"virtual_router_id" => "50",
|
||||||
"advert_int" => "1",
|
"advert_int" => "1",
|
||||||
"priorities" => {
|
"priorities" => {
|
||||||
"centos-10-145-88-152" => "110",
|
"centos-10-145-88-152" => 110,
|
||||||
"centos-10-145-88-153" => "101"
|
"centos-10-145-88-153" => 101
|
||||||
},
|
},
|
||||||
"states" => {
|
"states" => {
|
||||||
"centos-10-145-88-152" => "BACKUP",
|
"centos-10-145-88-152" => "BACKUP",
|
||||||
"centos-10-145-88-153" => "MASTER"
|
"centos-10-145-88-153" => "MASTER"
|
||||||
},
|
},
|
||||||
"interface" => "eth0",
|
"interface" => "eth0",
|
||||||
"ip_addresses" => ["192.168.220.40 dev eth0"],
|
"ip_addresses" => ["#{node['keepalived']['vip']['eth0']} dev eth0"],
|
||||||
"track_script" => "haproxy"
|
"track_script" => "haproxy"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,16 +17,73 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
require 'chef/util/file_edit'
|
||||||
|
|
||||||
|
defaultbag = "openstack"
|
||||||
|
if !Chef::DataBag.list.key?(defaultbag)
|
||||||
|
Chef::Application.fatal!("databag '#{defaultbag}' doesn't exist.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
myitem = node.attribute?('cluster')? node['cluster']:"env_default"
|
||||||
|
|
||||||
|
if !search(defaultbag, "id:#{myitem}")
|
||||||
|
Chef::Application.fatal!("databagitem '#{myitem}' doesn't exist.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
mydata = data_bag_item(defaultbag, myitem)
|
||||||
|
|
||||||
|
if mydata['ha']['status'].eql?('enable')
|
||||||
|
mydata['ha']['keepalived']['router_ids'].each do |nodename, routerid|
|
||||||
|
node.override['keepalived']['global']['router_ids']["#{nodename}"] = routerid
|
||||||
|
end
|
||||||
|
|
||||||
|
mydata['ha']['keepalived']['instance_name']['priorities'].each do |nodename, priority|
|
||||||
|
node.override['keepalived']['instances']['openstack']['priorities']["#{nodename}"] = priority
|
||||||
|
end
|
||||||
|
|
||||||
|
mydata['ha']['keepalived']['instance_name']['states'].each do |nodename, status|
|
||||||
|
node.override['keepalived']['instances']['openstack']['states']["#{nodename}"] = status
|
||||||
|
end
|
||||||
|
|
||||||
|
interface = node['keepalived']['instances']['openstack']['interface']
|
||||||
|
node.override['keepalived']['instances']['openstack']['ip_addresses'] = [
|
||||||
|
"#{mydata['ha']['keepalived']['instance_name']['vip']} dev #{interface}" ]
|
||||||
|
end
|
||||||
|
|
||||||
package "keepalived"
|
package "keepalived"
|
||||||
|
|
||||||
if node['keepalived']['shared_address']
|
if node['keepalived']['shared_address']
|
||||||
file '/etc/sysctl.d/60-ip-nonlocal-bind.conf' do
|
case node['platform_family']
|
||||||
mode 0644
|
when "debian"
|
||||||
content "net.ipv4.ip_nonlocal_bind=1\n"
|
file '/etc/sysctl.d/60-ip-nonlocal-bind.conf' do
|
||||||
end
|
mode 0644
|
||||||
|
content "net.ipv4.ip_nonlocal_bind=1\n"
|
||||||
|
end
|
||||||
|
|
||||||
service 'procps' do
|
service 'procps' do
|
||||||
action :start
|
action :start
|
||||||
|
end
|
||||||
|
|
||||||
|
when "rhel"
|
||||||
|
ruby_block "update sysctl" do
|
||||||
|
block do
|
||||||
|
fe = Chef::Util::FileEdit.new('/etc/sysctl.conf')
|
||||||
|
fe.search_file_delete_line(/^net.ipv4.ip_nonlocal_bind\s*=\s*0/)
|
||||||
|
fe.write_file
|
||||||
|
fe.insert_line_if_no_match(/^net.ipv4.ip_nonlocal_bind\s*=s*1/,
|
||||||
|
"net.ipv4.ip_nonlocal_bind = 1")
|
||||||
|
fe.write_file
|
||||||
|
end
|
||||||
|
not_if %Q|grep "^net.ipv4.ip_nonlocal_bind[[:space:]]*=[[:space:]]*1" /etc/sysctl.conf|
|
||||||
|
notifies :run, "execute[apply sysctl]", :immediately
|
||||||
|
end
|
||||||
|
|
||||||
|
execute "apply sysctl" do
|
||||||
|
command "sysctl -p"
|
||||||
|
action :nothing
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user