mysql主主+keepalived高可用

192.168.81.109 vip
192.168.81.100 centos7 客户端
192.168.81.101 centos7 MysqL主+keepalived主
192.168.81.102 centos7 MysqL主+keepalived备

192.168.81.100
部署数据库
yum -y install mariadb mariadb-server
修改配置文件
vim /etc/my.cnf
server-id=1
log-bin=MysqLbin
relay-log=relays-log
启动mariadb
systemctl start mariadb
部署主服务器
MysqL -e "grant all on *.* to MysqL@'%' identified by 'MysqL';"
MysqL -e "show master status;"
MysqL -e "change master to master_host='192.168.81.102',master_user='MysqL',master_passowrd='MysqL',master_log_file='MysqLbin.000001',master_log_pos=123456"
MysqL -e "slave start;"
MysqL -e "show slave status \G;"
部署keepalived
yum -y install keepalived ipvsadm
修改keepalived配置文件
vim /etc/keepalived/keepalived.conf
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 {
        192.168.81.109
    }
}
virtual_server 192.168.81.109 3306 {
    delay_loop 6
    lb_algo rr
    lb_kind NAT
    persistence_timeout 50
    protocol TCP

    real_server 192.168.81.100 3306 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 3306
        }
    }
}
启动keepalived
systemctl start keepalived
开机启动
chkconfig keepalived on
查看ipvsadm
ipvsadm
192.168.81.100
部署数据库
yum -y install mariadb mariadb-server
修改配置文件
vim /etc/my.cnf
server-id=1
log-bin=MysqLbin
relay-log=relays-log
启动mariadb
systemctl start mariadb
部署主服务器
MysqL -e "grant all on *.* to MysqL@'%' identified by 'MysqL';"
MysqL -e "show master status;"
MysqL -e "change master to master_host='192.168.81.101',master_user='MysqL',master_passowrd='MysqL',master_log_file='MysqLbin.000001',master_log_pos=123456"
MysqL -e "slave start;"
MysqL -e "show slave status \G;"
部署keepalived
yum -y install keepalived ipvsadm
修改keepalived配置文件
vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
    state SLAVE
    interface eth0
    virtual_router_id 51
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.81.109
    }
}
virtual_server 192.168.81.109 3306 {
    delay_loop 6
    lb_algo rr
    lb_kind NAT
    persistence_timeout 50
    protocol TCP

    real_server 192.168.81.101 3306 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 3306
        }
    }
}
启动keepalived
systemctl start keepalived
开机启动
chkconfig keepalived on
查看ipvsadm
ipvsadm
192.168.81.100
部署mariadb
yum -y install mariadb mariadb-server
systemctl start mariadb
远程登陆MysqL主主架构
MysqL -uMysqL -pMysqL -h192.168.81.109 -P3306
MysqL -e "show variables like 'server_id';"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 1     |
+---------------+-------+
1 row in set (0.00 sec)
关闭keepalived主的keepalived和MysqL
systemctl stop keepalived
systemctl stop mariadb
再远程登陆MysqL
MysqL -uMysqL -pMysqL -h192.168.81.109 -P3306
MysqL -e "show variables like 'server_id';"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 2     |
+---------------+-------+
1 row in set (0.00 sec)
自动切换为keepalived备用MysqL数据库

相关文章

安装开始...1.打开“https://dev.mysql.com/downloadsepo/yu...
安装Helm3#官网下载慢#wgethttps://get.helm.sh/helm-v3.5.4...
通过Linux命令行启动用的指令:systemctlstartmariadb.servi...
InstallingMariaDBServer10.4TodeployMariaDBCommunityServe...
阅读目录一什么是存储引擎二mysql支持的存储引擎三使用存储引...
1、安装MariaDB安装命令yum-yinstallmariadbmariadb-server安...