Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Cluster support #26

Merged
merged 1 commit into from

3 participants

@jkff

This patch introduces support for configuring RabbitMQ in cluster mode.

@jkff

Disregard this for a while until I fix rspec tests.

@jkff

Fixed broken tests and added a new one for this feature.

@bodepd

@jkff This will take a little bit of time to review and I definitely will not get around to it before I leave for vacation.

manifests/server.pp
@@ -58,6 +60,7 @@
}
$plugin_dir = "/usr/lib/rabbitmq/lib/rabbitmq_server-${version_real}/plugins"
+ $erlang_cookie_content = 'EOKOWXQREETZSHFNTPEY'
@bodepd
bodepd added a note

make this a parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
manifests/server.pp
@@ -98,6 +101,22 @@
ensure => $service_ensure,
}
+ exec { 'rabbitmq_stop':
+ command => '/etc/init.d/rabbitmq-server stop; /bin/rm -rf /var/lib/rabbitmq/mnesia',
@bodepd
bodepd added a note

is there no way to explicitly reload the cookie other than deleting all of the data?

@bodepd
bodepd added a note

I woud feel a lot better about it if it were inside a if $config_cluster statement and if it took a backup first :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@bodepd

@jkff can you move all of the cluster specific config inside of a $config_cluster conditional statement?

@jkff

@bodepd Fixed. The best I could do was 1) move everything under $config_cluster 2) introduce a parameter that denotes whether the user consents to wiping their RabbitMQ database. My research showed that there is no non-contrived way to change a node's cookie without wiping the database (the Mnesia backup/restore process doesn't work because RabbitMQ stores Erlang PID's in Mnesia which obviously are meaningless across process restarts)

manifests/server.pp
((6 lines not shown))
$node_ip_address = 'UNSET',
$config='UNSET',
- $env_config='UNSET'
+ $env_config='UNSET',
+ $erlang_cookie='EOKOWXQREETZSHFNTPEY',
+ $wipe_db_on_cookie_change=false,
@bodepd
bodepd added a note

remove trailing command for 2.6.x compat

@bodepd
bodepd added a note

there is not test for this parameter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@bodepd bodepd commented on the diff
manifests/server.pp
((6 lines not shown))
$node_ip_address = 'UNSET',
$config='UNSET',
- $env_config='UNSET'
+ $env_config='UNSET',
+ $erlang_cookie='EOKOWXQREETZSHFNTPEY',
@bodepd
bodepd added a note

there is not test for erlang_cookie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@ryanycoleman

Hi @bodepd & @jkff, are there further changes required to make this patch-set acceptable for merge?

@bodepd

my only concern was the config file. I wanted to do some testing before I merged it which I have not gotten around to.

@jkff

Whew, it's been a while. I completely forgot about this pullrequest.

I fixed the extra comma and added tests for erlang cookie.

@bodepd bodepd commented on the diff
spec/classes/rabbitmq_server_spec.rb
@@ -68,7 +68,7 @@
describe 'not configuring stomp by default' do
it 'should not specify stomp parameters in rabbitmq.config' do
verify_contents(subject, 'rabbitmq.config',
- ['[].'])
+ ['[','].'])
@bodepd
bodepd added a note

I am a little confused about where this , comes from, and if this is valid syntax for the config file. I need to do some reading about this.

@jkff
jkff added a note

It's the difference between []. and
[
].

The new code does the latter because it's easier to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@bodepd bodepd merged commit 4fcb719 into puppetlabs:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 13, 2012
  1. @jkff

    Cluster support

    jkff authored
This page is out of date. Refresh to see the latest.
View
14 README.md
@@ -37,6 +37,20 @@ Class for installing rabbitmq-server:
delete_guest_user => true,
}
+### Clustering
+To use RabbitMQ clustering and H/A facilities, use the rabbitmq::server
+parameters `config_cluster` and `cluster_disk_nodes`, e.g.:
+
+ class { 'rabbitmq::server':
+ config_cluster => true,
+ cluster_disk_nodes => ['rabbit1', 'rabbit2'],
+ }
+
+Currently all cluster nodes are registered as disk nodes (not ram).
+
+**NOTE:** You still need to use `x-ha-policy: all` in your client
+applications for any particular queue to take advantage of H/A, this module
+merely clusters RabbitMQ instances.
## Native Types
View
44 manifests/server.pp
@@ -13,6 +13,14 @@
# [*node_ip_address*] - ip address for rabbitmq to bind to
# [*config*] - contents of config file
# [*env_config*] - contents of env-config file
+# [*config_cluster*] - whether to configure a RabbitMQ cluster
+# [*cluster_disk_nodes*] - which nodes to cluster with (including the current one)
+# [*erlang_cookie*] - erlang cookie, must be the same for all nodes in a cluster
+# [*wipe_db_on_cookie_change*] - whether to wipe the RabbitMQ data if the specified
+# erlang_cookie differs from the current one. This is a sad parameter: actually,
+# if the cookie indeed differs, then wiping the database is the *only* thing you
+# can do. You're only required to set this parameter to true as a sign that you
+# realise this.
# Requires:
# stdlib
# Sample Usage:
@@ -30,9 +38,13 @@
$service_ensure = 'running',
$config_stomp = false,
$stomp_port = '6163',
+ $config_cluster = false,
+ $cluster_disk_nodes = [],
$node_ip_address = 'UNSET',
$config='UNSET',
- $env_config='UNSET'
+ $env_config='UNSET',
+ $erlang_cookie='EOKOWXQREETZSHFNTPEY',
@bodepd
bodepd added a note

