-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_rabbitmq_broker.sh
58 lines (47 loc) · 2.8 KB
/
run_rabbitmq_broker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Check root privileges and exit if not root
if [ "$(whoami)" != "root" ]; then
echo "This script requires root privileges. Please run with sudo."
exit 1
fi
# get the arguments
distribution_name="$1"
user_name="$2"
password="$3"
# Check if all arguments are provided
if [ -z "$distribution_name" ] || [ -z "$user_name" ] || [ -z "$password" ]; then
echo "Usage: $0 <distribution-name> <user-name> <password>"
exit 1
fi
# Check if all arguments are provided
sudo apt update -y
sudo apt-get install curl gnupg -y
sudo apt-get install apt-transport-https -y
# Add RabbitMQ keys to trusted keys
curl -1sLf "https://keys.openpgp.org/vks/v1/by-fingerprint/0A9AF2115F4687BD29803A206B73A36E6026DFCA" | sudo gpg --dearmor | sudo tee /usr/share/keyrings/com.rabbitmq.team.gpg > /dev/null
curl -1sLf "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xf77f1eda57ebb1cc" | sudo gpg --dearmor | sudo tee /usr/share/keyrings/net.launchpad.ppa.rabbitmq.erlang.gpg > /dev/null
curl -1sLf "https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey" | sudo gpg --dearmor | sudo tee /usr/share/keyrings/io.packagecloud.rabbitmq.gpg > /dev/null
# Add RabbitMQ repository definitions
definition_file="/etc/apt/sources.list.d/rabbitmq.list"
cat << EOF > "$definition_file"
deb [signed-by=/usr/share/keyrings/net.launchpad.ppa.rabbitmq.erlang.gpg] http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu distribution-name main
deb-src [signed-by=/usr/share/keyrings/net.launchpad.ppa.rabbitmq.erlang.gpg] http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu distribution-name main
deb [signed-by=/usr/share/keyrings/io.packagecloud.rabbitmq.gpg] https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ distribution-name main
deb-src [signed-by=/usr/share/keyrings/io.packagecloud.rabbitmq.gpg] https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ distribution-name main
EOF
# Replace "distribution-name" with the variable in the file
sudo sed -i "s/distribution-name/$distribution_name/g" /etc/apt/sources.list.d/rabbitmq.list
# Install RabbitMQ server
sudo apt-get update -y
sudo apt-get install -y erlang-base erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key erlang-runtime-tools erlang-snmp erlang-ssl erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl
sudo apt-get install rabbitmq-server -y --fix-missing
# Start RabbitMQ server
sudo systemctl enable rabbitmq-server
sudo systemctl start rabbitmq-server
# Create a new user, set permissions
sudo rabbitmq-plugins enable rabbitmq_management
sudo rabbitmqctl add_user "$user_name" "$password"
sudo rabbitmqctl set_permissions -p "/" "$user_name" ".*" ".*" ".*"
sudo rabbitmqctl set_user_tags "$user_name" administrator
# Print success message
echo "RabbitMQ broker is successfully set up with user $user_name"