puppet连载21:搭建rabbitmq

rabbitmq 3.6.6

cd /puppet/soft
wget http://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el7.centos.x86_64.rpm
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.6/rabbitmq-server-3.6.6-1.el7.noarch.rpm
wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
mkdir -p /etc/puppet/modules/linuxrabbitmq/{manifests,files,templates}


写配置文件

vi /etc/puppet/modules/linuxrabbitmq/templates/rabbitmq-env-3.6.6.conf.erb

RABBITMQ_NODE_IP_ADDRESS=0.0.0.0

RABBITMQ_NODE_PORT=<%= real_rabbitmq_port %>

RABBITMQ_NODENAME=<%= real_rabbitmq_name %>

RABBITMQ_CONFIG_FILE="/etc/rabbitmq/rabbitmq.conf"

RABBITMQ_MNESIA_BASE="/var/lib/rabbitmq/mnesia"

RABBITMQ_LOG_BASE="/var/log"

RABBITMQ_PLUGINS_DIR="/usr/lib/rabbitmq/lib/rabbitmq_server-3.6.6/plugins"


cp /usr/share/doc/rabbitmq-server-3.6.6/rabbitmq.config.example /etc/puppet/modules/linuxrabbitmq/templates/rabbitmq-3.6.6.conf.erb

vim /etc/puppet/modules/linuxrabbitmq/manifests/init.pp
class linuxrabbitmq::rabbitmq366 {

rabbitmq_port ? { '' => '5672',default => real_rabbitmq_mana_port=rabbitmq_mana_port }
rabbitmq_erl_port ? { '' => '25672',default => real_rabbitmq_name=fqdn',default => $rabbitmq_name }

file {"/usr/local/src/erlang-19.0.4-1.el7.centos.x86_64.rpm":
source => "puppet:///soft/erlang-19.0.4-1.el7.centos.x86_64.rpm",
ensure => file,
mode => 755,owner => root,group => root,
notify => Exec["rpm erlang-19.0.4-1.el7.centos.x86_64.rpm"],
}
file {"/usr/local/src/rabbitmq-server-3.6.6-1.el7.noarch.rpm":
source => "puppet:///soft/rabbitmq-server-3.6.6-1.el7.noarch.rpm",
ensure => file,
mode => 755,owner => root,group => root,
notify => Exec["yum rabbitmq-server-3.6.6-1.el7.noarch.rpm"],
require => File["/usr/local/src/rabbitmq-signing-key-public.asc"],
}
file {"/usr/local/src/rabbitmq-signing-key-public.asc":
source => "puppet:///soft/rabbitmq-signing-key-public.asc",
ensure => file,
mode => 755,owner => root,group => root,
notify => Exec["rpm rabbitmq-signing-key-public.asc"],
require => File["/usr/local/src/erlang-19.0.4-1.el7.centos.x86_64.rpm"],
}
exec {"rpm erlang-19.0.4-1.el7.centos.x86_64.rpm":
command => "rpm -ivh erlang-19.0.4-1.el7.centos.x86_64.rpm",
path => ["/usr/bin","/usr/sbin","/sbin","/bin"],
cwd => "/usr/local/src",
refreshonly => true,
}
exec {"rpm rabbitmq-signing-key-public.asc":
command => "rpm --import rabbitmq-signing-key-public.asc",
path => ["/usr/bin","/usr/sbin","/sbin","/bin"],
cwd => "/usr/local/src",
refreshonly => true,
}
exec {"yum rabbitmq-server-3.6.6-1.el7.noarch.rpm":
command => "yum -y install rabbitmq-server-3.6.6-1.el7.noarch.rpm",
path => ["/usr/bin","/usr/sbin","/sbin","/bin"],
cwd => "/usr/local/src",
refreshonly => true,
before => Service["rabbitmq-server"],
}
exec {"firewallrabbitmqport":
command => "firewall-cmd --add-port real_rabbitmq_mana_port/tcp --permanent && firewall-cmd --add-port real_rabbitmq_port/tcp'",
}
service {"rabbitmq-server":
ensure => running,
enable => true,
}
exec {"rabbitmq_management":
command => "rabbitmq-plugins enable rabbitmq_management&&rabbitmqctl add_user root root&&rabbitmqctl set_user_tags root administrator&&rabbitmqctl set_permissions -p / root '.' '.' '.*'",
path => ["/usr/sbin","/usr/bin","/bin","/sbin"],
require => Service["rabbitmq-server"],
unless => "rabbitmqctl list_users|grep root",
}
file {'/etc/rabbitmq/rabbitmq-env.conf':
ensure => file,
mode => 755,owner => root,group => root,
content => template("/etc/puppet/modules/linuxrabbitmq/templates/rabbitmq-env-3.6.6.conf.erb"),
backup => '.bak',
notify => Service["rabbitmq-server"],
require => Exec["yum rabbitmq-server-3.6.6-1.el7.noarch.rpm"],
}
file {'/etc/rabbitmq/rabbitmq.conf':
ensure => file,
mode => 755,owner => root,group => root,
content => template("/etc/puppet/modules/linuxrabbitmq/templates/rabbitmq-3.6.6.conf.erb"),
backup => '.bak',
notify => Service["rabbitmq-server"],
require => Exec["yum rabbitmq-server-3.6.6-1.el7.noarch.rpm"],
}
}


调用

node 'huangat-test' {
rabbitmq_mana_port = 15672
$rabbitmq_erl_port = 25672
include linuxrabbitmq::rabbitmq366
}


你可能感兴趣的:(puppet连载21:搭建rabbitmq)