mysql高可用探究(二)Lvs+Keepalived+Mysql单点写入主主同步高可用方案

      这个方案能够便于单台数据库的管理维护以及切换工作

 

        lvs_sync_daemon_inteface eth0

      # echo “/etc/rc.d/init.d/realserver.sh start” >>
/etc/rc.local

}

        smtp_server mail.test.com

stop)  

nb_get_retry
3

notification_email {

MySQL + KeepAlived + LVS单点写入主主同步高可用架构实验

/sbin/ifconfig
lo:0 $VIP broadcast $VIP netmask 255.255.255.255 -arp

        smtp_server mail.test.com

   

weight
100

 

     在 ODD

delay_before_retry
3

        priority
180

        persistence_timeout 20  

#
make && make install

stop)

 

smtp_server
127.0.0.1

group {

exit 0  

#
yum -y install ipvsadm

}

       # tar -zxv -f keepalived-1.1.19.tar.gz

notification_email
{

}

        nb_get_retry 3  

delay_loop 6#(每隔10秒查询realserver状态)

ü  扩展不是很方便。

[[email protected]
~]$ mysqladmin shutdown  

persistence_timeout
0#(同一IP的连接60秒内被分配到同一台realserver)

        delay_before_retry 3

      ● 扩展不是很方便

1.5 启动keepalived

}

        interface eth0  

real_server
192.168.0.151 3005 {#Real Server 2

1.4.5 Lvs的安装

   

#
yum -y install openssl-devel popt-devel

        auth_pass 1111

     

delay_loop 6#(每隔10秒查询realserver状态)

        interface eth0

成功!!  

auth_pass
1111

1.4  方案实战

        router_id LVS1  

weight
100

 

       # ./configure –prefix=/usr/local/keepalived

delay_before_retry
3

start)

      ● 安装配置简单,
实现方便,高可用效率好,可以根据服务与系统的可用性多方面进行切换

!
Configuration File for keepalived

        advert_int 1

[plain] 

lb_kind
DR#(Direct Route)

*)

       # make

#
mkdir /etc/keepalived

对于realserver的配置master和backup是一致的,脚本内容如下:

   

delay_before_retry
3

        delay_before_retry 3

   

192.168.0.206(BACKUP)的配置和MASTER类似,只是会变更其中某个参数,这个已经在上面的配置文件中标出,这里不再赘述。

        smtp_connect_timeout 30

   

}

1.4.1 适用场景

     大部分都和 ODD 一样、只有 2 处:

vrrp_instance
VI_1 {

        priority
150

  

weight
100#(权重)

        router_id LVS1

       

router_id
LVS_DEVEL_1 #Backup服务器将此项改为LVS_DEVEL_2

        auth_type PASS

        lb_kind DR  

echo
“1”>/proc/sys/net/ipv4/conf/all/arp_ignore

echo “/etc/rc.d/init.d/keepalived start” >>
/etc/rc.local

       exit 1  

#
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/

Master和backup不一样的地方已经标记为红色

      优点

#
cp /usr/local/sbin/keepalived /usr/sbin/

1.4.9 Master和backup的启动

 

TCP_CHECK
{

澳门金沙vip,        weight 3

   ㈣ 方案架构图

保存一个文件,取名随意,这里以dr.sh为例,内容如下:

}

# description: Config realserver lo and apply noarp  

connect_port
80

ü  启动master上的keepalived,看VIP是否会迁移回master上。

        sorry_server 192.168.1.115 3306  

echo
“2”>/proc/sys/net/ipv4/conf/all/arp_announce

1.4.6 Keepalived的安装

停止前:  

protocol
TCP#(用TCP协议检查realserver状态)

1.3  方案优缺点

        smtp_server smtp.gmail.com  

echo
“0”>/proc/sys/net/ipv4/conf/all/arp_announce

ü  启动master上的mysql,看是否能切换回master。

130508 00:53:50 mysqld_safe mysqld from pid file
/home/mysql/mysql/data/odd.example.com.pid ended  

}

