为什么80%的码农都做不了架构师?>>>   

MySQL Fabric 是一个用于管理 MySQL 服务器群的可扩展框架。该框架实现了两个特性 — 高可用性 (HA) 以及使用数据分片的横向扩展。这两个特性既可以单独使用,也可以结合使用。本文只测试高可用性。

测试环境

centos 6.5

192.168.17.177   mysql数据库

192.168.17.178   Fabric服务器和mysql数据库

192.168.17.179 mysql数据库

192.168.17.180   mysql数据库

防火墙

重启后永久性生效:

开启:chkconfig iptables on

关闭:chkconfig iptables off

即时生效,重启后失效:

开启:service iptables start

关闭:service iptables stop

1、安装mysql,4台服务器安装相同版本mysql和相同配置

先删除centos6.5自带mysql

rpm -qa | grep mysql
rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64

下载mysql,http://dev.mysql.com/downloads/mysql/

MySQL-client-5.6.28-1.el6.x86_64.rpm
MySQL-devel-5.6.28-1.el6.x86_64.rpm
MySQL-server-5.6.28-1.el6.x86_64.rpm
MySQL-shared-5.6.28-1.el6.x86_64.rpm
MySQL-shared-compat-5.6.28-1.el6.x86_64.rpm

安装mysql

yum localinstall –-nogpgcheck  *.rpm

配置mysql

more /root/.mysql_secret  //查看默认自带密码
service mysql start       //启动mysql
/usr/bin/mysql_secure_installation //初始化mysql

fabric是基于GTID主从复制,所以这些实例中必须要启用GTID,在mysql的配置文件要加上下边参数:

编辑mysql配置文件

vim /usr/my.cnf

在文件中加上

gtid_mode=ON
log-bin
log-slave-updates
enforce-gtid-consistency
server_id=1 //各个服务器的值不同

创建mysql管理员帐号,fabric需要使用mysql管理员级别帐号来管理数据库,4台mysql服务器创建相同的帐号

GRANT ALL PRIVILEGES ON *.* TO 'fabric'@'%' IDENTIFIED BY 'secret' WITH GRANT OPTION;
FLUSH PRIVILEGES;

2、在192.168.17.178服务器安装mysql fabric

Fabric已经被打包到了MySQL Utilities中,下载MySQL Utilities就可以了,另外fabric操作mysql需要使用python连接器,需要同时下载mysql-utilities-1.5.6-1.el6.noarch.rpm(http://dev.mysql.com/downloads/utilities/)、

mysql-connector-python-2.1.3-1.el6.x86_64.rpm(http://dev.mysql.com/downloads/connector/python/)安装。

安装fabric

yum localinstall –-nogpgcheck  *.rpm

vim /etc/mysql/fabric.cfg // 修改fabric配置

[DEFAULT]
prefix =
sysconfdir = /etc
logdir = /var/log
[statistics]
prune_time = 3600
[logging]
url = file:///var/log/fabric.log
level = INFO
[storage]
auth_plugin = mysql_native_password
database = fabric
user = fabric                   //与上边创建的帐号一致
address = 192.168.17.178:3306   // fabric Backing Store用的mysql
connection_delay = 1
connection_timeout = 6
password = secret              //与上边创建的帐号一致
connection_attempts = 6
[failure_tracking]
notification_interval = 60
notification_clients = 50
detection_timeout = 1
detection_interval = 6
notifications = 300
detections = 3
failover_interval = 0
prune_time = 3600
[servers]      //  192.168.17.180、192.168.17.179、192.168.17.177三台mysql的管理员帐号
restore_user = fabric
unreachable_timeout = 5
backup_password = secret
backup_user = fabric
user = fabric
restore_password = secret
password = secret
[connector]
ttl = 1
[protocol.xmlrpc]
disable_authentication = yes  // 关闭验证
ssl_cert =
realm = MySQL Fabric
ssl_key =
ssl_ca =
threads = 5
user = admin
address = 192.168.17.178:32274
password =
[executor]
executors = 5
[sharding]
prune_limit = 10000
mysqldump_program = /usr/bin/mysqldump
mysqlclient_program = /usr/bin/mysql
[protocol.mysql]
disable_authentication = yes  // 关闭验证
ssl_cert =
ssl_key =
ssl_ca =
user = admin
address = 192.168.17.178:32275
password =

初始化Backing Store数据,初始化完成后,可以在192.168.17.178的mysql中看到fabric数据表,这个数据库主要用来Backing Store使用。

mysqlfabric manage setup

启动fabric

mysqlfabric manage start

建立HA服务器组

mysqlfabric group create my_group

将mysql服务器加入HA组中

mysqlfabric group add my_group 192.168.17.177:3306
mysqlfabric group add my_group 192.168.17.179:3306
mysqlfabric group add my_group 192.168.17.180:3306

添加完成后,默认情况不会自己选出主库(PRIMARY),可以让fabric自动选出主库,也可以手动选出主库

1)执行下边命令让fabric选出主库

mysqlfabric group promote my_group

2)手动指定主库

mysqlfabric server set_status 192.168.17.179:3306 primary   // set_status可手工指定4个状态primary, secondary,spare, or faulty.

