【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
rabbitmq集群搭建
防火墙添加并重启
-A INPUT -p tcp -m multiport --dports 4369,25672,5672,15672 -j ACCEPT
安装
cd /usr/local/src/; wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.16/rabbitmq-server-3.7.16-1.el7.noarch.rpm
curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
yum install erlang -y
yum install rabbitmq-server-3.7.16-1.el7.noarch.rpm -y
四台服务器的/etc/hosts配置统一
192.168.1.1 node1
192.168.1.1 node2
192.168.1.1 node3
192.168.1.1 node4
确认每一台的.erlang.cookie的配置统一
chmod 700 /var/lib/rabbitmq/.erlang.cookie
echo -n "SECBJUFBZFRQWNETDDDU" > /var/lib/rabbitmq/.erlang.cookie
cat /var/lib/rabbitmq/.erlang.cookie
chmod 400 /var/lib/rabbitmq/.erlang.cookie
其他节点添加到磁盘节点
rabbitmqctl join_cluster rabbit@node01
其他节点添加为内存节点
rabbitmqctl stop_app ;rabbitmqctl change_cluster_node_type ram ;rabbitmqctl start_app
开机自启
systemctl enable rabbitmq-server
rabbitmq-plugins enable rabbitmq_management
rabbitmqctl cluster_status
设置用户
rabbitmqctl add_user wwdd yesdx#EDC
rabbitmqctl set_permissions -p / wwdd ".*" ".*" ".*"
**访问:**http://IP:15672
haproxy 到rabbitmq
yum install -y haproxy cd /etc/haproxy haproxy -f /etc/haproxy/haproxy.cfg 配置文件示例
#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 44000
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option tcplog
option dontlognull
# option http-server-close
# option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main *:5000
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .gif .png .css .js
use_backend static if url_static
default_backend app
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin
server static 127.0.0.1:4331 check
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
balance roundrobin
server app1 127.0.0.1:5001 check
server app2 127.0.0.1:5002 check
server app3 127.0.0.1:5003 check
server app4 127.0.0.1:5004 check
###################RabbitMQ的管理界面#####################################
listen rabbitmq_admin
bind 0.0.0.0:15673
server node1 192.168.1.1:15672
server node2 192.168.1.1:15672
server node3 192.168.1.1:15672
server node4 192.168.1.1:15672
####################################################################
listen rabbitmq_cluster
bind 0.0.0.0:5673
option tcplog
mode tcp
timeout client 3h
timeout server 3h
option clitcpka
balance leastconn #负载均衡算法(#banlance roundrobin 轮询,balance source 保存session值,支持static-rr,leastconn,first,uri等参数)
# server node1 192.168.1.1:5672 check inter 5s rise 2 fall 3
server node2 192.168.1.1:5672 check inter 5s rise 2 fall 3
server node3 192.168.1.1:5672 check inter 5s rise 2 fall 3
server node4 192.168.1.1:5672 check inter 5s rise 2 fall 3
来源:oschina
链接:https://my.oschina.net/u/3635512/blog/3145881