首页 > mysql > keepalived+lvs+mysql-cluster负载均衡

keepalived+lvs+mysql-cluster负载均衡

2010年4月26日 eric 发表评论 阅读评论

根据上篇文章,把mysql-cluster的环境搭好后,利用LVS实现mysql的负载均衡,减轻mysqld节点的压力。

环境:

vip             192.168.6.7    

db1 www.nginxs.com MGM

db2 192.168.6.160 NDB,MYSQLD

db3 192.168.6.188 NDB,MYSQLD

db4 192.168.6.191 MYSQLD

为了节省资源,我就把 keepalived 和 lvs 调度器,就安装在了 MGM 服务上

安装步骤:

一、KEEPALIVED 和 LVS 的安装与配置

1、在 db1 上安装 keepalived 和 lvs  

db1 $> apt-get install keepalvied ipvsadm

2、创建 keepavlied.conf 配置文件

db1 $> vim /etc/keepalived.conf

vrrp_instance VI_1 {

    state MASTER        #辅机器改为 BACKUP

    interface eth0

    virtual_router_id 51

    priority 200           #权值要比 BAUCKUP

    authentication {

           auth_type PASS

           auth_pass eric

    }

    virtual_ipaddress {

       192.168.6.7

    }

}

virtual_server 192.168.6.7 3306 {

        delay_loop 6

        lb_algo rr

        lb_kind DR

#       persistence_timeout     50

        protocol TCP

        real_server     192.168.6.160 3306 {

                weight  1

                TCP_CHECK {

                        connect_port 3306

                        connect_timeout 30

                }

        }

        real_server     192.168.6.191   3306 {

                weight  1

                TCP_CHECK {

                        connect_port    3306

                        connect_timeout 30

                }

        }

        real_server     192.168.6.188   3306 {

                weight  1

                TCP_CHECK {

                        connect_port    3306

                        connect_timeout 30

                }

        }

}

##配置文件的意思,我就不解释了,相信大家也都理解。

3、启动服务 keepalived 服务,它会自动给ipvsadm 加规则

db1 $> /etc/init.d/keepalived start

4.然后查看 ipvsadm 列表

db1 $> ipvsadm -Ln

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

TCP  192.168.6.7:3306 rr

好了 VIP 启动了,因为现在 三太 mysql 节点的 mysql还没起来,所以没有连接上。

二、安装配置三台mysqld 节点(同样的操作,同样的配置文件!)

1. 内核参数 arp 

vim /etc/sysctl.conf

### 在最下面添加

net.ipv4.ip_forward=0

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

保存退出 执行  sysctl -p

2、修改 /etc/network/interfaces

添加 如下配置

auto lo:0

iface lo:0 inet static

address 192.168.6.7

netmask 255.255.255.255

##保存,随后重启下三台服务器,让其配置生效

三、启动 NDB 和 MYSQLD 服务

db2 $> /usr/local/mysql/libexec/ndbd                     ##启动 ndbd节点

db2 $> /usr/local/mysql/bin/mysqld_safe --user=mysql &     ##启动 mysqld服务
db3 $> /usr/local/mysql/libexec/ndbd                     ##启动 ndbd节点

db3 $> /usr/local/mysql/bin/mysqld_safe --user=mysql &     ##启动 mysqld服务
db4 $> /usr/local/mysql/bin/mysqld_safe --user=mysql &     ##启动 mysqld服务

四、查看 IPVSADM 列表,看是客户端是否都健康

db1 $> ipvsadm -Ln

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

TCP  192.168.6.7:3306 rr

  -> 192.168.6.160:3306           Route   1      0          0

  -> 192.168.6.191:3306           Route   1      0          0

  -> 192.168.6.188:3306           Route   1      0          0

好了三台 mysqld 节点都起来了,然后用客户端来连接。

转载请注明:文章转载自:Eric's linux and nginx! (http://www.nginxs.com)
本文地址:http://www.nginxs.com/linux/139.html

