Linux Shell 实现一键部署Rabbitmq

时间:2023-04-07 19:02:43

Linux Shell 实现一键部署RabbitmqLinux Shell 实现一键部署Rabbitmq

rabbitmq 前言

RabbitMQ是实现了高级消息队列协议(AMQP)的开源消息代理软件(亦称面向消息的中间件)。RabbitMQ服务器是用Erlang语言编写的,而集群和故障转移是构建在开放电信平台框架上的。所有主要的编程语言均有与代理接口通讯的客户端库。

rabbitmq 参考

rabbitmq erlang
download download
备用download

Linux 各系统下载使用参考

Red Hat Rocky Linux  Oracle Linux

AlmaLinux 

ubuntu suselinux esxi RHEL标准安装 系统安装参考 YUM参考

MobaXterm 远程连接工具

Red Hat Enterprise 9.0 文档 Kickstart 生成器
download download download download download download download 参考 参考 配置参考 download 参考 Kickstart 
版本兼容性

安装 rabbitmq

  • 创建安装自动化脚本

  •  版本兼容性参考

  • 实现在线安装rabbitmq,erlang,配置rabbitmq配置文件,防火墙配置,企业微信机器人通知。
  • 以下基于Redhat系统
  • find / -name rabbitmq  #rabbitmq目录查看
  • find / -name erlang  #erlang目录查看
  • rabbitmq 用户名密码admin/Report@123
  • Redhat 9 functions使用需要执行安装yum install initscripts -y 
  • curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXXXX' #更改自己的企业微信机器人地址 
  • curl -o /etc/yum.repos.d/redhat.repo http://mirrors.aliyun.com/repo/Centos-8.repo #阿里在线repo
  • yum install figlet -y #用于将文字转换为放大艺术字(使用figlet Mysql显示)
vim /rabbitmq_install.sh
#!/bin/bash -e
# Author: CIASM 
# Date: 2023/04/07

<<!
██████╗  █████╗ ██████╗ ██████╗ ██╗████████╗███╗   ███╗ ██████╗ 
██╔══██╗██╔══██╗██╔══██╗██╔══██╗██║╚══██╔══╝████╗ ████║██╔═══██╗
██████╔╝███████║██████╔╝██████╔╝██║   ██║   ██╔████╔██║██║   ██║
██╔══██╗██╔══██║██╔══██╗██╔══██╗██║   ██║   ██║╚██╔╝██║██║▄▄ ██║
██║  ██║██║  ██║██████╔╝██████╔╝██║   ██║   ██║ ╚═╝ ██║╚██████╔╝
╚═╝  ╚═╝╚═╝  ╚═╝╚═════╝ ╚═════╝ ╚═╝   ╚═╝   ╚═╝     ╚═╝ ╚═
!

<<!
#Redhat 9 install erlang 
yum install -y https://github.com/rabbitmq/erlang-rpm/releases/download/v25.3/erlang-25.3-1.el9.x86_64.rpm
yum install -y https://github.com/rabbitmq/erlang-rpm/releases/download/v25.3/erlang-debuginfo-25.3-1.el9.x86_64.rpm
yum install -y https://github.com/rabbitmq/erlang-rpm/releases/download/v25.3/erlang-debugsource-25.3-1.el9.x86_64.rpm
!

source /etc/rc.d/init.d/functions

rabbitmq_PREFIX=/var/lib/rabbitmq

function install_rabbitmq (){
if [ ! -d ${rabbitmq_PREFIX} ];then
 yum install -y net-tools socat
 yum install -y ncurses-devel unixODBC unixODBC-devel
 yum install -y https://github.com/rabbitmq/erlang-rpm/releases/download/v25.3/erlang-25.3-1.el8.x86_64.rpm
 yum install -y https://github.com/rabbitmq/erlang-rpm/releases/download/v25.3/erlang-debuginfo-25.3-1.el8.x86_64.rpm
 yum install -y https://github.com/rabbitmq/erlang-rpm/releases/download/v25.3/erlang-debugsource-25.3-1.el8.x86_64.rpm
 yum install -y https://mirrors.huaweicloud.com/rabbitmq-server/v3.11.6/rabbitmq-server-3.11.6-1.el8.noarch.rpm
 if [ $? -eq 0 ];then 
   systemctl enable --now rabbitmq-server.service
   firewall-cmd --zone=public --permanent --add-port={4369,25672,5671,5672,15672,61613,61614,1883,8883}/tcp
   firewall-cmd --reload
   rabbitmq-plugins enable rabbitmq_management
   rabbitmqctl add_user admin Report@123
   rabbitmqctl set_user_tags admin administrator
   rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
   action "The rabbitmq Install Sussess..." /bin/true
   else
	action "The rabbitmq Install Failed..." /bin/false 
	exit 1
   fi
   else
	echo -e "\033[31mThe rabbitmq already Install...\033[0m"
fi
}

function Deployment_completion_notification (){
   host_ID=`dmidecode -s system-serial-number | sed -r 's/\s+//g'`
   host_IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2}' | awk 'NR==1'`
   memory_Size=`dmidecode -t memory | grep Size | grep -v No | awk '{sum+=$2} END {printf "%.0fG\n",sum/1^C4}'`
   CPU_Model=`cat /proc/cpuinfo | grep 'model name' | awk '{print $6}' | uniq`
   Disk_size=`fdisk -l | grep "sda:" | awk '{print $3$4}'`
   redhat_version=`cat /etc/redhat-release | grep "release" | awk '{print $6}'`
   redhat_core=`cat /proc/version | grep "version" | awk '{print $3}'`
   rabbitmq_server=`rabbitmqctl version`
   erl_version=`erl -eval '{ok, Version} = file:read_file(filename:join([code:root_dir(), "releases", erlang:system_info(otp_release), "OTP_VERSION"])), io:fwrite(Version), halt().' -noshell`
   curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=b27af453-0dd1-4b0e-a5d1-ca17e9fca6f6' \
   -H 'Content-Type: application/json' \
   -d '
    {
     "msgtype": "markdown",
      "markdown": {
         "content": " **system check** <font color=\"info\"> complete </font>  \n
         > **Host IP Address** \n
          [http://'$host_IP'](http://'$host_IP') \n
         > **Hardware information** \n
          hostSN:<font color=\"info\"> '$host_ID' </font> \n
          CPU_Model:<font color=\"info\"> '$CPU_Model' </font> \n
          memory_Size:<font color=\"info\"> '$memory_Size' </font> \n
          Disk_size:<font color=\"info\"> '$Disk_size' </font> \n
          System_version:<font color=\"info\"> '$redhat_version' </font> \n
          system_core:<font color=\"info\"> '$redhat_core' </font> \n
         > **rabbitmq install** \n
          rabbitmq_server:<font color=\"info\"> '$rabbitmq_server' </font> \n
          erl_version:<font color=\"info\"> '$erl_version' </font> \n",
      }
   }'
}
 

function main (){
install_rabbitmq
Deployment_completion_notification
}
 
main

执行安装

sh /rabbitmq_install.sh

企业微信机器人通知

Linux Shell 实现一键部署Rabbitmq

网页访问测试

  • http://YOU_ip:15672
  • 用户名密码admin/Report@123

Linux Shell 实现一键部署Rabbitmq