Centos7 RPM安装RabbitMQ集群 3.7.4


安装erlang环境与rabbitmq

#最新版快速安装
#erlang
curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
yum install erlang
#rabbitmq
curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash
yum install rabbitmq-server

#yum install erlang rabbitmq-server -y
vi /etc/yum.repos.d/rabbitmq-erlang.repo
[rabbitmq-erlang]
name=rabbitmq-erlang
baseurl=https://dl.bintray.com/rabbitmq/rpm/erlang/20/el/7
gpgcheck=1
gpgkey=https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
repo_gpgcheck=0
enabled=1

yum install erlang -y
yum install https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.4/rabbitmq-server-3.7.4-1.el7.noarch.rpm -y
chkconfig rabbitmq-server on



md5-ee4db188bbffd3bb4f1bc79c4461d144



vi /usr/lib/systemd/system/rabbitmq-server.service
[Service]下增加:
LimitNOFILE=131072
systemctl daemon-reload
systemctl restart rabbitmq-server



md5-13f7f678e19e0d88acaf87f232307c3e



channel_max=0
log.file.level=debug



md5-9332da3cd780c991ad997371e34721de



mv /var/lib/rabbitmq/ /data/
ln -s /data/rabbitmq /var/lib/rabbitmq
service rabbitmq-server start

rabbitmqctl stop
#所有节点/var/lib/rabbitmq/.erlang.cookie内容必须一样,权限为400
#所有节点IP与主机名加入每台节点的hosts文件

service rabbitmq-server start
rabbitmqctl cluster_status



md5-96b7d7d1115cd47adc79554b11cd9e87



设置所有节点加入其中一个节点(默认是磁盘节点,至少要有一个磁盘节点),在剩余节点执行(都以内存模式加入即可):
rabbitmqctl stop_app
rabbitmqctl join_cluster --ram rabbit@fg-uat-mq2
rabbitmqctl start_app
rabbitmqctl cluster_status

#开启web管理
rabbitmq-plugins enable rabbitmq_management
#增加vhost
rabbitmqctl add_vhost test
#设置账户
rabbitmqctl list_users
rabbitmqctl delete_user guest
rabbitmqctl add_user admin xxxxxxxx
#设置管理员与授权vhost
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
rabbitmqctl set_permissions -p test admin ".*" ".*" ".*"
#设置镜像策略
rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'
rabbitmqctl -p test set_policy ha-all "^" '{"ha-mode":"all"}'



md5-34648bcc25e1d3d6f2f3164591b9a2c3



重启rabbitmq

systemctl stop rabbitmq-server.service
systemctl start rabbitmq-server.service



md5-3a05eae87413e6e80e6e17007686a445



global
   log 127.0.0.1:514 local1 debug
   log 127.0.0.1:514 local2 err
   chroot /var/lib/haproxy
   maxconn           1048576
   user haproxy
   group haproxy
   daemon

# turn on stats unix socket
#stats socket /var/lib/haproxy/stats mode 600 level admin
defaults
   log global
   mode http
   #option httplog
   option dontlognull
   maxconn        1048576
   timeout connect 5000
listen WEB-STATUS
   bind 0.0.0.0:18080
   mode http
#   stats refresh 30s
   stats uri /haproxy?stats

frontend rabbitmq5672
   bind *:5672
   log                global
   mode               tcp
   option             tcplog
   option             contstats
   option             tcpka
   default_backend    rabbitmq-nodes

backend rabbitmq-nodes
   balance     leastconn
   mode        tcp
   option      tcpka
   option      tcplog
   option      srvtcpka
   balance roundrobin
   server   node1 10.200.77.131:5672 check inter 2000 rise 2 fall 3
   server   node2 10.200.77.132:5672 check inter 2000 rise 2 fall 3
   server   node3 10.200.77.133:5672 check inter 2000 rise 2 fall 3