MySQL MHA高可用环境搭建(2)


(4) 查看主库备份时的binlog名称和位置,MASTER_LOG_FILE和MASTER_LOG_POS:
# head -n 30 all.sql | grep 'CHANGE MASTER TO'
-- CHANGE MASTER TO MASTER_LOG_FILE='master-bin.000004', MASTER_LOG_POS=120;


(5) 把备份复制到192.168.1.122和192.168.1.123
# scp all.sql 192.168.1.122:/root/ 
# scp all.sql 192.168.1.123:/root/


(6) 分别在两台服务器上导入备份,执行复制相关命令
在node2、node3 主机上操作:
# mysql -uroot -p123456 < all.sql
mysql> stop slave;
CHANGE MASTER TO   
MASTER_HOST='192.168.1.121',   
MASTER_USER='repl',   
MASTER_PASSWORD='123456',   
MASTER_LOG_FILE='master-bin.000004',   
MASTER_LOG_POS=120;
mysql> start slave; 
mysql> show slave status\G


2. 创建MHA管理用户,在master上创建。
mysql> grant all privileges on *.* to 'root'@'192.168.1.%' identified  by '123456';   
mysql> flush  privileges;
 
三、配置Keepalived VIP
vip配置可以采用两种方式,一种通过keepalived的方式管理虚拟ip的浮动;一人是通过脚本方式,本文通过keepalived方式实现
1. 在node1(Master)与node2(备选主节点)安装keepalived。
# wget    
# tar xf keepalived-1.2.12.tar.gz   
# cd keepalived-1.2.12   
# ./configure --prefix=/usr/local/keepalived   
# make &&  make install   
# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/   
# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/   
# mkdir /etc/keepalived   
# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/   
# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/


2. 配置keepalived的配置文件,在node1(master)上配置操作如下:
注:keepalived配置成backup->backup,即IP地址切换后,主起来后IP地址不切换,本文监控脚本由MHA提供,keepalived不提供对mysqld的监控。
# vi /etc/keepalived/keepalived.conf   
! Configuration File for keepalived
global_defs { 
    notification_email {   
    abc@163.com   
  }   
  notification_email_from dba@dbserver.com   
  smtp_server 127.0.0.1   
  smtp_connect_timeout 30   
  router_id MySQL-HA   
}
vrrp_instance VI_1 { 
    state BACKUP   
    interface eth0   
    virtual_router_id 51   
    priority 150   
    advert_int 1   
    nopreempt
    authentication { 
    auth_type PASS   
    auth_pass 1111   
    }
    virtual_ipaddress { 
        192.168.1.130   
    }   
}


3. 配置keepalived的配置文件,在node2(备用节点)上配置操作如下:
# vi /etc/keepalived/keepalived.conf   
! Configuration File for keepalived
global_defs { 
    notification_email {   
    abc@163.com   
  }   
  notification_email_from dba@dbserver.com   
  smtp_server 127.0.0.1   
  smtp_connect_timeout 30   
  router_id MySQL-HA   
}
vrrp_instance VI_1 { 
    state BACKUP   
    interface eth0   
    virtual_router_id 51   
    priority 120   
    advert_int 1   
    nopreempt
    authentication { 
    auth_type PASS   
    auth_pass 1111   
    }
    virtual_ipaddress { 
        192.168.1.130   
    }   
}


4. node1,node2启动keepalived服务
# service keepalived start 
# chkconfig keepalived on


5. node1查看VIP启动情况
[root@node1 ~]# ip a 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN   
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00   
    inet 127.0.0.1/8 scope host lo   
    inet6 ::1/128 scope host   
      valid_lft forever preferred_lft forever   
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000   
    link/ether 00:0c:29:4e:53:71 brd ff:ff:ff:ff:ff:ff   
    inet 192.168.1.121/24 brd 192.168.1.255 scope global eth0   
    inet 192.168.1.130/32 scope global eth0   
    inet6 fe80::20c:29ff:fe4e:5371/64 scope link   
      valid_lft forever preferred_lft forever

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/33f1d15d8837f955282f8c830e136209.html