1.4.7.2   Backup的keepalived的配置

  

#
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/

        router_id LVS1

       # tar -zxv -f ipvsadm-1.24.tar.gz

connect_timeout
10#(10秒无响应超时)

 

}  

1.4 配置keepalived

        priority 150  

 

wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz
tar zxvf keepalived-1.1.19.tar.gz
cd keepalived-1.1.19
./configure –prefix=/usr/local/keepalived
make
make install
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
mkdir /etc/keepalived

  

}

       echo “2”
>/proc/sys/net/ipv4/conf/all/arp_announce

        notification_email_from
[email protected]  

advert_int
1

        connect_port 3306

      在ODD EVEN:

real_server
192.168.0.208 80 {#Real Server 2

优点:

   ⑶ LVS 安装

 

       echo “RealServer Stoped”

     在EVEN:

persistence_timeout
0#(同一IP的连接60秒内被分配到同一台realserver)

               zhangxy@test.com

       echo “1” >/proc/sys/net/ipv4/conf/lo/arp_ignore  

nb_get_retry
3

authentication {

       echo “0” >/proc/sys/net/ipv4/conf/lo/arp_ignore  

real_server
192.168.0.207 80 {#Real Server 1

 

   

notification_email_from
lvs@xyxy.tk

在master、backup服务器都进行安装:

        delay_loop 6  

stop)

        TCP_CHECK {

        192.168.1.128 dev eth0 label eth0:1  

start)

case “$1” in

      在 ODD EVEN

#
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/

        nb_get_retry 3

      比如进行大表的表结构更改、数据库的升级等都是非常方便的

sysctl
-p

notification_email {

     在 ODD EVEN 上

 

 Lvs+Keepalived+Mysql单点写入主主同步高可用方案

      

;;

        sorry_server 10.1.1.75 3306

        auth_pass 1111  

case
“$1” in

authentication {

   

#
vi /etc/keepalived/keepalived.conf

exit 0

*)  

}

        loadbalance

}  

auth_type
PASS

 

 

}

virtual_ipaddress {

TCP  192.168.1.128:3306 rr persistent 20  

virtual_server
192.168.0.139 3005 {

ü  切换需要1s左右的时间。

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

exit
1

1.4.10     高可用方案测试

       echo “0” >/proc/sys/net/ipv4/conf/all/arp_ignore  

/sbin/ifconfig
lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up#注意子网掩码

        state
MASTER

   

nb_get_retry
3

ü  安装配置简单,实现方便,高可用效率好,可以根据服务与系统的可用性多方面进行切换。

virtual_server 192.168.1.128 3306 {  

sysctl
-p

global_defs {

       echo “2” >/proc/sys/net/ipv4/conf/all/arp_announce  

protocol
TCP#(用TCP协议检查realserver状态)

/etc/rc.d/init.d/realserver.sh start

[[email protected]
keepalived]# ipvsadm -ln  

}

}

 

#!/bin/sh

       route del $SNS_VIP >/dev/null
2>&1

服务器名·
IP
OS
MySQL

#
tar zxvf keepalived-1.2.7.tar.gz

        smtp_connect_timeout 30

SNS_VIP=192.168.1.128  

192.168.0.139#VIP,可以是多个,每个ip占一行

在master、backup服务器都进行安装:

vrrp_instance loadbalance {  

安装完后,在安装lvs,我们这样采用云安装:

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

   ⑷ KeepAlived安装

#
cd keepalived-1.2.7

       ;;

+ KeepAlived +
LVS单点写入主主同步高可用架构实验 ㈠ 实战环境 服务器名 IP OS MySQL
odd.example.com 192.168.1.116 RHEL-5.8 5.5.16 even.example.com
192.1…

}

 

IP Virtual Server version 1.2.1 (size=4096)  

1.3
配置keepalived开机启动

1.1  方案简介