MySQL Fabric高可用配置

1、架构说明

主机  IP 作用
node10 192.168.1.209 MySQL主机
node09 192.168.1.208 MySQL从机
node08 192.168.1.207 MySQL从机
node06 192.168.1.205 Fabric主机,MySQL 5.7

注:node10\node09\node08的主从已经配置过程略过

2、下载工具包

mkdir soft
cd soft
wget http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.3-1.el6.x86_64.rpm
wget http://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-utilities-1.5.6-1.el6.noarch.rpm
wget http://downloads.mysql.com/archives/get/file/mysql-5.7.9-1.el6.x86_64.rpm-bundle.tar
tar -xvf mysql-5.7.9-1.el6.x86_64.rpm-bundle.tar

3、安装Fabric工具包

[[email protected] soft]# rpm -ivh mysql-connector-python-2.1.3-1.el6.x86_64.rpm 
warning: mysql-connector-python-2.1.3-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-connector-python ########################################### [100%]

[[email protected] soft]# rpm -ivh mysql-utilities-1.5.6-1.el6.noarch.rpm 
warning: mysql-utilities-1.5.6-1.el6.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-utilities        ########################################### [100%]

4、安装MySQL

[[email protected] soft]# rpm -qa|grep mysql |xargs -i rpm -e --nodeps {};
[[email protected] soft]# rpm -ivh mysql-community-*
warning: mysql-community-client-5.7.9-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-common ########################################### [ 11%]
   2:mysql-community-libs   ########################################### [ 22%]
   3:mysql-community-client ########################################### [ 33%]
   4:mysql-community-server ########################################### [ 44%]
   5:mysql-community-devel  ########################################### [ 56%]
   6:mysql-community-embedde########################################### [ 67%]
   7:mysql-community-embedde########################################### [ 78%]
   8:mysql-community-test   ########################################### [ 89%]
   9:mysql-community-libs-co########################################### [100%]

5、创建本地库

创建数据目录
mkdir -p  /u01/mysql
修改配置文件
vi /etc/my.cnf
[mysqld]
datadir=/u01/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

初始化库
 mysqld --initialize --datadir=/u01/mysql 

启动数据库
service mysqld restart
Stopping mysqld:                                           [  OK  ]
Initializing MySQL database:                               [  OK  ]
Starting mysqld:                                           [  OK  ]

查看密码
[[email protected] soft]# cat /var/log/mysqld.log |grep root
2016-03-15T14:54:17.104028Z 1 [Note] A temporary password is generated for [email protected]: %FoohqpBe5UK

登陆数据库修改密码
mysql -uroot -p‘%FoohqpBe5UK‘
mysql>  set password=password(‘Fabric123*‘);

创建帐号及数据库
[[email protected] soft]# mysql -uroot -p‘Fabric123*‘
mysql> create database fabric;
mysql> grant all on fabric.* to [email protected]‘%‘ identified by ‘Fabricdb123*‘;
mysql> grant all on fabric.* to [email protected]‘localhost‘ identified by ‘Fabricdb123*‘;
mysql> drop database fabric;

6、修改Fabric配置文件

vi /etc/mysql/fabric.cfg
.....
[storage]
auth_plugin = mysql_native_password
database = fabric
user = fabric
address = localhost:3306
connection_delay = 1
connection_timeout = 6
password = Fabricdb123*
.....

7、初始化库

[[email protected] soft]# mysqlfabric manage setup --param=storage.user=fabric 
[INFO] 1458056916.001109 - MainThread - Initializing persister: user (fabric), server (localhost:3306), database (fabric).
Finishing initial setup
=======================
Password for admin user is not yet set.
Password for admin/xmlrpc: 
Repeat Password: 
Password set.
Password set.

8、查询数据库

[[email protected] soft]# mysql -uroot -p‘Fabric123*‘
mysql> use fabric;show tables;
Database changed
+-------------------+
| Tables_in_fabric  |
+-------------------+
| checkpoints       |
| error_log         |
| group_replication |
| group_view        |
| groups            |
| log               |
| machines          |
| permissions       |
| proc_view         |
| providers         |
| role_permissions  |
| roles             |
| servers           |
| shard_maps        |
| shard_ranges      |
| shard_tables      |
| shards            |
| user_roles        |
| users             |
+-------------------+
19 rows in set (0.00 sec)

9、启动FABRIC

