Automating a RabbitMQ Cluster Deployment on Windows with Powershell DSC
This one has been annoying me for a while, but I finally got to the bottom of it!
The solution is really very simple, but with not a lot of love for Rabbit on Windows and nothing I could find on using DSC, it took longer than it really should have.
Hope this helps someone
The solution is really very simple, but with not a lot of love for Rabbit on Windows and nothing I could find on using DSC, it took longer than it really should have.
Hope this helps someone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
configuration RabbitMQServers | |
{ | |
Import-DscResource -ModuleName xPSDesiredStateConfiguration -Name MSFT_xPackageResource | |
Import-DscResource -ModuleName PSDscResources | |
node localhost { | |
#Download and install Erlang | |
xPackage InstallErlang { | |
Ensure = 'Present' | |
ProductId = '' | |
Name = 'Erlang OTP 21 (10.0.1)' | |
Arguments = "/S /D=c:\tools\erlang" | |
Path = 'https://<yourstorage>/installs/otp_win64_21.0.1.exe' | |
} | |
#Hack to set up the RABBITMQ_BASE environment variable | |
#Without this, it'll try to set it to the AppData folder of Local System which doesn't exist. | |
Environment RabbitMQ_Base | |
{ | |
Name = 'RABBITMQ_BASE' | |
Value = 'C:\RABBITMQ' | |
Ensure = 'Present' | |
Path = $false | |
Target = @('Process', 'Machine') | |
} | |
Script RabbitFiles { | |
GetScript = {@{ Result = 'Hello' }} | |
SetScript = { | |
# Set Erlang Cookie | |
$erlangcookiefile = "c:\windows\system32\config\systemprofile\.erlang.cookie" | |
$erlangcookievalue = "XXXXXXXXXXXXXXXXXXXX" | |
Set-Content -Path $erlangcookiefile -Value $erlangcookievalue -Force | |
$rabbitpath = "C:\RABBITMQ" | |
md $rabbitpath -Force | |
# Set Rabbit Config | |
$rabbitconffile = "$rabbitpath\rabbitmq.conf" | |
$rabbitconffiledata = @" | |
cluster_formation.peer_discovery_backend = rabbit_peer_discovery_classic_config | |
cluster_formation.classic_config.nodes.1 = rabbit@$rab01 | |
cluster_formation.classic_config.nodes.2 = rabbit@$rab02 | |
cluster_formation.classic_config.nodes.3 = rabbit@$rab03 | |
cluster_formation.node_type = disc | |
cluster_partition_handling = pause_minority | |
"@ | |
Set-Content -Path $rabbitconffile -Value $rabbitconffiledata -force | |
# Set Rabbit Plugins | |
$pluginfile = "$rabbitpath\enabled_plugins" | |
$pluginfiledata = '[rabbitmq_management].' | |
Set-Content -Path $pluginfile -Value $pluginfiledata -Force | |
} | |
TestScript = { | |
Test-Path "f:\rabbitmq\rabbitmq.conf" | |
} | |
DependsOn = @("[xPackage]InstallErlang") | |
} | |
#Download and install RabbitMQ | |
xPackage InstallRabbitMQ { | |
Ensure = 'Present' | |
ProductId = '' | |
Name = 'RabbitMQ Server 3.7.7' | |
Arguments = "/S" | |
Path = 'https://<yourstorage>/installs/rabbitmq-server-3.7.7.exe' | |
DependsOn = @("[xPackage]InstallErlang","[Environment]RabbitMQ_Base","[Script]RabbitFiles") | |
} | |
} | |
} |
Comments
Post a Comment