采用标准集群模式 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
chmod +x
安装配置rabbitmq集群
wget https://github.com/rabbitmq/erlang-rpm/releases/download/v21.2.6/erlang-21.2.6-1.el6.x86_64.rpm wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.13/rabbitmq-server-3.7.13-1.el7.noarch.rpm rpm -ivh erlang-21.2.6-1.el6.x86_64.rpm yum localinstall rabbitmq-server-3.7.13-1.el7.noarch.rpm -y
添加环境变量
export ERL_HOME
export RABBIT_HOME=/rabbitmq
export PATH=/$RABBIT_HOME/sbin:$PATH:$ERL_HOME/bin
mkdir /rabbitmq
chown rabbitmq /rabbitmq
在master
root@k8s-master rabbitmq]# systemctl start rabbitmq-server.service
[root@k8s-master rabbitmq]# systemctl status rabbitmq-server.service
● rabbitmq-server.service - RabbitMQ broker
Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2019-03-13 23:41:59 +08; 3s ago
Process: 10083 ExecStop=/usr/sbin/rabbitmqctl shutdown (code=exited, status=69)
Main PID: 10229 (beam.smp)
Status: "Initialized"
CGroup: /system.slice/rabbitmq-server.service
├─10229 /usr/lib64/erlang/erts-10.2.4/bin/beam.smp -W w -A 64 -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -K true -- -root /usr/...
├─10559 erl_child_setup 32768
├─10587 inet_gethost 4
└─10588 inet_gethost 4
Mar 13 23:41:58 k8s-master rabbitmq-server[10229]: ## ##
Mar 13 23:41:58 k8s-master rabbitmq-server[10229]: ## ## RabbitMQ 3.7.13. Copyright (C) 2007-2019 Pivotal Software, Inc.
Mar 13 23:41:58 k8s-master rabbitmq-server[10229]: ########## Licensed under the MPL. See http://www.rabbitmq.com/
Mar 13 23:41:58 k8s-master rabbitmq-server[10229]: ###### ##
Mar 13 23:41:58 k8s-master rabbitmq-server[10229]: ########## Logs: /var/log/rabbitmq/rabbit@k8s-master.log
Mar 13 23:41:58 k8s-master rabbitmq-server[10229]: /var/log/rabbitmq/rabbit@k8s-master_upgrade.log
Mar 13 23:41:58 k8s-master rabbitmq-server[10229]: Starting broker...
Mar 13 23:41:59 k8s-master rabbitmq-server[10229]: systemd unit for activation check: "rabbitmq-server.service"
Mar 13 23:41:59 k8s-master systemd[1]: Started RabbitMQ broker.
Mar 13 23:41:59 k8s-master rabbitmq-server[10229]: completed with 0 plugins.
获取erlang cookie
同步三台主机
然后启动三台主机
在另外两个节点上加入集群
停止应用
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@k8s-master
rabbitmqctl start_app
rabbitmqctl join_cluster --ram rabbit@k8s-master
rabbitmqctl start_app
rabbitmqctl add_user mytest mytest
rabbitmqctl set_user_tags mytest administrator
rabbitmqctl set_permissions -p / mytest '.*' '.*' '.*