1.rabbitmq高可用方案

采用标准集群模式  HAPROXY + rabbitmq 2个 ram  和  一个 disk 节点

主机规划:
192.168.157.128   haproxy  keepalive 主   ram节点
192.168.157.129   haproxy  keepalive 从   disk 节点
192.168.157.130   disk 节点
 VIP  192.168.154.131
前期准备:
关闭 selinux  firewalld  配置host解析



127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.157.128  k8s-node2
192.168.157.129  k8s-node1
192.168.157.130  k8s-maste

配置 haproxy的高可用

haproxy的配置

[root@k8s-master haproxy]# cat /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 4000 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 httplog 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 20000 #--------------------------------------------------------------------- ## 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 listen http_front bind 0.0.0.0:8081 #监听端口 stats refresh 30s #统计页面自动刷新时间 stats uri /haproxy?stats #统计页面url stats realm Haproxy Manager #统计页面密码框上提示文本 stats auth admin:admin #统计页面用户名和密码设置 #stats hide-version #隐藏统计页面上HAProxy的版本信息 listen rabbitmq_admin bind 0.0.0.0:8080 server node1 192.168.157.128:15672 check inter 5s rise 2 fall 3 server node2 192.168.157.129:15672 check inter 5s rise 2 fall 3 server node3 192.168.157.130:15672 check inter 5s rise 2 fall 3 listen rabbitmq_cluster bind 0.0.0.0:8882 #rabbitmq集群调用的端口 option tcplog mode tcp timeout client 3h timeout server 3h option clitcpka balance roundrobin #负载均衡算法(#banlance roundrobin 轮询,balance source 保存session值,支持static-rr,leastconn,first,uri等参数) server rabbitmq1 192.168.157.128:5672 check inter 5s rise 2 fall 3 #check inter 2000 是检测心跳频率,rise 2是2次正确认为服务器可用,fall 3是3次失败认为服务器不可用 server rabbitmq2 192.168.157.129:5672 check inter 5s rise 2 fall 3 server rabbitmq3 192.168.157.130:5672 check inter 5s rise 2 fall 3


keepalive配置

! Configuration File for keepalived
vrrp_script chk_http_port {
script "/etc/keepalived/check_haproxy.sh"
interval 2
weight 2
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP #cong上改为BACKUP
interface eth0
virtual_router_id 51
priority 150 #上改为120
advert_int 1
authentication {
auth_type PASS
auth_pass 2356
}
track_script {
chk_http_port
}
virtual_ipaddress {
192.168.154.131
}
}
}

 

/etc/keepalived/check_haproxy.sh
#!/bin/bash
num=`ps -C haproxy --no-header |wc -l`
if [ $num -eq 0 ];then
systemctl restart haproxy
sleep 3
if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then
systemctl stop keepalived
fi
fi

 

猜你喜欢

转载自www.cnblogs.com/leleyao/p/10524447.html