Mysql 5.6.27 双主模型&&主备模型安装测试

http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-5.6.27-1.el6.x86_64.rpm-bundle.tar
测试环境:
   两台服务器
         MYSQL-1:10.11.22.78
         MYSQL-2:10.11.22.248
   测试系统
         Centos 6.5_64
   Mysql版本
         MySQL-5.6.27
   Keepalived版本
         keepalived-1.2.13
1、安装Mysql5.6.27,两台服务器执行以下同样操作
   1.1、检查系统是否安装Mysql,如有安装其他的版本卸载之
           [[email protected] ~]# rpm -qa|grep mysql*
                      mysql-libs-5.1.71-1.el6.x86_64
           [[email protected] ~]# yum -y remove mysql-libs-*
   1.2、安装Mysql所依赖的组件
           [[email protected] ~]# yum -y install perl libaio libnuma*
   1.3、解压Mysql软件包并安装
           [[email protected] ~]# tar xf MySQL-5.6.27-1.el6.x86_64.rpm-bundle.tar
           [[email protected] ~]# rpm -ivh MySQL-client-5.6.27-1.el6.x86_64.rpm 
           [[email protected] ~]# rpm -ivh MySQL-server-5.6.27-1.el6.x86_64.rpm
   1.4、初始化数据并测试启动后关闭服务
           [[email protected] ~]# /usr/bin/mysql_install_db
           [[email protected] ~]# service mysql start
                      Starting MySQL. SUCCESS! 
           [[email protected] ~]# service mysql stop
                      Shutting down MySQL.. SUCCESS!
   1.5、移动Mysql到/data/mysql
           [[email protected] ~]# mkdir /data 
           [[email protected] ~]# mv /var/lib/mysql /data/
   1.6、修改Mysql配置文件,添加如下内容,
           [[email protected] ~]# vi /usr/my.cnf
                      [mysqld]
                      datadir=/data/mysql
                      socket=/data/mysql/mysql.sock      #在配置文件中添加两行
           [[email protected] ~]# service mysql start
                      Starting MySQL. SUCCESS!
   1.7、创建链接文件,不然登录数据库会报错:
           [[email protected] ~]# mkdir /var/lib/mysql
           [[email protected] ~]# ln -s /data/mysql/mysql.sock  /var/lib/mysql/mysql.sock
   1.8、查看数据库root用户的临时密码
           [[email protected] ~]# cat /root/.mysql_secret
                      # The random password set for the root user at Thu Apr 21 13:06:24 2016 (local time): xJYL3JTDc0uYZipg
   1.9、使用临时密码登录数据库,并修改密码为root      
           [[email protected] ~]# mysql -uroot -p
                      Enter password: 
                      Welcome to the MySQL monitor.  Commands end with ; or \g.
                      Your MySQL connection id is 1
                      Server version: 5.6.27
                      Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
                      Oracle is a registered trademark of Oracle Corporation and/or its
                      affiliates. Other names may be trademarks of their respective
                      owners.
                      Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
                      mysql>
                      mysql> set password =password(‘root‘);
                           Query OK, 0 rows affected (0.00 sec)
   1.10、添加开机启动
           [[email protected] ~]# chkconfig mysql on
2、配置Mysql服务
   2.1、在mysql-1服务器10.11.22.78上操作如下
           [[email protected] ~]# mysql -uroot -p 
                      mysql> CREATE USER ‘test‘@‘%‘;
                      mysql> GRANT REPLICATION SLAVE ON *.* TO ‘test‘@‘%‘ IDENTIFIED BY ‘123‘;
           [[email protected] ~]# vi /usr/my.cnf
                      server-id = 1
                      log-bin = mysql-bin
                      auto-increment-increment= 2
                      auto-increment-offset = 1
           [[email protected] ~]# mysql -uroot -p 
                      mysql>  CHANGE MASTER TO
                           -> MASTER_HOST=‘10.11.22.248‘,
                           -> MASTER_USER=‘test‘,
                           -> MASTER_PASSWORD=‘123‘;
                        Query OK, 0 rows affected, 2 warnings (0.05 sec)
                      mysql> START SLAVE;
                        Query OK, 0 rows affected (0.02 sec)
                      mysql> show slave status \G