[[email protected] soft]# mysqlfabric manage start &
[1] 2711
[[email protected] mysql]# [INFO] 1458060656.261079 - MainThread - Initializing persister: user (fabric), server (192.168.1.205:3306), database (fabric).
[WARNING] 1458060656.272060 - MainThread - Provider error: No module named novaclient.
[INFO] 1458060656.272060 - MainThread - Loading Services.
[INFO] 1458060656.288384 - MainThread - MySQL-RPC protocol server started, listening on localhost:32275
[INFO] 1458060656.304173 - MainThread - Fabric node version (1.5.6) started. 
[INFO] 1458060656.307733 - MainThread - Starting Executor.
[INFO] 1458060656.307843 - MainThread - Setting 5 executor(s).
[INFO] 1458060656.308641 - Executor-0 - Started.
[INFO] 1458060656.311089 - Executor-1 - Started.
[INFO] 1458060656.312136 - Executor-2 - Started.
[INFO] 1458060656.315085 - Executor-3 - Started.
[INFO] 1458060656.318284 - MainThread - Executor started.
[INFO] 1458060656.323093 - MainThread - Starting failure detector.
[INFO] 1458060656.323338 - Executor-4 - Started.
[INFO] 1458060656.328053 - XML-RPC-Server - XML-RPC protocol server (‘0.0.0.0‘, 32274) started.
[INFO] 1458060656.328361 - XML-RPC-Server - Setting 5 XML-RPC session(s).
[INFO] 1458060656.329761 - XML-RPC-Session-0 - Started XML-RPC-Session.
[INFO] 1458060656.330760 - XML-RPC-Session-1 - Started XML-RPC-Session.
[INFO] 1458060656.334350 - XML-RPC-Session-2 - Started XML-RPC-Session.
[INFO] 1458060656.337683 - XML-RPC-Session-3 - Started XML-RPC-Session.
[INFO] 1458060656.342705 - XML-RPC-Session-4 - Started XML-RPC-Session.

10、创建成员组

[[email protected] soft]# mysqlfabric group create mydb_group
Fabric UUID:  5ca1ab1e-a007-feed-f00d-cab3fe13249e
Time-To-Live: 1

                                uuid finished success result
------------------------------------ -------- ------- ------
8a41bc19-dc88-465c-84ad-4ef0c534193f        1       1      1

state success          when                                                   description
----- ------- ------------- -------------------------------------------------------------
    3       2   1.45806e+09 Triggered by <mysql.fabric.events.Event object at 0x195ad90>.
    4       2   1.45806e+09                             Executing action (_create_group).
    5       2   1.45806e+09                              Executed action (_create_group).

11、创建Fabric管理帐号到各数据库上

[[email protected] ~]# mysql -uroot -p123456 -e "grant all on *.* to [email protected]‘192.168.1.%‘ identified by ‘Server*01‘"
[[email protected] ~]# mysql -uroot -p123456 -e "grant all on *.* to [email protected]‘192.168.1.%‘ identified by ‘Server*01‘"
[[email protected] ~]# mysql -uroot -p123456 -e "grant all on *.* to [email protected]‘192.168.1.%‘ identified by ‘Server*01‘"

12、添加成员

 mysqlfabric group add mydb_group 192.168.1.209:13306
 mysqlfabric group add mydb_group 192.168.1.208:13306
 mysqlfabric group add mydb_group 192.168.1.207:13306

13、查看成员组信息

[[email protected] soft]# mysqlfabric group lookup_servers mydb_group
Fabric UUID:  5ca1ab1e-a007-feed-f00d-cab3fe13249e
Time-To-Live: 1

                         server_uuid             address    status      mode weight
------------------------------------ ------------------- --------- --------- ------
19e625e0-ea04-11e5-b192-0800273bba44 192.168.1.208:13306 SECONDARY READ_ONLY    1.0
5592ca61-ae26-11e5-8586-08002732e007 192.168.1.209:13306 SECONDARY READ_ONLY    1.0
7cb26cac-ea9d-11e5-a9a1-080027d9fe9c 192.168.1.207:13306 SECONDARY READ_ONLY    1.0

14、自动选主

[[email protected] soft]# mysqlfabric group promote mydb_group
[INFO] 1458061339.876909 - Executor-0 - Master has changed from 7cb26cac-ea9d-11e5-a9a1-080027d9fe9c to None.
[INFO] 1458061340.060467 - Executor-0 - Master has changed from None to 5592ca61-ae26-11e5-8586-08002732e007.
Fabric UUID:  5ca1ab1e-a007-feed-f00d-cab3fe13249e
Time-To-Live: 1

                                uuid finished success result
------------------------------------ -------- ------- ------
a9a9486b-0775-431b-80a7-83f8428c1d5c        1       1      1

