码迷,mamicode.com
首页 > 数据库 > 详细

MySQL8 Keepalived+双主

时间:2021-01-18 11:43:38      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:replica   serve   ica   tar   sql   ati   track   port   user   

1. 配置双主:

双机名

win89.inno.com

win88.inno.com

 

准备账号

SET SQL_LOG_BIN=0; 
set password for root@localhost=123456; 
grant all privileges on *.* to root@localhost with grant option;
create user repl@win88.inno.com identified WITH mysql_native_password by 123456 PASSWORD EXPIRE NEVER ; 
grant replication slave on *.* to repl@win88.inno.com with grant option; 
create user repl@win89.inno.com identified WITH mysql_native_password by 123456 PASSWORD EXPIRE NEVER ; 
grant replication slave on *.* to repl@win89.inno.com with grant option; 
create user repl@192.168.68.88 identified WITH mysql_native_password by 123456 PASSWORD EXPIRE NEVER ; 
grant replication slave on *.* to repl@192.168.68.88 with grant option; 
create user repl@192.168.68.89 identified WITH mysql_native_password by 123456 PASSWORD EXPIRE NEVER ; 
grant replication slave on *.* to repl@192.168.68.89 with grant option; 
flush privileges;
SET SQL_LOG_BIN=1; 

配置主从

win88.inno.com 的主机

change master to master_host=win89.inno.com,master_port=3308,master_user=repl,master_password=123456,master_auto_position=1; 
start slave; 
show slave status\G

win89.inno.com 的主机

 

change master to master_host=win88.inno.com,master_port=3308,master_user=repl,master_password=123456,master_auto_position=1; 
start slave; 
show slave status\G

 

设置mysql 开机自启

cp -p /data/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
cp -p /data/3308/my.cnf    /etc/my.cnf.d/my.cnf
chkconfig --list

安装keepalive

yum -y install keepalived

win89.inno.com 的keepalived 设定

[root@win89 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id mysql_slave_
   vrrp_skip_check_adv_addr
   vrrp_script check_run {
   script "/data/mysql_check.sh"
   interval 10
}
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens160
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.68.188
    }
    track_script {
    check_run
    }
}

virtual_server 192.168.68.188 3308 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP

    real_server 192.168.68.89 3308 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            connect_port 3308
        }
    }
}

win88.inno.com 的keepalived 设定

[root@win88 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id mysql_master_
   vrrp_skip_check_adv_addr
   vrrp_script check_run {
   script "/data/mysql_check.sh"
   interval 10
}
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens160
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.68.188
    }
    track_script {
    check_run
    }
}

virtual_server 192.168.68.188 3308 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP

    real_server 192.168.68.88 3308 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            connect_port 3308
        }
    }
}

 设置keepalived 开机自启

 systemctl enable keepalived
 systemctl start keepalived

 

MySQL8 Keepalived+双主

标签:replica   serve   ica   tar   sql   ati   track   port   user   

原文地址:https://www.cnblogs.com/tingxin/p/14290434.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!