添加完成后,可以使用使用下边命令查看当前my_group组中的服务器状况

mysqlfabric group lookup_servers my_group
Fabric UUID:  5ca1ab1e-a007-feed-f00d-cab3fe13249e
Time-To-Live: 1server_uuid             address    status       mode weight
------------------------------------ ------------------- --------- ---------- ------
086d9569-a78a-11e5-9205-005056ab3497 192.168.17.180:3306 SECONDARY  READ_ONLY    1.0
452ee193-a4a7-11e5-bf33-005056ab482f 192.168.17.179:3306   PRIMARY READ_WRITE    1.0
edcbd377-a4a7-11e5-bf37-005056ab131b 192.168.17.177:3306 SECONDARY  READ_ONLY    1.0

fabric常用相关命令

mysqlfabric group create my_group          #创建HA组
mysqlfabric group destroy my_group        #删除HA组
mysqlfabric group add my_group 192.168.17.180:3306     #添加组成员
mysqlfabric group remove my_group xxxxxxxx   #移出组成员
mysqlfabric group lookup_servers my_group  #查看组成员
mysqlfabric group promote my_group      #选举master
mysqlfabric groupactivate my_group        #激活自动故障转移
mysqlfabric group deactivate my_group           #禁用自动故障转移
mysqlfabric serverset_status server_uuid status #变更服务器状态
mysqlfabric help manage   #manage命令帮助
mysqlfabric help group     #group命令帮助
mysqlfabric help server      #server命令帮助

3、java测试代码建库,建表,插入数据,查询操作

操作数据库的顺序改为先连接Fabric,再由Fabric内部操作具体的数据库,这里使用java例子,测试代码来自http://dev.mysql.com/downloads/connector/j/ java驱动包中的例子

package demo.fabric;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import com.mysql.fabric.jdbc.FabricMySQLConnection;
/*** Demonstrate working with employee data in MySQL Fabric with Connector/J and the JDBC APIs.*/
public class EmployeesTest {public static void main(String args[]) throws Exception {String hostname = "192.168.17.178";String port = "32274"; String database = "employees";String user = "fabric";String password = "secret";String baseUrl = "jdbc:mysql:fabric://" + hostname + ":" + Integer.valueOf(port) + "/";// Load the driver if running under Java 5if (!com.mysql.jdbc.Util.isJdbc4()) {Class.forName("com.mysql.fabric.jdbc.FabricMySQLDriver");System.out.println("load driver");}Connection rawConnection = DriverManager.getConnection(baseUrl + "mysql?fabricServerGroup=my_group", user, password);Statement statement = rawConnection.createStatement();statement.executeUpdate("create database if not exists employees");System.out.println("create database if not exists employees");statement.close();rawConnection.close();// The 1-st way is to set it's name explicitly via the "fabricServerGroup" connection propertyrawConnection = DriverManager.getConnection(baseUrl + database + "?fabricServerGroup=my_group", user, password);statement = rawConnection.createStatement();statement.executeUpdate("create database if not exists employees");statement.close();rawConnection.close();rawConnection = DriverManager.getConnection(baseUrl + database + "?fabricServerGroup=my_group", user, password);statement = rawConnection.createStatement();statement.executeUpdate("drop table if exists employees");statement.executeUpdate("create table employees (emp_no int not null, first_name varchar(50), last_name varchar(50), primary key (emp_no))");// 2. Insert data// Cast to a Fabric connection to have access to specific methodsFabricMySQLConnection connection = (FabricMySQLConnection) rawConnection;// example data used to create employee recordsInteger ids[] = new Integer[] { 1, 2, 10001, 10002 };String firstNames[] = new String[] { "John", "Jane", "Andy", "Alice" };String lastNames[] = new String[] { "Doe", "Doe", "Wiley", "Wein" };// insert employee dataPreparedStatement ps = connection.prepareStatement("INSERT INTO employees.employees VALUES (?,?,?)");for (int i = 0; i < 4; ++i) {ps.setInt(1, ids[i]);ps.setString(2, firstNames[i]);ps.setString(3, lastNames[i]);ps.executeUpdate();}System.out.println("Querying employees");System.out.format("%7s | %-30s | %-30s%n", "emp_no", "first_name", "last_name");System.out.println("--------+--------------------------------+-------------------------------");ps = connection.prepareStatement("select emp_no, first_name, last_name from employees where emp_no = ?");for (int i = 0; i < 4; ++i) {ps.setInt(1, ids[i]);ResultSet rs = ps.executeQuery();rs.next();System.out.format("%7d | %-30s | %-30s%n", rs.getInt(1), rs.getString(2), rs.getString(3));rs.close();}ps.close();
//        connection.setServerGroupName("my_group");
//        statement.executeUpdate("drop table if exists employees");statement.close();connection.close();}
}

如果当前PRIMARY为192.168.17.179:3306,直接连接192.168.17.179进行增加修改删除,数据能自动同步到192.168.17.177和192.168.17.180,完整的主从模式。

如果当前PRIMARY为192.168.17.179:3306,直接连接192.168.17.177或192.168.17.180,会造成PRIMARY主库的修改无法同步到从数据,需要把从数据库冲突数据删除,重启冲突的从数据库,通过mysqlfabric server set_status修改从数据库的状态为secondary,数据会重新同步。

参考

http://www.csdn.net/article/2014-08-20/2821300

http://dev.mysql.com/doc/mysql-utilities/1.4/en/fabric.html

转载于:https://my.oschina.net/penngo/blog/549282

mysql fabric安装使用测试相关推荐