state success          when                                                   description
----- ------- ------------- -------------------------------------------------------------
    3       2   1.45806e+09 Triggered by <mysql.fabric.events.Event object at 0x1781190>.
    4       2   1.45806e+09                      Executing action (_define_ha_operation).
    5       2   1.45806e+09                       Executed action (_define_ha_operation).
    3       2   1.45806e+09 Triggered by <mysql.fabric.events.Event object at 0x18dd810>.
    4       2   1.45806e+09                    Executing action (_find_candidate_switch).
    5       2   1.45806e+09                     Executed action (_find_candidate_switch).
    3       2   1.45806e+09 Triggered by <mysql.fabric.events.Event object at 0x18dd850>.
    4       2   1.45806e+09                   Executing action (_check_candidate_switch).
    5       2   1.45806e+09                    Executed action (_check_candidate_switch).
    3       2   1.45806e+09 Triggered by <mysql.fabric.events.Event object at 0x18dd890>.
    4       2   1.45806e+09                       Executing action (_block_write_switch).
    5       2   1.45806e+09                        Executed action (_block_write_switch).
    3       2   1.45806e+09 Triggered by <mysql.fabric.events.Event object at 0x18dd8d0>.
    4       2   1.45806e+09                       Executing action (_wait_slaves_switch).
    5       2   1.45806e+09                        Executed action (_wait_slaves_switch).
    3       2   1.45806e+09 Triggered by <mysql.fabric.events.Event object at 0x18dd910>.
    4       2   1.45806e+09                      Executing action (_change_to_candidate).
    5       2   1.45806e+09                       Executed action (_change_to_candidate).

15、查看信息

[[email protected] soft]# mysqlfabric group lookup_servers mydb_group
Fabric UUID:  5ca1ab1e-a007-feed-f00d-cab3fe13249e
Time-To-Live: 1

                         server_uuid             address    status       mode weight
------------------------------------ ------------------- --------- ---------- ------
19e625e0-ea04-11e5-b192-0800273bba44 192.168.1.208:13306 SECONDARY  READ_ONLY    1.0
5592ca61-ae26-11e5-8586-08002732e007 192.168.1.209:13306   PRIMARY READ_WRITE    1.0
7cb26cac-ea9d-11e5-a9a1-080027d9fe9c 192.168.1.207:13306 SECONDARY  READ_ONLY    1.0

16、激活HA组

mysqlfabric group activate  mydb_group

17、测试HA

[[email protected] ~]# service mysqld stop
Stopping mysqld:                                           [  OK  ]
[[email protected] ~]# mysqlfabric group lookup_servers mydb_group
Fabric UUID:  5ca1ab1e-a007-feed-f00d-cab3fe13249e
Time-To-Live: 1

                         server_uuid             address    status       mode weight
------------------------------------ ------------------- --------- ---------- ------
19e625e0-ea04-11e5-b192-0800273bba44 192.168.1.208:13306 SECONDARY  READ_ONLY    1.0
5592ca61-ae26-11e5-8586-08002732e007 192.168.1.209:13306    FAULTY READ_WRITE    1.0
7cb26cac-ea9d-11e5-a9a1-080027d9fe9c 192.168.1.207:13306   PRIMARY READ_WRITE    1.0

18、恢复节点

[[email protected] ~]# service mysqld start
Starting mysqld:                                           [  OK  ]
[[email protected] ~]# mysqlfabric group lookup_servers mydb_group
Fabric UUID:  5ca1ab1e-a007-feed-f00d-cab3fe13249e
Time-To-Live: 1

                         server_uuid             address    status       mode weight
------------------------------------ ------------------- --------- ---------- ------
19e625e0-ea04-11e5-b192-0800273bba44 192.168.1.208:13306 SECONDARY  READ_ONLY    1.0
5592ca61-ae26-11e5-8586-08002732e007 192.168.1.209:13306    FAULTY READ_WRITE    1.0
7cb26cac-ea9d-11e5-a9a1-080027d9fe9c 192.168.1.207:13306   PRIMARY READ_WRITE    1.0
[[email protected] ~]# mysqlfabric server set_status 5592ca61-ae26-11e5-8586-08002732e007 SPARE
Fabric UUID:  5ca1ab1e-a007-feed-f00d-cab3fe13249e
Time-To-Live: 1

                                uuid finished success result
------------------------------------ -------- ------- ------
49450b84-e382-48f2-9cd9-029cf808490f        1       1      1

