电商七十一、keepalived+mysql集群搭建。mysql数据库主主同步。mysql多主同步。

①创建虚拟机,安装mysql、jdk等。

参考:电商六十八、搭建mysql集群。三台mysql机器节点。

②安装keepalived。

参考:电商六十二、Nginx负载均衡高可用、keepalived+nginx实现Nginx集群、主分发器和两台备分发器(可以多台备分发器)

③在mysql上配置keepalived.cnf文件。

利用软件连接192.168.10.168

 

 

 192.168.10.167上的keepalived.cnf内容为:

global_defs {
   router_id  MySQL-HA

 
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval   2
}
 
vrrp_sync_group VG1 {
group {
VI_1
}
}
 
vrrp_instance VI_1 {
    state  BACKUP
    interface eth1 
    virtual_router_id 51
   # nopreempt
    priority 100 
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1234
    }
    track_script {
    check_run
    }
    notify_master /home/mysql/master.sh
    notify_stop /home/mysql/stop.sh
 

    unicast_src_ip 192.168.10.167
    unicast_peer {
        192.168.10.168
        192.168.10.169
    }

    virtual_ipaddress {
       192.168.100.101
    }
}
 

global_defs {
   router_id  MySQL-HA
} 
 
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval   2
}
 
vrrp_sync_group VG1 {
group {
VI_1
}
}
 
vrrp_instance VI_1 {
    state  BACKUP
    interface eth1 
    virtual_router_id 51
   # nopreempt
    priority 100 
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1234
    }
    track_script {
    check_run
    }
    notify_master /home/mysql/master.sh
    notify_stop /home/mysql/stop.sh
 

    unicast_src_ip 192.168.10.167
    unicast_peer {
        192.168.10.168
        192.168.10.169
    }



    virtual_ipaddress {
       192.168.100.101
    }
}

 

 

 

 

 192.168.10.168上的keepalived.cnf的内容为:

global_defs {
   router_id MySQL-HA

 
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval   2
}
 
vrrp_sync_group VG1 {
group {
VI_1
}
}
 
vrrp_instance VI_1 {
    state BACKUP
    interface eth1 
    virtual_router_id 51
   # nopreempt
    priority 99  
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1234
    }
    track_script {
    check_run
    }
    notify_master /home/mysql/master.sh
    notify_stop /home/mysql/stop.sh
 
    unicast_src_ip 192.168.10.168
    unicast_peer {
        192.168.10.167
        192.168.10.169
    }


    virtual_ipaddress {
       192.168.100.101
    }
}
 

global_defs {
   router_id MySQL-HA
} 
 
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval   2
}
 
vrrp_sync_group VG1 {
group {
VI_1
}
}
 
vrrp_instance VI_1 {
    state BACKUP
    interface eth1 
    virtual_router_id 51
   # nopreempt
    priority 99  
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1234
    }
    track_script {
    check_run
    }
    notify_master /home/mysql/master.sh
    notify_stop /home/mysql/stop.sh
 
    unicast_src_ip 192.168.10.168
    unicast_peer {
        192.168.10.167
        192.168.10.169
    }


    virtual_ipaddress {
       192.168.100.101
    }
}

 

192.168.10.169上的keepalived.cnf的内容为:

global_defs {
   router_id MySQL-HA

 
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval   2
}
 
vrrp_sync_group VG1 {
group {
VI_1
}
}
 
vrrp_instance VI_1 {
    state BACKUP
    interface eth1 
    virtual_router_id 51
   # nopreempt
    priority 98  
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1234
    }
    track_script {
    check_run
    }
    notify_master /home/mysql/master.sh
    notify_stop /home/mysql/stop.sh
 

    unicast_src_ip 192.168.10.169
    unicast_peer {
        192.168.10.167
        192.168.10.168
    }

    virtual_ipaddress {
       192.168.100.101
    }
}
 

global_defs {
   router_id MySQL-HA
} 
 
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval   2
}
 
vrrp_sync_group VG1 {
group {
VI_1
}
}
 
vrrp_instance VI_1 {
    state BACKUP
    interface eth1 
    virtual_router_id 51
   # nopreempt
    priority 98  
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1234
    }
    track_script {
    check_run
    }
    notify_master /home/mysql/master.sh
    notify_stop /home/mysql/stop.sh
 

    unicast_src_ip 192.168.10.169
    unicast_peer {
        192.168.10.167
        192.168.10.168
    }



    virtual_ipaddress {
       192.168.100.101
    }
}

 

 

 

 

 

 

 

 

④创建脚本文件:

/home/mysql/mysql_check.sh

/home/mysql/master.sh

/home/mysql/stop.sh

而且内容都要用到/home/mysql/.bashrc

<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值