shell脚本超详细安装rabbitmq
#!/bin/bash
[ $UID -ne 0 ] && echo "need to be root so that" && exit 1
isInstallWget=`yum list installed | grep wget`
if [ $? -ne 0 ];then
yum -y install wget &>/dev/null
fi
echo "开始安装依赖..."
yum -y install gcc glibc-devel make ncurses-devel openssl-devel xmlto perl wget gtk2-devel binutils-devel 1>/dev/null
if [ $? -ne 0 ];then
echo "yum install soft package fail";
fi
echo "安装依赖包已完成"
sleep 1
if [ ! -d /usr/local/erlang ];then
mkdir /usr/local/erlang
echo "开始下载erlang"
dirName="otp_src_25.0.3"
erlangPack="$dirName.tar.gz"
erlangPackUrl="https://github.com/erlang/otp/releases/download/OTP-25.0.3/$erlangPack"
ls /opt/otp_src*
if [ $? -ne 0 ];then
wget -P /opt/ $erlangPackUrl;
fi
echo "erlang已经下载完成"
if [ ! -f $dirName ];then
tar --no-same-owner -xf "/opt/$erlangPack" -C /opt/
fi
echo "开始编译erlang..."
cd /opt/$dirName
./configure --prefix=/usr/local/erlang 1>/dev/null
make install 1>/dev/null
sed -i '$aERLANG_PATH=\/usr\/local\/erlang\/bin \nPATH=\$ERLANG_PATH:$PATH \nexport $PATH' /etc/profile
source /etc/profile
echo "至此erlang️安装完成"
fi
sleep 1
echo "接下来安装rabbitmq"
if [ ! -d /usr/local/rabbitmq ];then
yum install -y xz 1>/dev/null
echo "开始下载rabbitmq"
dirName="rabbitmq-server-generic-unix-3.10.7"
rabbitmqPack="$dirName.tar.xz"
rabbitmqUrl="https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.10.7/$rabbitmqPack"
ls /opt/$dirName*
if [ $? -ne 0 ];then
wget -P /opt/ $rabbitmqUrl
fi
echo "rabbitmq下载完成"
if [ ! -f "/opt/rabbitmq_server-3.10.7"];then
if [ ! -f "/opt/$dirName.tar" ];then
/bin/xz -d "/opt/$rabbitmqPack.tar.xz" -C /opt/
fi
if [ ! -f "/opt/$dirName" ];then
tar --no-same-owner -xf "/opt/$rabbitmqPack" -C /opt/
fi
fi
mv /opt/rabbitmq_server-3.10.7 /usr/local/rabbitmq
sed -i '$aRABBITMQ_PATH=\/usr\/local\/rabbitmq\/sbin \nPATH=\$RABBITMQ_PATH:$PATH \nexport $PATH' /etc/profile
source /etc/profile
echo "至此rabbitmq安装完成"
fi
<<rabbitmqAccount # 查看所有用户 rabbitmqctl list_users # 添加用户 rabbitmqctl add_user admin 123456 # 配置权限 rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*" # 查看用户权限 rabbitmqctl list_user_permissions admin # 设置tag rabbitmqctl set_user_tags admin administrator # 删除用户 rabbitmqctl delete_user guest rabbitmqAccount
<<rabbitmqAutoStart cd /etc/init.d # 新建脚本 # 添加权限+加入 chmod +x rabbitmq chkconfig --add rabbitmq #启动 service rabbitmq start|stop rabbitmqAutoStart
rabbitmq开机自动重启脚本
#! /bin/sh
export HOME=/root
export PATH=/usr/local/erlang/bin:$PATH
case "$1" in
start)
/usr/local/rabbitmq/sbin/rabbitmq-server start 1>/dev/null
echo "rabbitmq is started"
;;
stop)
/usr/local/rabbitmq/sbin/rabbitmqctl stop 1>/dev/null
echo "rabbitmq is stoped"
;;
*)
;;
esac
exit 0
文章评论