state success          when                                                   description
----- ------- ------------- -------------------------------------------------------------
    3       2   1.45815e+09 Triggered by <mysql.fabric.events.Event object at 0x130c510>.
    4       2   1.45815e+09                        Executing action (_set_server_status).
    5       2   1.45815e+09                         Executed action (_set_server_status).

[[email protected] ~]# mysqlfabric server set_status 5592ca61-ae26-11e5-8586-08002732e007 SECONDARY
Fabric UUID:  5ca1ab1e-a007-feed-f00d-cab3fe13249e
Time-To-Live: 1

                                uuid finished success result
------------------------------------ -------- ------- ------
58c4b09f-415f-4735-b95b-967fb4e564a8        1       1      1

state success          when                                                   description
----- ------- ------------- -------------------------------------------------------------
    3       2   1.45815e+09 Triggered by <mysql.fabric.events.Event object at 0x130c510>.
    4       2   1.45815e+09                        Executing action (_set_server_status).
    5       2   1.45815e+09                         Executed action (_set_server_status).
[[email protected] ~]# mysql -uroot -pServer01 -e "show slave status\G"
mysql: [Warning] Using a password on the command line interface can be insecure.
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.207
                  Master_User: fabric
                  Master_Port: 13306
                Connect_Retry: 60
              Master_Log_File: mybin.000001
          Read_Master_Log_Pos: 446
               Relay_Log_File: iZ23o48zbfjZ-relay-bin.000002
                Relay_Log_Pos: 402
        Relay_Master_Log_File: mybin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

20、更新主机

[[email protected] ~]# mysqlfabric group promote mydb_group
[INFO] 1458147024.997307 - Executor-3 - Master has changed from 7cb26cac-ea9d-11e5-a9a1-080027d9fe9c to None.
[INFO] 1458147025.166686 - Executor-3 - Master has changed from None to 5592ca61-ae26-11e5-8586-08002732e007.
Fabric UUID:  5ca1ab1e-a007-feed-f00d-cab3fe13249e
Time-To-Live: 1

                                uuid finished success result
------------------------------------ -------- ------- ------
57f98367-a2bd-4531-9c9d-4804a3aaeb7a        1       1      1

state success          when                                                   description
----- ------- ------------- -------------------------------------------------------------
    3       2   1.45815e+09 Triggered by <mysql.fabric.events.Event object at 0x1123150>.
    4       2   1.45815e+09                      Executing action (_define_ha_operation).
    5       2   1.45815e+09                       Executed action (_define_ha_operation).
    3       2   1.45815e+09 Triggered by <mysql.fabric.events.Event object at 0x12807d0>.
    4       2   1.45815e+09                    Executing action (_find_candidate_switch).
    5       2   1.45815e+09                     Executed action (_find_candidate_switch).
    3       2   1.45815e+09 Triggered by <mysql.fabric.events.Event object at 0x1280810>.
    4       2   1.45815e+09                   Executing action (_check_candidate_switch).
    5       2   1.45815e+09                    Executed action (_check_candidate_switch).
    3       2   1.45815e+09 Triggered by <mysql.fabric.events.Event object at 0x1280850>.
    4       2   1.45815e+09                       Executing action (_block_write_switch).
    5       2   1.45815e+09                        Executed action (_block_write_switch).
    3       2   1.45815e+09 Triggered by <mysql.fabric.events.Event object at 0x1280890>.
    4       2   1.45815e+09                       Executing action (_wait_slaves_switch).
    5       2   1.45815e+09                        Executed action (_wait_slaves_switch).
    3       2   1.45815e+09 Triggered by <mysql.fabric.events.Event object at 0x12808d0>.
    4       2   1.45815e+09                      Executing action (_change_to_candidate).
    5       2   1.45815e+09                       Executed action (_change_to_candidate).

[[email protected] ~]# mysqlfabric group lookup_servers mydb_group
Fabric UUID:  5ca1ab1e-a007-feed-f00d-cab3fe13249e
Time-To-Live: 1

                         server_uuid             address    status       mode weight
------------------------------------ ------------------- --------- ---------- ------
19e625e0-ea04-11e5-b192-0800273bba44 192.168.1.208:13306 SECONDARY  READ_ONLY    1.0
5592ca61-ae26-11e5-8586-08002732e007 192.168.1.209:13306   PRIMARY READ_WRITE    1.0
7cb26cac-ea9d-11e5-a9a1-080027d9fe9c 192.168.1.207:13306 SECONDARY  READ_ONLY    1.0

注:Fabric HA还是不错的,但做为中间件性能就......

时间: 2025-01-08 21:14:27

MySQL Fabric高可用配置的相关文章

Mysql Fabric高可用集群分片功能测试

