首页 > 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. 2019年3月17日15:10 | #1

    Wonderful, what a weblog it is! This webpage gives useful information to us, keep it up.

  2. 2019年3月18日03:20 | #2

    With havin so much content do you ever run into any issues of plagorism or copyright infringement?

    My blog has a lot of completely unique content I’ve either authored myself or outsourced but it
    seems a lot of it is popping it up all over the web without my permission. Do you know
    any techniques to help protect against content from being
    stolen? I’d really appreciate it.

  3. 2019年3月18日11:24 | #3

    I am regular visitor, how are you everybody? This post posted at this web page
    is genuinely good.

  4. 2019年3月19日08:49 | #4

    Wow, incredible weblog layout! How long have you been blogging for?
    you make running a blog look easy. The full look of your web site is fantastic, as well as the
    content!

  5. 2019年3月19日23:39 | #5

    Do you have a spam issue on this site; I also am a blogger, and I was wondering your situation; we have developed some nice procedures and we are looking
    to swap strategies with others, why not shoot me an e-mail if
    interested.

  6. 2019年3月20日07:29 | #6

    naturally like your web site but you have to check the spelling on several of your posts.
    A number of them are rife with spelling problems and I in finding
    it very troublesome to inform the reality nevertheless I’ll certainly come
    again again.

  7. 2019年3月20日11:57 | #7

    Hi, after reading this awesome paragraph i am too cheerful to share my
    experience here with friends.

  8. 2019年3月20日19:55 | #8

    I’m extremely inspired together with your writing talents
    and also with the structure to your weblog. Is this a paid theme or did you modify it
    your self? Either way keep up the nice high quality
    writing, it is uncommon to see a great blog like this one these days..

  9. 2019年3月22日05:24 | #9

    I don’t even know how I ended up here, but I thought this post was great.
    I don’t know who you are but definitely you are going to a
    famous blogger if you aren’t already ;) Cheers!

  10. 2019年3月22日06:50 | #10

    Thank you for the auspicious writeup. It in fact was a amusement account it.
    Look advanced to far added agreeable from you!
    By the way, how could we communicate?

  11. 2019年3月22日12:55 | #11

    Pretty! This was a really wonderful post. Thanks for providing
    this information.

  12. 2019年3月23日13:52 | #12

    Hi, I do believe this is an excellent website. I stumbledupon it
    ;) I will revisit once again since i have bookmarked
    it. Money and freedom is the best way to change, may you be rich and continue
    to guide others.

评论分页
1 ... 8 9 10 139
订阅评论
0+6= (必填)