• 欢迎访问VPS岛网站,国外VPS,国内VPS,国外服务器,国内服务器,服务器主机,测评及优惠码,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站 QQ群

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

mysql技术 yangzhimingg 50次浏览 已收录 0个评论

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

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

负载均衡端(MASTER):

yum install ipvsadm keepalived ipset-devel

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

vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
notification_email {aa@ming.com
br/>aa@ming.com<br/
}
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分配情况)

负载均衡端(BACKUP):

yum install ipvsadm keepalived ipset-devel

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

vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
notification_email {aa@ming.com
br/>aa@ming.com<br/
}
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 BACKUP
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 (此时是不会出现vip的,如果master那台down了,这台会自动显示)

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;"


VPS岛 的文章和资源来自互联网,仅作为参考资料,如果有侵犯版权的资源请尽快联系站长,我们会在24h内删除有争议的资源。丨 转载请注明LVS+keepalived做Mysql集群的负载均衡
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址