  1. mysql fabric搭建_MySQL Fabric 安装部署

    MySQL Fabric 是一个用于管理 MySQL 服务器群的可扩展框架.该框架实现了两个特性 - 高可用性 (HA) 以及使用数据分片的横向扩展.这两个特性既可以单独使用,也可以结合使用. 环境: ...

  2. my SQL下载安装,环境配置,以及密码忘记的解决,以及navicat for mysql下载,安装,测试连接...

    一.下载 在百度上搜索"mysql-5.6.24-winx64下载" 二.安装 选择安装路径,我的路径"C:\Soft\mysql-5.6.24-winx64" ...

  3. 测试mysql安装成功_MySQL安装之“测试”

    将MySQL安装完成之后还需要对其进行测试,判断MySQL是否安装成功,MySQL其可视化与我们之前使用过的SQLserver不同.MySQL其中测试方法有两种:一.使用MySQL命令进行测试:二.安 ...

  4. java mysql settings_Java中使用MySQL从安装、配置到实际程序测试详解

    By zieckey(zieckey@yahoo.com.cn) All Rights Reserved! 这里假设你的Java开发环境已经搭建好了. 一.准备工作: 下载MySQL:mysql-5. ...

  5. mysql tpcc_MySQL压测--TPCC安装,测试

    今天我们来讲一下MySQL的压力测试工具,目前我接触到的主要有两种压力测试工具:TPCC,Sysbench,前者只适合MySQL数据库OLTP压力测试,而Sysbench功能就比较广泛,可以测试OS的 ...

  6. MySQL Fabric 实践

    MySQL Fabric能提供MySQL的HA和Sharding方案. 自从2014年5月28日Oracle发布了Fabric,用于MySQL的HA配置管理.这是原生的官方产品,可以放心使用,Fabr ...

  7. mysql读写分离(MySQL Proxy 安装和使用)

    一.必备软件: 1.LUA    可以去LUA的官方下载:www.lua.org 2.MySQL Proxy    这里有好多二进制版本.     http://mysql.cdpa.nsysu.ed ...

  8. mysql以及mysql bench安装教程

    首先,我们需要去官网下载mysql(这里以下载) 1 2 3 4 5 下载好了自己好了之后,点击安装好的东西出现如下界面: 1.接受使用条款并点击next 2.点击custom,可以根据个人习惯进行安 ...

  9. ubuntu+php+mysql+apache安装配置

    ubuntu+php+mysql+apache安装配置 1. 安装运行环境 复制内容到剪贴板 代码: sudo apt-get install apache2 sudo apt-get install ...

最新文章

  1. apache用proxy 实现URL 转发
  2. vs2010中svn使用教程_SVN安装以及和VS2010整合使用-阿里云开发者社区
  3. oracle批输入命令流,ORACLE对表批处理操作
  4. HttpServlet中的service方法
  5. C#有关Session 操作的几个误区【转】
  6. 没有必要对着手机的记事本来记录太多的东西:尝试一下许愿墙的模式吧
  7. Unrecognized option: -javaagent
  8. HTTPS与MITM
  9. 大学生如何成功就业。
  10. Spring中AOP切面编程学习笔记
  11. Android项目跑不起来,本机的android虚拟机跑不起android小项目
  12. OPPO首部5G手机亮相 10倍混合光学变焦技术惊艳MWC
  13. linux的cache过高的原因定位与解决echo 3 > /proc/sys/vm/drop_caches
  14. 火爆全网MySQL路线笔记!linuxmysql允许远程连接
  15. 2018腾讯内部转岗面试题3——找出数组中比左边大比右边的小的元素
  16. 安卓饼状图设置软件_Android自定义控件实现饼状图
  17. 深度学习和机器学习的相关资料
  18. 一篇文章搞懂前端学习方法与构建知识体系
  19. 如何阅读一本书 笔记
  20. 自定义串口通信协议,如何实现?

热门文章

  1. Boost:bind绑定的unique_ptr测试程序
  2. ITK:应用Exp负图像过滤器
  3. VTK:Utilities之WindowModifiedEvent
  4. c++Selection Sort选择排序的实现算法(附完整源码)
  5. c语言实现堆Stack(附完整源码)
  6. 经典C语言程序100例之二八
  7. qmoc文件_Qt中Q_OBJECT与生成的moc文件的作用
  8. docker 外部连接_如何从主机外部(同一网络)连接到Docker容器[Windows]
  9. 1.13.、1.14.Flink 支持的DataType和序列化、Flink Broadcast Accumulators Counters Distributed Cache
  10. 史上最简单的SpringCloud教程 | 第十篇: 高可用的服务注册中心