码迷,mamicode.com
首页 > 数据库 > 详细

LVS+keepalived做Mysql集群的负载均衡

时间:2020-06-10 19:25:38      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:tar   The   ica   xxx   delay   nec   ipaddress   sysctl   systemctl   

LVS+keepalived做Mysql集群的负载均衡:

注:
1、LVS本身不对node做健康检查的,所以要借助keepalived
2、根据配置当某node down掉会有几秒判断时间,这点请注意。

负载均衡端:

yum install ipvsadm keepalived ipset-devel

注:
keepalived的log在/var/log/message里

vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
notification_email {br/>aa@ming.com
}
notification_email_from aa@ming.com
smtp_server 10.0.0.10
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr

vrrp_strict (这行一定要注掉,不注掉vip可能会ping不通)

vrrp_garp_interval 0
vrrp_gna_interval 0
}

vrrp_instance VI_1 {
state MASTER
interface eno1 (这里网卡名要写对)
virtual_router_id 51
priority 100
advert_int 3
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.1.10
}
}

virtual_server 10.0.1.10 3306 {
delay_loop 6
lb_algo rr
lb_kind DR (此处需改为DR)
persistence_atimeout 10
protocol TCP

real_server 10.0.1.2 3306 {
    weight 1
    TCP_CHECK {
        connect_timeout 3
        nb_get_retry 3
        delay_before_retry 3
        connect_port 3306
    }

}

real_server 10.0.1.3 3306 {
    weight 1
    TCP_CHECK {
        connect_timeout 3
        retry 3
        delay_before_retry 1
        connect_port 3306
    }

}

real_server 10.0.1.4 3306 {
    weight 1
    TCP_CHECK {
        connect_timeout 3
        retry 3
        delay_before_retry 1
        connect_port 3306
    }

}

}

:wq

systemctl restart keepalived

systemctl enable keepalived

systemctl status keepalived

ip a (检查eno1是不是多了个10.0.1.10的vip,这个ip在ifconfig是看不到的,要确保可以ping通)

ipvsadm -L --stats (查看各node分配情况)

Mysql node端(所有node都做):

ifconfig lo:0 10.0.1.10 netmask 255.255.255.255 broadcast 10.0.1.10

route add -host 10.0.1.10 dev lo:0

vi /etc/sysctl.conf

net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2

:wq

sysctl -p

ifconfig lo:0

route -n

验证(可以看到访问的为不同node):

mysql -u aa -p‘xxxx‘ -h 10.0.1.10 -e "select @@hostname;"

LVS+keepalived做Mysql集群的负载均衡

标签:tar   The   ica   xxx   delay   nec   ipaddress   sysctl   systemctl   

原文地址:https://blog.51cto.com/yangzhiming/2503258

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!