欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

MySQL高可用性之Keepalived+Mysql

程序员文章站 2022-05-09 18:33:52
...

环境描述:OS:CentOS6.5_X64MASTER:192.168.0.202BACKUP:192.168.0.203VIP:192.168.0.2041、配置两台Mysql主主同步[root@master~]#yuminstallmysql-servermy

环境描述:

OS:CentOS6.5_X64

MASTER:192.168.0.202

BACKUP:192.168.0.203

VIP:192.168.0.204

1、配置两台Mysql主主同步

[root@master ~]# yum install mysql-server mysql -y [root@master ~]# service mysqld start [root@master ~]# mysqladmin -u root password 123.com [root@master ~]# vi /etc/my.cnf #开启二进制日志,设置id [mysqld] log-bin=mysql-bin server-id=1 #backup这台设置2 [root@master ~]# service mysqld restart

#先查看下log bin日志和pos值位置

MySQL高可用性之Keepalived+Mysql

master配置如下:

[root@ master ~]# mysql -u root -p123.com mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.0.%' IDENTIFIED BY 'replication'; mysql> flush privileges; mysql> change master to -> master_host='192.168.0.203', -> master_user='replication', -> master_password='replication', -> master_log_file='mysql-bin.000002', -> master_log_pos=106; #对端状态显示的值 mysql> start slave; #启动同步

backup配置如下:

[root@backup ~]# mysql -u root -p123.com mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.0.%' IDENTIFIED BY 'replication'; mysql> flush privileges; mysql> change master to -> master_host='192.168.0.202', -> master_user='replication', -> master_password='replication', -> master_log_file='mysql-bin.000002', -> master_log_pos=106; mysql> start slave;