there is not test for erlang_cookie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ $wipe_db_on_cookie_change=false
) {
validate_bool($delete_guest_user, $config_stomp)
@@ -79,8 +91,36 @@
owner => '0',
group => '0',
mode => '0644',
+ require => Package[$package_name],
notify => Class['rabbitmq::service'],
- require => Package[$package_name]
+ }
+
+ if $config_cluster {
+ file { 'erlang_cookie':
+ path =>"/var/lib/rabbitmq/.erlang.cookie",
+ owner => rabbitmq,
+ group => rabbitmq,
+ mode => '0400',
+ content => $erlang_cookie,
+ replace => true,
+ before => File['rabbitmq.config'],
+ require => Exec['wipe_db'],
+ }
+ # require authorize_cookie_change
+
+ if $wipe_db_on_cookie_change {
+ exec { 'wipe_db':
+ command => '/etc/init.d/rabbitmq-server stop; /bin/rm -rf /var/lib/rabbitmq/mnesia',
+ require => Package[$package_name],
+ unless => "/bin/grep -qx ${erlang_cookie} /var/lib/rabbitmq/.erlang.cookie"
+ }
+ } else {
+ exec { 'wipe_db':
+ command => '/bin/false "Cookie must be changed but wipe_db is false"', # If the cookie doesn't match, just fail.
+ require => Package[$package_name],
+ unless => "/bin/grep -qx ${erlang_cookie} /var/lib/rabbitmq/.erlang.cookie"
+ }
+ }
}
file { 'rabbitmq-env.config':
View
32 spec/classes/rabbitmq_server_spec.rb
@@ -68,7 +68,7 @@
describe 'not configuring stomp by default' do
it 'should not specify stomp parameters in rabbitmq.config' do
verify_contents(subject, 'rabbitmq.config',
- ['[].'])
+ ['[','].'])
@bodepd
bodepd added a note

I am a little confused about where this , comes from, and if this is valid syntax for the config file. I need to do some reading about this.

@jkff
jkff added a note

It's the difference between []. and
[
].

The new code does the latter because it's easier to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
end
end
@@ -80,9 +80,37 @@
end
it 'should specify stomp port in rabbitmq.config' do
verify_contents(subject, 'rabbitmq.config',
- ['[ {rabbitmq_stomp, [{tcp_listeners, [5679]} ]} ].'])
+ ['[','{rabbitmq_stomp, [{tcp_listeners, [5679]} ]}','].'])
end
end
+ describe 'configuring cluster' do
+ let :params do
+ { :config_cluster => true,
+ :cluster_disk_nodes => ['hare-1', 'hare-2']
+ }
+ end
+ it 'should specify cluster nodes in rabbitmq.config' do
+ verify_contents(subject, 'rabbitmq.config',
+ ['[',"{rabbit, [{cluster_nodes, ['rabbit@hare-1', 'rabbit@hare-2']}]}", '].'])
+ end
+ it 'should have the default erlang cookie' do
+ verify_contents(subject, 'erlang_cookie',
+ ['EOKOWXQREETZSHFNTPEY'])
+ end
+
+ end
+
+ describe 'specifying custom erlang cookie in cluster mode' do
+ let :params do
+ { :config_cluster => true,
+ :erlang_cookie => 'YOKOWXQREETZSHFNTPEY' }
+ end
+ it 'should set .erlang.cookie to the specified value' do
+ verify_contents(subject, 'erlang_cookie',
+ ['YOKOWXQREETZSHFNTPEY'])
+ end
+ end
+
end
View
0  spec/fixtures/manifests/site.pp
No changes.
View
9 templates/rabbitmq.config
@@ -1,9 +1,12 @@
% This file managed by Puppet <%= puppetversion %>
% Template Path: <%= module_name %>/templates/rabbitmq.config
+[
+<% if config_cluster -%>
+{rabbit, [{cluster_nodes, [<%= cluster_disk_nodes.map { |n| "\'rabbit@#{n}\'" }.join(', ') %>]}]}<% if config_stomp -%>,<% end %>
+<% end -%>
<% if config_stomp -%>
% Configure the Stomp Plugin listening port
-[ {rabbitmq_stomp, [{tcp_listeners, [<%= stomp_port %>]} ]} ].
-<% else -%>
-[].
+{rabbitmq_stomp, [{tcp_listeners, [<%= stomp_port %>]} ]}
<% end -%>
+].
% EOF
Something went wrong with that request. Please try again.