分类: mysql 标签: , , ,
  1. 2018年10月18日11:03 | #1

    Hello to every one, it’s in fact a good for me to visit this website,
    it includes important Information.

  2. 2018年10月18日21:31 | #2

    If some one wants to be updated with most recent technologies afterward he must be pay a visit this web page
    and be up to date everyday.

  3. 2018年10月19日06:14 | #3

    You could definitely see your skills within the article you write.
    The sector hopes for even more passionate writers such as you who aren’t afraid to mention how they believe.
    Always go after your heart.

  4. 2018年10月20日05:33 | #4

    Thank you a lot for sharing this with all folks you really know what you’re speaking about!

    Bookmarked. Kindly also consult with my site =). We will have a hyperlink exchange arrangement among us

  5. 2018年10月20日08:40 | #5

    Yes! Finally someone writes about Coconut Oil.

  6. 2018年11月6日19:27 | #6

    onlineing online online in usa

    f4ff online online deals

  7. 2018年11月7日00:54 | #7

    online online professional 40

    f4ff look there get online online

  8. 2018年11月7日06:59 | #8

    online to sell

    f4ff online ad email virus

  9. 2018年11月7日09:01 | #9

    usefull link online doses

    f4ff acheter online et levitra

  10. 2018年11月9日09:45 | #10

    Greetings! Very helpful advice in this particular article!

    It is the little changes which will make the most significant changes.
    Thanks a lot for sharing!

  11. 2018年11月11日15:21 | #11

    We’re a group of volunteers and opening a new scheme in our community.
    Your site offered us with valuable info to work on. You have done
    an impressive activity and our whole neighborhood might be
    thankful to you.

  12. 2018年11月11日17:41 | #12

    I’ve learn several excellent stuff here. Definitely worth bookmarking for revisiting.
    I wonder how a lot attempt you set to make the sort of excellent informative site.

  13. 2018年11月13日12:09 | #13

    Hey there! I could have sworn I’ve been to this site before but after reading through some of the post
    I realized it’s new to me. Anyways, I’m definitely
    happy I found it and I’ll be bookmarking and checking back often!

  14. 2018年11月14日21:42 | #14

    I’ve been surfing online more than three hours today, yet I never
    found any interesting article like yours. It is pretty worth enough
    for me. Personally, if all webmasters and bloggers made good content as you did,
    the web will be much more useful than ever before.

  15. 2018年11月15日03:52 | #15

    Thanks very interesting blog!

  16. 2018年11月17日00:08 | #16

    I visited several web sites except the audio quality for audio songs
    current at this website is really superb.

  17. 2018年11月23日14:42 | #17

    Investments in most securities contain risks.

  18. 2018年11月24日08:20 | #18

    Investor researches shares, bonds, and so on.

  19. 2018年11月24日20:19 | #19

    Investor researches stocks, bonds, and so forth.

  20. 2018年11月28日02:52 | #20

    Today, I went to the beach front with my children. I found a sea shell and
    gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to
    her ear and screamed. There was a hermit crab inside and
    it pinched her ear. She never wants to go back! LoL I know this is totally off topic but I had
    to tell someone!

  21. 2018年12月1日08:44 | #21

    Hi every one, here every one is sharing these kinds of experience,
    therefore it’s fastidious to read this web site, and I used to go to see this
    webpage everyday.

  22. 2018年12月3日00:47 | #22

    My family members every time say that I am killing my
    time here at net, but I know I am getting knowledge daily by
    reading such good content.

  23. 2018年12月4日18:02 | #23

    online europa barata

    4e42 online genrico muy barato

  24. 2018年12月6日00:23 | #24

    With havin so much content do you ever run into any problems of plagorism or
    copyright infringement? My website has a lot of completely unique content I’ve either
    created myself or outsourced but it looks like a lot of it is popping it
    up all over the web without my agreement.
    Do you know any techniques to help protect against content from being stolen? I’d truly appreciate
    it.

评论分页
1 ... 6 7 8 139
订阅评论
3+5= (必填)