*************************** 1. row ***************************
                         Slave_IO_State: Waiting for master to send event
                            Master_Host: 10.11.22.248
                            Master_User: test34
                            Master_Port: 3306
                          Connect_Retry: 60
                        Master_Log_File: mysql-bin.000001
                    Read_Master_Log_Pos: 120
                         Relay_Log_File: MYSQL-1-relay-bin.000002
                          Relay_Log_Pos: 283
                  Relay_Master_Log_File: mysql-bin.000001
                       Slave_IO_Running: Yes
                      Slave_SQL_Running: Yes
                        Replicate_Do_DB: 
                    Replicate_Ignore_DB: 
                     Replicate_Do_Table: 
                 Replicate_Ignore_Table: 
                Replicate_Wild_Do_Table: 
            Replicate_Wild_Ignore_Table: 
                             Last_Errno: 0
                             Last_Error: 
                           Skip_Counter: 0
                    Exec_Master_Log_Pos: 120
                        Relay_Log_Space: 458
                        Until_Condition: None
                         Until_Log_File: 
                          Until_Log_Pos: 0
                     Master_SSL_Allowed: No
                     Master_SSL_CA_File: 
                     Master_SSL_CA_Path: 
                        Master_SSL_Cert: 
                      Master_SSL_Cipher: 
                         Master_SSL_Key: 
                  Seconds_Behind_Master: 0
          Master_SSL_Verify_Server_Cert: No
                          Last_IO_Errno: 0
                          Last_IO_Error: 
                         Last_SQL_Errno: 0
                         Last_SQL_Error: 
            Replicate_Ignore_Server_Ids: 
                       Master_Server_Id: 2
                            Master_UUID: 29bd0cab-077f-11e6-83be-000c29933162
                       Master_Info_File: /data/mysql/master.info
                              SQL_Delay: 0
                    SQL_Remaining_Delay: NULL
                Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O 
                thread     to update it
                     Master_Retry_Count: 86400
                            Master_Bind: 
                Last_IO_Error_Timestamp: 
               Last_SQL_Error_Timestamp: 
                         Master_SSL_Crl: 
                     Master_SSL_Crlpath: 
                     Retrieved_Gtid_Set: 
                      Executed_Gtid_Set: 
                          Auto_Position: 0
                  1 row in set (0.00 sec) 
   2.2、在mysql-2服务器10.11.22.248上操作如下
           [[email protected] ~]# mysql -uroot -p 
                      mysql> CREATE USER ‘test‘@‘10.11.22.78‘; 
                      mysql> GRANT REPLICATION SLAVE ON *.* TO ‘test‘@‘10.11.22.78‘ IDENTIFIED BY 
                             ‘123‘;  
           [[email protected] ~]# vi /usr/my.cnf
                      server-id = 2
                      log-bin = mysql-bin            #开启日志功能
                      auto-increment-increment= 2
                      auto-increment-offset = 1 
           [[email protected] ~]# mysql -uroot -p
                      mysql> CHANGE MASTER TO
                          -> MASTER_HOST=‘10.11.22.78‘,
                          -> MASTER_USER=‘test‘,
                          -> MASTER_PASSWORD=‘123‘; 
                        Query OK, 0 rows affected, 2 warnings (0.10 sec) 
                      mysql>  START SLAVE;
                        Query OK, 0 rows affected (0.01 sec)
                      mysql>  START SLAVE;
                        Query OK, 0 rows affected (0.01 sec)
                      mysql> show slave status \G
              *************************** 1. row ***************************
                             Slave_IO_State: Waiting for master to send event
                                Master_Host: 10.11.22.78
                                Master_User: test
                                Master_Port: 3306
                              Connect_Retry: 60
                            Master_Log_File: mysql-bin.000001
                        Read_Master_Log_Pos: 120
                             Relay_Log_File: MYSQL-2-relay-bin.000002
                              Relay_Log_Pos: 283
                      Relay_Master_Log_File: mysql-bin.000001
                           Slave_IO_Running: Yes
                          Slave_SQL_Running: Yes
                            Replicate_Do_DB: 
                        Replicate_Ignore_DB: 
                         Replicate_Do_Table: 
                     Replicate_Ignore_Table: 
                    Replicate_Wild_Do_Table: 
                Replicate_Wild_Ignore_Table: 
                                 Last_Errno: 0
                                 Last_Error: 
                               Skip_Counter: 0
                        Exec_Master_Log_Pos: 120
                            Relay_Log_Space: 458
                            Until_Condition: None
                             Until_Log_File: 
                              Until_Log_Pos: 0
                         Master_SSL_Allowed: No
                         Master_SSL_CA_File: 
                         Master_SSL_CA_Path: 
                            Master_SSL_Cert: 
                          Master_SSL_Cipher: 
                             Master_SSL_Key: 
                      Seconds_Behind_Master: 0
              Master_SSL_Verify_Server_Cert: No
                              Last_IO_Errno: 0
                              Last_IO_Error: 
                             Last_SQL_Errno: 0
                             Last_SQL_Error: 
                Replicate_Ignore_Server_Ids: 
                           Master_Server_Id: 1
                                Master_UUID: f3a1ded7-079d-11e6-8487-000c29fb08f7
                           Master_Info_File: /data/mysql/master.info
                                  SQL_Delay: 0
                        SQL_Remaining_Delay: NULL
                    Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O  
                                             thread to update it
                         Master_Retry_Count: 86400
                                Master_Bind: 
                    Last_IO_Error_Timestamp: 
                   Last_SQL_Error_Timestamp: 
                             Master_SSL_Crl: 
                         Master_SSL_Crlpath: 
                         Retrieved_Gtid_Set: 
                          Executed_Gtid_Set: 
                              Auto_Position: 0
                1 row in set (0.00 sec)
   2.3、测试同步
       2.3.1、在MYSQL-1服务器10.11.22.78上创建一个数据库:MYSZHANG
               mysql> CREATE DATABASE MYSZHANG;
                    Query OK, 1 row affected (0.00 sec)
       2.3.2、在MYSQL-2服务器10.11.22.248上查看同步情况
               mysql> show databases;
                      +--------------------+
                      | Database           |
                      +--------------------+
                      | information_schema |
                      | MYSZHANG           |
                      | mysql              |
                      | performance_schema |
                      | test               |
                      +--------------------+
                 5 rows in set (0.02 sec)
   2.4、测试数据库同步成功
