本文共 4380 字,大约阅读时间需要 14 分钟。
#############################################################
keepalivedkeepalived是VRRP协议的完美实现,最早是为lvs设计的高可用模块。VRRP协议:解决静态路由单点故障的问题太。VRRP通过竞选协议来实现虚拟路由器的功能,所有的协议报文都是通过IP多播(组播)(组播地址224.0.0.18)对外表现为一个周知的MAC地址00-00-5E-00-01-X,对外不管谁是MASTER,都是同样的MAC和IP。#############################################################
配置后端httpd服务端口都为8080vim /etc/httpd/conf/httpd.conf Listen 8080service httpd restart
#############################################################两台他同时安装haproxyyum install haproxy -yvim /etc/haproxy/haproxy.cfg frontend http_front #前端网页配置mode http #默认mode是httpbind *:80stats uri /haproxy?statsdefault_backend http_backbackend http_back
balance roundrobin #默认算法轮询,也可以是source相当于nginx的ip_hash,cookieoption httpchk GET /index.html #默认检查端口,基于url的健康检查,ngingx不支持option forwardfor header X-REAL-IP #客户端真实ip,后端程序通过X-REAL-IP获取server linux-node1 192.168.56.20:8080 check inter 2s rise 3 fall 4 weight 2 #inter 2s 两秒检查 rise 3 3次ok才正常4次ng才失败server linux-node2 192.168.56.21:8080 check inter 2s rise 3 fall 4 weight 1service haproxy start
#############################################################安装keepalivedyum install keepalived -yvim /etc/keepalived/keepalived.conf
! Configuration File for keepalivedglobal_defs {
notification_email { lmkmike@qq.com}
notification_email_from haproxy-ha@qq.comsmtp_server 192.168.200.1smtp_connect_timeout 30router_id LVS_DEVEL}
vrrp_instance VI_1 {
state MASTER #角色 另外改BACKUPinterface eth0 #网卡virtual_router_id 51 #不能重复priority 150 #权重 另外改100advert_int 1 #检查时间默认1sauthentication { auth_type PASSauth_pass haproxy_ha}virtual_ipaddress { 192.168.56.22192.168.56.23}
}
下面暂时不用配置
#############################################################启动keepalivedservice keepalived start
#############################################################
查看ip是否绑定ip ad li[root@master ~]# ip ad li1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host loinet6 ::1/128 scope host valid_lft forever preferred_lft forever2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:40:82:2f brd ff:ff:ff:ff:ff:ffinet 192.168.56.20/24 brd 192.168.56.255 scope global eth0inet 192.168.56.22/32 scope global eth0inet 192.168.56.23/32 scope global eth0inet6 fe80::20c:29ff:fe40:822f/64 scope link valid_lft forever preferred_lft forever#############################################################停止master的keepalived服务,看backup是否获取ipservice keepalived stop#############################################################
开启master的keepalived服务,看master是否获取service keepalived stop#############################################################
抓包可见ip 224.0.0.18[root@minion ~]# tcpdump -n 'host 224.0.0.18'tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes19:50:29.152236 IP 192.168.56.20 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 2419:50:30.157829 IP 192.168.56.20 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 2419:50:31.159852 IP 192.168.56.20 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 2419:50:32.165625 IP 192.168.56.20 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 2419:50:33.167739 IP 192.168.56.20 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 2419:50:34.176987 IP 192.168.56.20 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 2419:50:35.183179 IP 192.168.56.20 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 2419:50:36.185416 IP 192.168.56.20 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 2419:50:37.187998 IP 192.168.56.20 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 2419:50:38.192458 IP 192.168.56.20 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 2419:50:39.194564 IP 192.168.56.20 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 24转载于:https://blog.51cto.com/13491150/2061062