Cluster实现高可用负载均衡MySQL

以前的实验做过使用手动的配置使两台MySQL数据库服务器可以数据同步,这个采用mysql-cluster简化了配置的过程,并且很从容的可以扩容大量的节点,具体mysql-cluster的介绍可以参见mysql的官方网站,这里不啰嗦。

Cluster实现高可用负载均衡MySQL


IP规划:

LD1(负载均衡器)192.168.1.41

LD2192.168.1.42

SQL1192.168.1.21

SQL2192.168.1.22

NDB1192.168.1.11

NDB2192.168.1.12

MGM192.168.1.196

VIP192.168.1.200

实验原理:两台SQL和两台NDB和两台LDf分别实现高可用,LDSQL的调度实现负载均衡。

第一:在两台LD(负载均衡器上的设置,两者大致相同,故这里只设置其中一台,并且标出需要修改的地方)

[root@localhost ~]# yum -y install ipvsadm kernel-devel openssl openssl-devel

[root@localhost ~]# ln -s /usr/src/kernels/2.6.18-194.el5-i686/ /usr/src/linux

[root@localhost ~]# wget

[root@localhost ~]# ls keepalived-1.2.1.tar.gz

keepalived-1.2.1.tar.gz

[root@localhost ~]# tar zxvf keepalived-1.2.1.tar.gz

[root@localhost ~]# cd keepalived-1.2.1

[root@localhost keepalived-1.2.1]# ./configure  //www.linuxidc.com结束后出现以下的内容表示可以编译安装了

Keepalived configuration

------------------------

Keepalived version       : 1.2.1

Compiler                 : gcc

Compiler flags           : -g -O2 -DETHERTYPE_IPV6=0x86dd

Extra Lib                : -lpopt -lssl -lcrypto

Use IPVS Framework       : Yes

IPVS sync daemon support : Yes

Use VRRP Framework       : Yes

Use Debug flags          : No

[root@localhost keepalived-1.2.1]# make && make install

[root@localhost ~]# mkdir /etc/keepalived

[root@localhost ~]# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf

[root@localhost ~]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/keepalived

 

[root@localhost ~]# cp /usr/local/sbin/keepalived /usr/sbin/keepalived

[root@localhost ~]# cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/keepalived

[root@localhost ~]# vi /etc/keepalived/cc.conf

 

! Configuration File for keepalived

 

global_defs {

   notification_email {

   38205036@qq.com

   }

   notification_email_from Alexandre.Cassen@firewall.loc

   smtp_server 192.168.1.196

   smtp_connect_timeout 30

   router_id LVS_DEVEL

}

vrrp_sync_group VGM {

   group {

   V_MYSQL

   }

}

 

vrrp_instance V_MYSQL {

    state MASTER   //备用节点上这里修改为BACKUP

    interface eth0

    lvs_sync_daemon_interface eth0

    virtual_router_id 51

    priority 100   //备用节点上这里修改为90

    advert_int 5

    authentication {

        auth_typePASS

        auth_pass 1111

    }

    virtual_ipaddress {

        192.168.1.200/24 dev eth0

    }

}

virtual_server 192.168.1.200 3306 {

    delay_loop 6

    lb_algo rr

    lb_kind DR

    persistence_timeout 6

    protocol TCP

 

real_server 192.168.1.21 3306 {

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 3306

        }

    }

real_server 192.168.1.22 3306 {

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 3306

        }

    }

}

linux

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/ppfys.html