3、安装keepalived-1.2.13
   3.1、下载Keepalived安装包
       http://rpmfind.net/linux/rpm2html/search.php?query=keepalived(x86-64)
   3.2、安装Keepalived,用yum --nogpgcheck localinstall 在本地解决依赖关系
       [[email protected] ~]# yum -y --nogpgcheck localinstall keepalived-1.2.13-5.el6_6.x86_64.rpm
   3.3、双节点配置Keepalived
       [[email protected] ~]# vi /etc/keepalived/keepalived.conf
               ! Configuration File for keepalived
                 global_defs {
                 notification_email {
                        [email protected]
                       }
                 notification_email_from [email protected]
                        smtp_server 127.0.0.1
                        smtp_connect_timeout 30
                        router_id LVS_DEVEL
                }
                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 {
                          10.11.22.55/24 dev eth0 label eth0:0
                          }
                }
    3.4、测试方法如上
    3.5、主备节点配置,备节点只需将 state MASTER改为state BACKUP,优先级priority 100调低
               ! Configuration File for keepalived
                 global_defs {
                 notification_email {
                        [email protected]
                       }
                 notification_email_from [email protected]
                        smtp_server 127.0.0.1
                        smtp_connect_timeout 30
                        router_id LVS_DEVEL
                }
                vrrp_instance VI_1 {
                     state MASTER            #主节点,备节点调整为BACKUP
                     interface eth0
                     virtual_router_id 51
                     priority 100            #备节点优先级调低于主节点即可
                     advert_int 1
                     authentication {
                          auth_type PASS
                          auth_pass 1111
                         }
                    virtual_ipaddress {
                          10.11.22.55/24 dev eth0 label eth0:0
                          }
                }
                virtual_server 10.11.22.55 3306 {
                     delay_loop 6
                     lb_algo rr
                     lb_kind DR
                     nat_mask 255.255.255.0
                     #persistence_timeout 50
                     protocol TCP
                     real_server 10.11.22.78 3306 {
                                weight 1
                                TCP_CHECK {
                                   connect_timeout 3
                                   nb_get_retry 3
                                   delay_before_retry 3
                                }
                     }
                    real_server 10.11.22.248 3306 {
                             weight 1
                             TCP_CHECK {
                                 connect_timeout 3
                                 nb_get_retry 3
                                 delay_before_retry 3
                             }
                    }
                  }
                }
    3.6、测试方法如上,不论主主还是主备测试成功。主备模式down掉运行的主节点数据库服务器,备节点会接管主节
         点继续运行。

Mysql 5.6.27 双主模型&&主备模型安装测试

时间: 2024-10-13 17:42:39

Mysql 5.6.27 双主模型&&主备模型安装测试的相关文章

MariaDB、MySQL双主互备模型同步数据

MySQL双主互备即两台MySQL服务器同时是主服务器,而同时又是对方的从服务器,这样可以分担主服务器的一部分写请求,因为如果是单主模型的话数据写入只能写入在一台MySQL服务器,而双主模型则可同时写在两台服务器上,有效加快了写入的速度,而且还能提供数据的备份功能. 环境如下: server1:CentOS 6.5 x86_64 mariadb 10.0.10 IP:192.168.10.204 server2:CentOS 6.5 x86_64 mariadb 10.0.10  IP:192.

MySQL双主(主主)架构方案

