Mysql 主主+keepalived

主主搭建配置

  • . 修改配置文件
    binlog_ignore_db=mysql
    binlog_ignore_db=information_schema
    binlog_ignore_db=performance_schema
    binlog_ignore_db=sys
    server_id=…
    reset master
    show master logs
  • . 添加复制用户(两台机器都添加)
    grant replication slave on . to ‘repl’@‘192.168.114.%’ identified by ‘1234’;
  • . A 库操作
    CHANGE MASTER TO
    MASTER_HOST=‘192.168.114.133’,
    MASTER_USER=‘repl’,
    MASTER_PASSWORD=‘1234’,
    MASTER_PORT=3306
    start slave;
    show slave status \G;
    B 库操作
    CHANGE MASTER TO
    MASTER_HOST=‘192.168.114.134’,
    MASTER_USER=‘repl’,
    MASTER_PASSWORD=‘1234’,
    MASTER_PORT=3306
    start slave;
    show slave status \G;
  • . 验证
    A create database t1;
    B create database t2;

虚拟ip配置

  • 手动配置
    ifconfig ens33:1 192.168.114.155 netmask 255.255.255.0
    ip addr del 192.168.114.155 dev ens33:1
  • keepavlied 工具
! Configuration File for keepalived

global_defs {
    router_id HA_MsSql
}

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

virtual_server 192.168.114.155 3306 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP
    real_server 192.168.114.133 3306 {
        weight 1
	    notify_down /root/shutdown.sh
	    TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
	    connect_port 3306
           }
        }
}

你可能感兴趣的:(mysql,操作)