How Do You Install RabbitMQ Server on Any Distribution of Linux?

Problem scenario
You want to install RabbitMQ on any distribution of Linux using the same script. How do you write such a script?

Solution

1.a. If you are using SUSE or a Red Hat deriviative of Linux (e.g., CentOS/RHEL/Fedora), go to step #2.

1.b. If you are using Debian or Ubuntu Linux, read the following. There may be manual steps (often three steps with Ubuntu 18.04 in AWS). If prompted for "Configuring grub-pc" you are asked "What do you want to do about modified configuration file grub?", choose "keep local version currently installed". If you are prompted with "A new version of /boot/grub/menu.lst is available, but the version installed currently has been locally modified…What do you want to do about menu.lst?", choose "keep local version currently installed".

2. Create a file in /tmp/ called rabbit.sh with the following lines:

rabbitmqversion=3.6.15

distro=$(cat /etc/*-release | grep NAME)

debflag=$(echo $distro | grep -i "ubuntu")
if [ -z "$debflag" ]
then # If it is not Ubuntu, test if it is Debian.
debflag=$(echo $distro | grep -i "debian")
echo "determining Linux distribution…"
else
echo "You have Ubuntu Linux!"
fi

rhflag=$(echo $distro | grep -i "red*hat")
if [ -z "$rhflag" ]
then #If it is not RedHat, see if it is CentOS or Fedora.
rhflag=$(echo $distro | grep -i "centos")
if [ -z "$rhflag" ]
then #If it is neither RedHat nor CentOS, see if it is Fedora.
echo "It does not appear to be CentOS or RHEL…"
rhflag=$(echo $distro | grep -i "fedora")
fi
fi

if [ -z "$rhflag" ]
then
echo "…still determining Linux distribution…"
else
echo "You have a RedHat distribution (e.g., CentOS, RHEL, or Fedora)"
yum -y install gcc zip elixir
makeversion=4.2
curl -Lk http://ftp.gnu.org/gnu/make/make-$makeversion.tar.gz > /tmp/make-$makeversion.tar.gz
cp /tmp/make-$makeversion.tar.gz /bin/
cd /bin
tar -zxvf make-$makeversion.tar.gz
cd make-$makeversion
./configure
make
make install
cp make /bin/
# install Erlang
curl -Lk https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm > /tmp/epel-release-latest-7.noarch.rpm
rpm -ivh /tmp/epel-release-latest-7.noarch.rpm
yum -y install erlang
curl -Lk https://www.rabbitmq.com/releases/rabbitmq-server/v$rabbitmqversion/rabbitmq-server-$rabbitmqversion.tar.xz > /tmp/rabbitmq-server-$rabbitmqversion.tar.xz
cp /tmp/rabbitmq-server-$rabbitmqversion.tar.xz /bin/
cd /bin
tar xf rabbitmq-server-$rabbitmqversion.tar.xz
cd rabbitmq-server-$rabbitmqversion
make
make install
fi

if [ -z "$debflag" ]
then
echo "…still determining Linux distribution…"
echo "But if the distribution was part of the Red Hat family, you can ignore the above message."
else
echo "You are using either Ubuntu Linux or Debian Linux."
apt -y update
apt -y install make xsltproc zip erlang-runtime-tools erlang-tools erlang-dev erlang-base erlang-ssl python erlang-nox erlang-src
apt -y upgrade
curl -Lk https://www.rabbitmq.com/releases/rabbitmq-server/v$rabbitmqversion/rabbitmq-server-$rabbitmqversion.tar.xz > /tmp/rabbitmq-server-$rabbitmqversion.tar.xz
cp /tmp/rabbitmq-server-$rabbitmqversion.tar.xz /bin/
cd /bin
tar xf rabbitmq-server-$rabbitmqversion.tar.xz
echo '{application, 'rabbit_common', [
{description, "Modules shared by rabbitmq-server and rabbitmq-erlang-client"},
{vsn, "$rabbitmqversion"},
{id, ""},
{modules, ['app_utils','code_version','credit_flow','delegate','delegate_sup','ec_semver','ec_semver_parser','file_handle_cache','file_handle_cache_stats','gen_server2','mirrored_supervisor','mnesia_sync','mochijson2','mochinum','mochiweb_util','pmon','priority_queue','rabbit_amqqueue_common','rabbit_auth_backend_dummy','rabbit_auth_mechanism','rabbit_authn_backend','rabbit_authz_backend','rabbit_backing_queue','rabbit_basic_common','rabbit_binary_generator','rabbit_binary_parser','rabbit_cert_info','rabbit_channel_common','rabbit_command_assembler','rabbit_control_misc','rabbit_core_metrics','rabbit_data_coercion','rabbit_error_logger_handler','rabbit_event','rabbit_exchange_type','rabbit_framing_amqp_0_8','rabbit_framing_amqp_0_9_1','rabbit_heartbeat','rabbit_log','rabbit_misc','rabbit_msg_store_index','rabbit_net','rabbit_nodes_common','rabbit_password_hashing','rabbit_pbe','rabbit_policy_validator','rabbit_queue_collector_common','rabbit_queue_master_locator','rabbit_resource_monitor_misc','rabbit_runtime_parameter','rabbit_ssl_options','rabbit_types','rabbit_writer','supervisor2','vm_memory_monitor','worker_pool','worker_pool_sup','worker_pool_worker','time_compat','ssl_compat','ets_compat','rand_compat','time_compat','ssl_compat','ets_compat','rand_compat']},
{registered, []},
{applications, [kernel,stdlib,compiler,syntax_tools,xmerl,recon]},
{env, []},
%% Hex.pm package informations.
{maintainers, [
"RabbitMQ Team info@rabbitmq.com",
"Jean-Sebastien Pedron jean-sebastien@rabbitmq.com"
]},
{licenses, ["MPL 1.1"]},
{links, [
{"Website", "http://www.rabbitmq.com/"},
{"GitHub", "https://github.com/rabbitmq/rabbitmq-common"}
]},
{build_tools, ["make", "rebar3"]},
{files, [
"erlang.mk",
"git-revisions.txt",
"include",
"LICENSE*",
"Makefile",
"rabbitmq-components.mk",
"README",
"README.md",
"src",
"mk"
]}
]}.
' > ./rabbitmq-server-$rabbitmqversion/deps/rabbit_common/ebin/rabbit_common.app

echo '%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2013-2016. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%

-ifndef(ssl_api).
-define(ssl_api, true).

-include("ssl_cipher.hrl").

%% Visible in API
-export_type([connect_option/0, listen_option/0, ssl_option/0, transport_option/0,
prf_random/0, sslsocket/0]).

%% Looks like it does for backwards compatibility reasons
-record(sslsocket, {fd = nil, pid = nil}).

-type sslsocket() :: #sslsocket{}.
-type connect_option() :: socket_connect_option() | ssl_option() | transport_option().
-type socket_connect_option() :: gen_tcp:connect_option().
-type listen_option() :: socket_listen_option() | ssl_option() | transport_option().
-type socket_listen_option() :: gen_tcp:listen_option().

-type ssl_option() :: {versions, ssl_record:ssl_atom_version()} |
{verify, verify_type()} |
{verify_fun, {fun(), InitialUserState::term()}} |
{fail_if_no_peer_cert, boolean()} | {depth, integer()} |
{cert, Der::binary()} | {certfile, path()} | {key, Der::binary()} |
{keyfile, path()} | {password, string()} | {cacerts, [Der::binary()]} |
{cacertfile, path()} | {dh, Der::binary()} | {dhfile, path()} |
{user_lookup_fun, {fun(), InitialUserState::term()}} |
{psk_identity, string()} |
{srp_identity, {string(), string()}} |
{ciphers, ciphers()} | {ssl_imp, ssl_imp()} | {reuse_sessions, boolean()} |
{reuse_session, fun()} | {hibernate_after, integer()|undefined} |
{alpn_advertised_protocols, [binary()]} |
{alpn_preferred_protocols, [binary()]} |
{next_protocols_advertised, list(binary())} |
{client_preferred_next_protocols, binary(), client | server, list(binary())}.

-type verify_type() :: verify_none | verify_peer.
-type path() :: string().
-type ciphers() :: [ssl_cipher:erl_cipher_suite()] |
string(). % (according to old API)
-type ssl_imp() :: new | old.

-type transport_option() :: {cb_info, {CallbackModule::atom(), DataTag::atom(),
ClosedTag::atom(), ErrTag::atom()}}.
-type prf_random() :: client_random | server_random.

-endif. % -ifdef(ssl_api).' > /bin/rabbitmq-server-$rabbitmqversion/deps/rabbit_common/src/ssl_api.hrl

cd rabbitmq-server-$rabbitmqversion
make
make install

fi

suseflag=$(echo $distro | grep -i "suse")
if [ -z "$suseflag" ]
then
if [ -z "$debflag" ]
then
if [ -z "$rhflag" ]
then
echo "" echo "Could not determine the Linux distribution!" echo "Installation aborted. Nothing was done." echo "*"
exit
fi
fi
else
echo "this is for SUSE"
zypper -n update
zypper -n install gcc make autoconf ncurses-devel xsltproc
otpversion=20.2
curl -Lk https://github.com/erlang/otp/archive/OTP-$otpversion.tar.gz > /tmp/OTP-$otpversion.tar.gz
cp /tmp/OTP-$otpversion.tar.gz /bin/
cd /bin
tar -zxvf OTP-$otpversion.tar.gz
cd otp-OTP-$otpversion
./otp_build autoconf
./configure
make
make install
cp ./bin/erl /bin
cp -i /usr/local/bin/erlc /bin
curl -Lk https://www.rabbitmq.com/releases/rabbitmq-server/v$rabbitmqversion/rabbitmq-server-$rabbitmqversion.tar.xz > /tmp/rabbitmq-server-$rabbitmqversion.tar.xz
cp /tmp/rabbitmq-server-$rabbitmqversion.tar.xz /bin/
cd /bin
tar xf rabbitmq-server-$rabbitmqversion.tar.xz
cd rabbitmq-server-$rabbitmqversion
make
make install
fi

3. Run the script like this: sudo bash /tmp/rabbit.sh

4. After script is done, run this command:

sudo bash /bin/rabbitmq-server-3.6.15/deps/rabbit/scripts/rabbitmq-server

Leave a comment

Your email address will not be published. Required fields are marked *