RabbitMQ-shell自动安装脚本
发布时间:2023年12月27日
set -e
ERLANG_PACKAGE="/usr/local/tech/autoinstall/lib/otp_src_24.3.tar.gz"
RABBITMQ_PACKAGE="/usr/local/tech/autoinstall/lib/rabbitmq-server-generic-unix-3.9.16.tar.xz"
DEPENDENCY_DIR="/usr/local/tech/autoinstall/third-lib/"
INSTALL_DIR="/usr/local/tech/rabbitmq"
ERLANG_DIR="$INSTALL_DIR"/otp_src_24.3
RABBITMQ_USER="mquser"
RABBITMQ_PASSWORD="mqpassword"
RABBITMQ_TAG="administrator"
if [[ $EUID -ne 0 ]]; then
echo "该脚本必须以root身份运行"
exit 1
fi
if [ ! -f "$ERLANG_PACKAGE" ]; then
echo "Erlang安装包不存在."
exit 1
fi
if [ ! -f "$RABBITMQ_PACKAGE" ]; then
echo "RabbitMQ安装包不存在."
exit 1
fi
echo "安装依赖..."
yum localinstall -y "$DEPENDENCY_DIR/glibc-devel"/*.rpm
yum localinstall -y "$DEPENDENCY_DIR/xmlto"/*.rpm
yum localinstall -y "$DEPENDENCY_DIR/unixODBC-devel"/*.rpm
yum localinstall -y "$DEPENDENCY_DIR/perl"/*.rpm
yum localinstall -y "$DEPENDENCY_DIR/bison"/*.rpm
yum localinstall -y "$DEPENDENCY_DIR/byacc"/*.rpm
echo "创建RabbitMQ用户和组..."
groupadd rabbitmq
useradd -r -g rabbitmq -s /bin/false rabbitmq
echo "创建目录并设置权限..."
mkdir -p "$INSTALL_DIR"
chown -R rabbitmq:rabbitmq "$INSTALL_DIR"
echo "解压并安装Erlang..."
tar -xf "$ERLANG_PACKAGE" -C "$INSTALL_DIR"
cd "$ERLANG_DIR"
./configure && make && make install
echo "解压并安装RabbitMQ..."
tar -xf "$RABBITMQ_PACKAGE" --strip-components=1 -C "$INSTALL_DIR"
chown -R rabbitmq:rabbitmq "$INSTALL_DIR"
cd "$INSTALL_DIR"/sbin
chmod +x rabbitmq*
echo "将Erlang和RabbitMQ可执行文件添加到系统路径..."
echo "export PATH=\$PATH:$ERLANG_DIR/bin:$INSTALL_DIR/sbin" >> /etc/profile
source /etc/profile
echo "启动RabbitMQ服务..."
rabbitmq-server -detached
sleep 10
echo "启动RabbitMQ Web管理插件..."
rabbitmq-plugins enable rabbitmq_management
echo "添加RabbitMQ用户,设置密码和权限,删除guest用户..."
rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD
rabbitmqctl set_user_tags $RABBITMQ_USER $RABBITMQ_TAG
rabbitmqctl set_permissions -p / $RABBITMQ_USER ".*" ".*" ".*"
rabbitmqctl delete_user guest
echo "创建systemd服务文件..."
cat << EOF > /etc/systemd/system/rabbitmq.service
[Unit]
Description=RabbitMQ Server
After=network.target
[Service]
User=rabbitmq
Group=rabbitmq
ExecStart=$INSTALL_DIR/sbin/rabbitmq-server
ExecReload=/bin/kill -s HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
echo "启动并设置RabbitMQ服务为开机自启..."
systemctl daemon-reload
systemctl start rabbitmq
systemctl enable rabbitmq
echo "RabbitMQ已经安装并启动!"
文章来源:https://blog.csdn.net/weixin_42115825/article/details/135233769
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:chenni525@qq.com进行投诉反馈,一经查实,立即删除!