Lvs+keepalived+mysql 双主。

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: Node1: 10.0.17.154Node2: 10.0.17.155VIP: 10.0.17.158环境 centos5.2##########################LVS+Keepalived########################1、安装ipvsadmyum...
Node1: 10.0.17.154
Node2: 10.0.17.155
VIP: 10.0.17.158

环境 centos5.2


##########################LVS+Keepalived########################
1、安装ipvsadm
yum -y install ipvsadm
 
2、安装keepalived
[root@mysql-n2 ~]# wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
[root@mysql-n2 ~]# tar zxvf keepalived-1.1.15.tar.gz
[root@mysql-n2 ~]# cd keepalived-1.1.15
[root@mysql-n2 keepalived-1.1.15]# ./configure --prefix=/ --mandir=/usr/local/share/man/ --with-kernel-dir=/usr/src/kernels/2.6.18-194.el5-x86_64/

配置后会出现如下结果,则配置正确:

Keepalived configuration
------------------------
Keepalived version       : 1.1.15
Compiler                 : gcc
Compiler flags           : -g -O2
Extra Lib                : -lpopt -lssl -lcrypto
Use IPVS Framework       : Yes
IPVS sync daemon support : Yes
Use VRRP Framework       : Yes
Use LinkWatch            : No
Use Debug flags          : No

[root@mysql-n2 keepalived-1.1.15]make && make install
[root@mysql-n2 keepalived-1.1.15]# cd /etc/keepalived/
[root@mysql-n2 keepalived-1.1.15]# vim keepalived.conf


3.keepalived.conf配置细节:
! Configuration File for keepalived

global_defs {
   notification_email {
     zhangshengdongly@gmail.com
   }
   notification_email_from zhangshengdongly@gmail.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.17.158
    }
}

virtual_server 10.0.17.158 443 {
    delay_loop 6
    lb_algo wlc
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 10.0.17.154 443 {
        weight 3
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 10.0.17.155 443 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

BACKUP:只要修改"state MASTER"为"state BACKUP"
              将 "priority 100"更改为"priority 80"

4.配置realserver脚本:(由于只有两台主机,所以既当lvs,也当realserver)
疑问:netmask 255.255.255.255 up修改为netmask 255.255.252.0 up就出现问题

[root@mysql-n2 keepalived-1.1.15]vim realserver

#!/bin/bash
#description : start realserver
VIP=192.168.1.250
/etc/rc.d/init.d/functions
case "$1" in
start)
echo " start LVS of REALServer"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
stop)
/sbin/ifconfig lo:0 down
echo "close LVS Directorserver"
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac

[root@mysql-n2 keepalived-1.1.15]# chmod +x realserver
[root@mysql-n2 keepalived-1.1.15]# ./realserver start

5.主&副keepalived启动:
[root@mysql-n2 ~]# /etc/init.d/keepalived start
Starting keepalived: [  OK  ]
[root@mysql-n1 keepalived]# /etc/init.d/keepalived start
Starting keepalived: [  OK  ]

6.查看日志&IP,看看是否启动成功,ip是否绑定
[root@mysql-n2 ~]# tail -f /var/log/messages
Aug  8 14:47:05 mysql-n2 Keepalived_healthcheckers: SMTP alert successfully sent.
Aug  8 14:47:05 mysql-n2 Keepalived_healthcheckers: SMTP alert successfully sent.
Aug  8 14:47:06 mysql-n2 Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Aug  8 14:47:06 mysql-n2 Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Aug  8 14:47:06 mysql-n2 Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 10.0.17.158
Aug  8 14:47:06 mysql-n2 Keepalived_vrrp: Netlink reflector reports IP 10.0.17.158 added
Aug  8 14:47:06 mysql-n2 Keepalived_healthcheckers: Netlink reflector reports IP 10.0.17.158 added
Aug  8 14:47:06 mysql-n2 avahi-daemon[3052]: Registering new address record for 10.0.17.158 on eth0.
Aug  8 14:47:11 mysql-n2 Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 10.0.17.158
Aug  8 14:47:31 mysql-n2 avahi-daemon[3052]: Invalid query packet.

[root@mysql-n2 ~]# ip a
1: lo: mtu 16436 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet 10.0.17.158/32 brd 10.0.17.158 scope global lo:0
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:ed:e8:c6 brd ff:ff:ff:ff:ff:ff
    inet 10.0.17.154/22 brd 10.0.19.255 scope global eth0
    inet 10.0.17.158/32 scope global eth0
    inet6 fe80::20c:29ff:feed:e8c6/64 scope link
       valid_lft forever preferred_lft forever
3: sit0: mtu 1480 qdisc noop
    link/sit 0.0.0.0 brd 0.0.0.0



LVS+keepalived成功安装后,开始配置mysql的双主。

第一步:安装mysql5.5  http://blog.chinaunix.net/uid-26446098-id-3261946.html
第二步:配置mysql双主 http://blog.chinaunix.net/uid-26446098-id-3267556.html

配置完之后,插入几条数据。
让第一台宕机,看看ip是否漂移,如成功,则安装成功。



相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
12月前
|
负载均衡 应用服务中间件 Linux
Nginx系列教程(14) - LVS+KeepAlived+Nginx实现高性能负载均衡集群
Nginx系列教程(14) - LVS+KeepAlived+Nginx实现高性能负载均衡集群
1019 0
|
2月前
|
运维 负载均衡 网络协议
LVS+Keepalived 负载均衡
LVS+Keepalived 负载均衡
60 8
LVS+Keepalived 负载均衡
|
2月前
|
域名解析 运维 负载均衡
LVS+Keepalived 负载均衡(二)28-1
【8月更文挑战第28天】LVS+Keepalived 负载均衡 配置 LVS VIP
58 5
|
6月前
|
关系型数据库 MySQL 数据库
MySQL集群 双主架构(配置命令)
MySQL集群 双主架构(配置命令)
111 1
|
6月前
|
运维 负载均衡 监控
keepalived+LVS实现高可用性集群
通过结合keepalived和LVS,你可以创建一个高可用性的负载均衡集群,确保服务器的稳定性和性能。这对于托管Web服务、应用服务器等关键服务的服务器集群非常有用。
115 1
|
6月前
|
关系型数据库 MySQL
MySQL高可用性之Keepalived+Mysql(双主热备)
MySQL高可用性之Keepalived+Mysql(双主热备)
|
6月前
|
负载均衡 监控 Linux
CentOS6.5高可用集群LVS+Keepalived(DR模式)
CentOS6.5高可用集群LVS+Keepalived(DR模式)
|
6月前
|
关系型数据库 MySQL Linux
centos7下 Mysql+Keepalived 双主热备高可用图文配置详解
centos7下 Mysql+Keepalived 双主热备高可用图文配置详解
111 0
|
6月前
|
负载均衡 监控 调度
Keepalived+Lvs(dr)调度器主备配置小实验
Keepalived和LVS(Linux Virtual Server)是两个常用的开源软件,通常结合使用以提供高可用性和负载均衡的解决方案。 Keepalived是一种用于实现高可用性的软件,它可以监控服务器的健康状态,并在主服务器出现故障时自动切换到备份服务器。
195 2
|
12月前
|
负载均衡 算法 网络协议
Keepalived+LVS搭建高可用负载均衡
Keepalived+LVS搭建高可用负载均衡
355 1