一.MySQL Fabric高可用集群中一台数据库崩溃了,不影响数据的完整性 1.测试前准备 a)   查看group_id-1集群组的服务器状态 mysqlfabric group lookup_servers group_id-1 返回结果: Command : { success = True   return = [{'status': 'PRIMARY', 'server_uuid': '7a45f71d-7934-11e4-9e8c-782bcb74823a', 'mode': 'R

MySQL+keeplived高可用配置

MySQL高可用基础环境:基于MySQL互为主从(双主.主主),请现配置 主备两台机器 主的操作1.在keepalived主服务器上安装keepalived yum -y install keepalived 2.编辑配置文件 vim /etc/keepalived/keepalived.conf 内容更改如下: vrrp_instance VI_1 { state MASTER \\初始状态:MASTER/BACKUP interface eth0 \\生成VIP的网卡设备 virtual_r

MySQL mmm 高可用配置

10.10.10.20:监控端 10.10.10.21:主 10.10.10.22:主 10.10.10.23:从 10.10.10.24:从 yum -y install mysql mysql-server service mysqld start yum -y install mysql-mmm* useradd --comment "MMM Script owner" --shell /sbin/nologin mmmd yum -y install perl-Time-HiR

mysql复制(高可用架构方案的基础)

mysql复制:把一个数据库实例上所有改变复制到另外一个数据库库服务器实例的过程特点:1.没有改变就无所谓复制 ;改变是复制的根本与数据源2.所有的改变:是指可以复制全部改变,也可以复制部分改变 可以在全部改变中根据业务需求选择部分库和部分表的复制复制的场景: 1.数据库容灾 2.需求:创建一个从数据服务器,做数据的测试和分析 3.负载均衡 4.复制时高可用架构方案的基础 mysql高可用架构特点1.数据库故障的检测与排除2.主从数据库的切换3.数据的备份和保护 mysql高可用架构常用方案1.

DRBD+Heartbeat+Mysql:配置mysql的高可用

说明: 今天接着研究DRBD的第二个应用,利用DRBD+Heartbeat+Mysql:配置mysql的高可用 环境: [[email protected] ~]# cat /etc/issue CentOS release 6.4 (Final) Kernel \r on an \m [[email protected] ~]# uname -r 2.6.32-358.el6.i686 dbm137 192.168.186.137 dbm137.51.com primary DRBD+Hear

MySQL高可用配置

openstack高可用配置文档 介绍利用两台物理主机实现高可用的openstack云平台,这里主要说明mysql和rabbitmq的高可用配置. l  安装openstack云平台(两台主机上都部署openstack I版) 安装centos操作系统,由于以active-passive模式配置mysql等服务的高可用时,需要单独的硬盘分区来装载和同步mysql等服务的数据,所以安装系统时,在系统镜像配置文件里预留出2-3块20G左右单独的硬盘分区作为备用; Yum –y update &&

MySQL之MHA高可用配置及故障切换

前言:跑相同服务的服务器组合起来称为群集中心化群集:有master.slave,MHA用来解决群集中master宕机的情况,MMM群集架构:有两台master服务器MHA概述 日本DeNA公司youshimaton(现就职于Facebook公司)开发 一套优秀的作为MySQL高可用性环境下故障切换和主从提升的高可用软件MHA的组成 MHA Manager(管理节点) MHA Node(数据节点)MHA特点 自动故障切换过程中,MHA试图从宕机的主服务器上保存二进制日志,最大程度的保证数据的不丢失

CoroSync + Drbd + MySQL 实现MySQL的高可用集群

Corosync + DRBD + MySQL 构建高可用MySQL集群 节点规划: node1.huhu.com172.16.100.103 node2.huhu.com172.16.100.104 资源名称规划 资源名称:可以是除了空白字符外的任意ACSII码字符 DRBD设备:在双节点上,此DRBD设备文件,一般为/dev/drbdN,主设备号147 磁盘:在双方节点上,各自提供存储设备 网络配置:双方数据同步所使用的网络属性 DRBD从Linux内核2.6.33起已经整合进内核 1.配置

基于keepalived搭建MySQL的高可用集群

http://www.cnblogs.com/ivictor/p/5522383.html 基于keepalived搭建MySQL的高可用集群 MySQL的高可用方案一般有如下几种: keepalived+双主,MHA,MMM,Heartbeat+DRBD,PXC,Galera Cluster 比较常用的是keepalived+双主,MHA和PXC. 对于小公司,一般推荐使用keepalived+双主,简单. 下面来部署一下 配置环境: 角色