企业Web高可用集群实战之LVS+Keepalived+MySQL HA(6)

先在31服务器上建个库:

mysql> create database t_test; Query OK, 1 row affected (0.03 sec)  mysql> show databases; +--------------------+ | Database           | +--------------------+ | information_schema | | mysql              | | performance_schema | | t_test             | | test               | +--------------------+ 5 rows in set (0.00 sec)  再到32服务器查询是否同步过来这个库: mysql> show databases; +--------------------+ | Database           | +--------------------+ | information_schema |  | bbs                |  | mysql              |  | performance_schema |  | t_test             |  | test               |  +--------------------+ 6 rows in set (0.00 sec)  可以看到同步过来了! 反过来一样!这步略!  5.keepalived安装配置 yum -y install kernel-devel ipvsadm ln -sv /usr/src/kernels/2.6.18-308.8.2.el5-x86_64/ /usr/src/linux cd /opt tar zxf keepalived-1.1.20.tar.gz cd keepalived-1.1.20 ./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.18-308.11.1.el5-x86_64/ make;make install cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ mkdir /etc/keepalived chkconfig keepalived on  创建配置文件: 主服务器: cat /etc/keepalived/keepalived.conf  ! Configuration File for keepalived  global_defs {    notification_email {      250621008@qq.com    }    notification_email_from 250621008@qq.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 100     advert_int 1     nopreempt   #不抢占,只在priority高的节点上设置     authentication {         auth_type PASS         auth_pass 1111     }     virtual_ipaddress {         192.168.8.30     }  virtual_server 192.168.8.30 3306 {     delay_loop 2     lb_algo wrr     lb_kind DR     persistence_timeout 60     protocol TCP      real_server 192.168.8.31 3306         weight 3         notify_down /root/sh/mysql.sh             TCP_CHECK {             connect_timeout 10             nb_get_retry 3             delay_before_retry 3             connect_port 3306         }     }  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  从服务器: cat /etc/keepalived/keepalived.conf  ! Configuration File for keepalived  global_defs {    notification_email {      250621008@qq.com    }    notification_email_from 250621008@qq.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 90     advert_int 1     authentication {         auth_type PASS         auth_pass 1111     }     virtual_ipaddress {         192.168.8.30     }  virtual_server 192.168.8.30 3306 {     delay_loop 2     lb_algo wrr     lb_kind DR     persistence_timeout 60     protocol TCP      real_server 192.168.8.32 3306         weight 3         notify_down /root/sh/mysql.sh             TCP_CHECK {             connect_timeout 10             nb_get_retry 3             delay_before_retry 3             connect_port 3306         }     } 

主备配置文件注意几点:

1).router_id 两边必须相同

2).state 两边都为BACKUP

3).virtual_router_id 两边必须相同

4).priority 主节点的值必须大于从节点的值

5).nopreempt 不抢占,只在priority高的节点(即主节点)上设置

6).real_server 只需要本机的IP,不需要其它节点的!

7).notify_down 作用是监测到当mysql停止工作时自动关闭本机的keepalived的脚本,实现故障转移!

 

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

转载注明出处:http://www.heiqu.com/d97f8152a936bfc51c890875a49d8fdc.html