Linux安全网 - Linux操作系统_Linux 命令_Linux教程_Linux黑客

会员投稿 投稿指南 本期推荐:
搜索:
您的位置: Linux安全网 > Linux系统 > » 正文

VM下LINUX+Keepalived+Mysql-Cluster实现高可用负载均衡MYSQL

来源: 未知 分享至:

 以前的实验做过使用手动的配置使两台mysql数据库服务器可以数据同步,这个采用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 http://www.keepalived.org/software/keepalived-1.2.1.tar.gz

[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  //结束后出现以下的内容表示可以编译安装了

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

        }

    }

}

第二:在SQL上的设置

两个SQL节点上都要运行一个脚本,并且两个节点配置基本相同

[root@localhost ~]# vi /etc/init.d/lvscdr    //编写ARPVIP绑定脚本(两节点完全相同)

#!/bin/bash

#descrpption :start realserver DR

VIP=192.168.1.200

#./etc/rc.d/init.d/functions

case "$1" in

        start)

        echo "start LVS of RealServer DR"

        /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up

        /sbin/route add -host $VIP dev lo:0

        echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore


Tags:
分享至:
最新图文资讯
1 2 3 4 5 6
相关文章列表:
验证码:点击我更换图片 理智评论文明上网,拒绝恶意谩骂 用户名:
关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 发展历史