RabbitMQ介绍及搭建-安装配置

yum install -y rabbitmq-server

mkdir -p /etc/systemd/system/rabbitmq-server.service.d
# 修改文件打开数
vi /etc/systemd/system/rabbitmq-server.service.d/limit.conf
[Service]
LimitNOFILE = 100000

# 修改ip与端口
vi /etc/rabbitmq/rabbitmq-env.conf
RABBITMQ_NODE_IP_ADDRESS="本机ip"
RABBITMQ_NODE_PORT=5672
vi /etc/rabbitmq/rabbitmq.config

% Template Path: rabbitmq/templates/rabbitmq.config
[
 {kernel,[
  {inet_dist_listen_min, 41055},
  {inet_dist_listen_max, 41055},
  # epmd端口必须打开,群集才能正常工作、cli才能使用,设置端口范围
  {inet_default_connect_options, [{nodelay,true}]} ]},
 {rabbit,[
  # 在autoheal模式下,当某网络分区故障时,RabbitMQ会自动决定一个获胜分区winning,然后重启不在这个分区中的节点以恢复网络分区
  {cluster_partition_handling, autoheal},
  # tcp套接字的配置
  {tcp_listen_options, [
   binary,
   {packet, raw},
   {reuseaddr, true},
   # 未接受的TCP连接队列的最大数,达到此数量时,新的连接将被拒绝
   {backlog, 4096},
   {nodelay, true},
   {exit_on_close, false},
   # heartbeat: 0,代表关闭心跳服务
   # 启用tcp keepalive机制
   {keepalive, true}
  ]}
 {rabbitmq_management,[
  {http_log_dir, "/tmp/rabbit-mgmt"},
  # 监控各项资源的速率,none为不监控,默认为basic
  {rates_mode,none}
 ]}
# 复制cookie
scp /var/lib/rabbitmq/.erlang.cookie root@rabbit2:/var/lib/rabbitmq/.erlang.cookie
scp /var/lib/rabbitmq/.erlang.cookie root@rabbit3:/var/lib/rabbitmq/.erlang.cookie

chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie
chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config
chmod 400 /var/lib/rabbitmq/.erlang.cookie

systemctl daemon-reload
systemctl enable rabbitmq-server.service
systemctl start rabbitmq-server.service
# 查看状态
rabbitmqctl cluster_status


# 关闭:其他从节点先执行关闭,然后加入集群主节点
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@rabbit1
rabbitmqctl start_app
# 查看
rabbitmqctl cluster_status 

# 队列的镜像设置,在集群中所有的节点上进行镜像
rabbitmqctl set_policy ha-all '^(?!amq\.).*' '{"ha-mode": "all"}

# 创建用户
rabbitmqctl add_user test 
rabbitmqctl set_permissions -p / test test#123
rabbitmqctl set_user_tags test 角色
上一篇:总结mac下解决matplotlib中文显示问题的几种方法


下一篇:Django中间件