在企业中,数据库高可用一直是企业的重中之重,中小企业很多都是使用mysql主从方案,一主多从,读写分离等,但是单主存在单点故障,从库切换成主库需要作改动.因此,如果是双主或者多主,就会增加mysql入口,增加高可用.不过多主需要考虑自增长ID问题,这个需要特别设置配置文件,比如双主,可以使用奇偶,总之,主之间设置自增长ID相互不冲突就能完美解决自增长ID冲突问题. 主从同步复制原理 在开始之前,我们先来了解主从同步复制原理. 复制分成三步: 1. master将改变记录到二进制日志(binary

Keepalived+nginx双主互备模型实现

Keepalived双主互备模型实现 实验拓扑概述 本次实验所涉及的系统发行版本为:CentOS6.6-64bit:内核版本:2.6.32-504.el6.x86_64 (nod1)Nginx代理1:配置有nginx服务,向外部宣称一个公网ip接收外部客户端请求,网卡eth0桥接模式,配置有内网ip172.16.13.11:eth1(1.1.1.2/24)仅主机模式,模拟与出口路由器通信接口,nod1为VIP1的MASTER时,VIP(1.1.1.100/32)配置于eth1的别名eth1:1上

MySQL Replication, 主从和双主配置

MySQL Replication, 主从和双主配置 MySQL的Replication是一种多个MySQL的数据库做主从同步的方案,特点是异步,广泛用在各种对MySQL有更高性能,更高可靠性要求的场合.与之对应的另一个技术是同步的MySQL Cluster,但因为比较复杂,使用者较少.   下图是MySQL官方给出了使用Replication的场景: Replication原理   Mysql 的 Replication 是一个异步的复制过程,从一个MySQL节点(称之为Master)复制到另

MySQL组复制(4):配置多主模型的组复制

在这一篇,我演示的是如何配置MySQL组复制的多主模型(multi-primary).在配置上,多主模型的组复制和单主模型基本没区别. 本文仅为搭建和维护多主模型组复制抛块小砖,若对其间涉及的术语和理论有所疑惑,可参看: 单主模型相关内容的大长文:配置单主模型的组复制. 组复制的理论:MySQL组复制官方手册翻译. 使用组复制技术,必须要了解它的要求和局限性.见:组复制的要求和局限性. 1.组复制:单主和多主模型 MySQL组复制支持单主模型和多主模型,它们都能保证MySQL数据库的高可用. 单

MySQL高可用方案——双主

MySQL的高可用方案有很多种,双主.MHA.MMM等等,这里只是写下最简单的双主这种高可用方案. 一.配置MySQL互为主从 1.环境准备 系统 IP 主机名 服务 Centos 7.5 192.168.20.2 mysql01 MySQL+keepalived Centos 7.5 192.168.20.3 mysql02 MySQL+keepalived 注:MySQL已部署完成,可参考博文Centos部署MySQL 5.7进行部署. 2.开启二进制日志及中继日志 #主机mysql01配置

MHA大杀器——mysql主、从双击热备配置安装解析

MHA的主要作用: 在mysql的主从复制中,当master崩溃了,利用mha实现backup顶替崩溃的master自动切换为master继续工作,从而实现高可用. 下面介绍本次实验的环境: MHA分为manager管理节点和node节点,一般来讲最少是三台服务器,两台node节点,一台manager节点,但本次环境限制,只能使用两台,所以把manager也装在一台node节点上. 两台服务器,两个网口: IP: 10.2.16.253     10.0.0.1  node1 10.2.16.2

HA集群之keepalived详解/基于keepalived+LVS-DR构建HA主备模型(一)

一.理论部分:     keepalived是vrrp协议的实现:原生设计目的为高可用ipvs服务:keepalived能够配置文件中的定义生成ipvs规则:并能够对各RealServer的健康状态进行检测:  vrrp协议:虚拟冗余路由协议:早期只是主要在路由器上提供的一种非常简单的完成将多个物理设备组建成一个虚拟设备,并且在多个物理设备之间漂移地址一种协议:非常轻量化,性能非常好.而keepalived无非就是通过vrrp协议在Linux主机上通过一个守护进程,把Linux主机扮演成路由器,

MySQL集群MGR架构for单主在线转为多主模式

本文源链接地址:https:www.93bok.com 之前已经完成了MGR集群的单主模式搭建,在生产环境中,我们有时候想改变一下MGR的模式,但是又不想停止mysql服务的正常运行和正常提供服务,本文就来说说,该怎么在不影响mysql正常提供服务的前提下,从单主模式转换为多主模式,即在线转换 注意: 多点写入会存在冲突检查,这耗损性能挺大的,官方建议采用网络分区功能,在程序端把相同的业务定位到同一节点,尽量减少冲突发生几率. 单主模式之前已经搭建过,可参考之前文章,这里直接接着单主模式继续操作