实现功能:

可以实现MySQL的分表,以及分表之后的增加,删除,修改,查询等MySQL的一系列操作。可以扩展MySQL的主从架构,方便MySQL架构的分布式扩展。

实验测试架构为在两个MASTER上面安装了keepalived和kingshard中间件,两个master之间互为主从,两个master都有一个slave。实现MySQL和kingshard的高可用,防止单点故障。

注意:

所有关于分表的操作都必须通过kingshard连接。

Kingshard只负责分表之后的操作,所有的数据同步是MySQL主从同步自己完成。

现在node1上面keepalived配置如下keepalived.conf:

! Configuration File for keepalived

global_defs {

notification_email {

ibuler@qq.com ##出故障发送邮件给谁

}

notification_email_from keepalived@localhost ##故障用哪个邮箱发送邮件

smtp_server 127.0.0.1 ##SMTP_Server IP

smtp_connect_timeout 30 ##超时时间

router_id LVS_DEVEL ##服务器标识

}

#vrrp_script chk_http_port {

#  script "/opt/nginx.sh"

#  interval 2

#  weight 2

#}

vrrp_instance VI_1 {

state MASTER

##状态,都为BACKUP,它们会推选Master,如果你写MASTER,它就会是Master,

##当Master故障时Backup会成为Master,当原来的Master恢复后,原来的Master会成为Master

interface em1 ##发送VRRP的接口,仔细看你的是不是eth0

virtual_router_id 51 ##虚拟路由标识,同一个组应该用一个,即Master与Backup同一个

priority 100 ##重要的优先级哦

nopreempt ##不抢占,一个故障时,重启后恢复后不抢占意资源

advert_int 1 ##同步间隔时长

authentication { ##认证

auth_type PASS ##认证方式

auth_pass www.laoguang.me ##密钥

}

track_script {

chk_http_port

}

virtual_ipaddress {

192.168.1.170 ##VIP

}

}

Kingshard配置如下,ks.yaml:

# server listen addr

addr : 0.0.0.0:9696

# server user and password

user :  kingshard

password : kingshard

# if set log_path, the sql log will write into log_path/sql.log,the system log

# will write into log_path/sys.log

log_path : /tmp/kingshard

# log level[debug|info|warn|error],default error

log_level : debug

# if set log_sql(on|off) off,the sql log will not output

log_sql: on

# only log the query that take more than slow_log_time ms

#slow_log_time : 100

# the path of blacklist sql file

# all these sqls in the file will been forbidden by kingshard

#blacklist_sql_file: /Users/flike/blacklist

# only allow this ip list ip to connect kingshard

#allow_ips: 127.0.0.1

# the charset of kingshard, if you don't set this item

# the default charset of kingshard is utf8.

#proxy_charset: gbk

# node is an agenda for real remote mysql server.

nodes :

-

name : node1

# default max conns for mysql server

max_conns_limit : 32

# all mysql in a node must have the same user and password

user :  root

password : 6lapp

# master represents a real mysql master server

master : 192.168.1.231:3306

# slave represents a real mysql salve server,and the number after '@' is

# read load weight of this slave.

slave : 192.168.1.188:3306

down_after_noalive : 32

-

name : node2

# default max conns for mysql server

max_conns_limit : 32

# all mysql in a node must have the same user and password

user :  root

password : 6lapp

# master represents a real mysql master server

master : 192.168.1.189:3306

# slave represents a real mysql salve server

slave : 192.168.1.181:3306

# down mysql after N seconds noalive

# 0 will no down

down_after_noalive: 32

# schema defines sharding rules, the db is the sharding table database.

schema :

db : 6l_wangfan

nodes: [node1]

default: node1

shard:

-

table: ll_wf_user_info

key: user_id

nodes: [node1]

type: hash

locations: [6]

Node2配置类似.

备注:

kingshard是开源的产品,githup地址为:https://github.com/flike/kingshard

使用软件:

keepalive1.2.7

mysql5.6.11

kingshard1.4

mysql kingshard_浅谈 Kingshard MySQL 中间件相关推荐

  1. mysql 不要统计null_浅谈为什么Mysql数据库尽量避免NULL

    在Mysql中很多表都包含可为NULL(空值)的列,即使应用程序并不需要保存NULL也是如此,这是因为可为NULL是列的默认属性.但我们常在一些Mysql性能优化的书或者一些博客中看到观点:在数据列中 ...

  2. MYSQL优化浅谈,工具及优化点介绍,mysqldumpslow,pt-query-digest,explain等

    MYSQL优化浅谈 msyql是开发常用的关系型数据库,快速.稳定.开源等优点就不说了. 个人认为,项目上线,标志着一个项目真正的开始.从运维,到反馈,到再分析,再版本迭代,再优化- 这是一个漫长且考 ...

  3. 浅谈Django的中间件与Python的装饰器

    浅谈Django的中间件 与Python的装饰器 一.原理 1.装饰器是Python的一种语法应用,利用闭包的原理去更改一个函数的功能,即让一个函数执行之前先到另外一个函数中执行其他需求语句,在执行该 ...

  4. mysql key_len_浅谈mysql explain中key_len的计算方法

    mysql的explain命令可以分析sql的性能,其中有一项是key_len(索引的长度)的统计.本文将分析mysql explain中key_len的计算方法. 1.创建测试表及数据 CREATE ...

  5. mysql创建存储过程意义_浅谈一下mySql中创建存储过程

    首先说一下为什么要使用存储过程,存储过程是在数据库中预编译的程序代码,其执行效率显然要比从程序端传过去的sql语句要高的多,这样既可以节省网络带宽,又可以加快sql的执行速度,可以很好的提高系统的性能 ...

  6. 【①MySQL】浅谈数据库系统:MySQL的简介与安装配置

    前言 欢迎来到小K的MySQL专栏,本节将为大家带来MySQL的简介与安装配置的详细讲解~ 目录 前言 一.数据库系统概述 数据(Data) 数据库(Database) 数据库管理系统(Databas ...

  7. mysql数据库内NOT NULL_浅谈为什么Mysql数据库尽量避免NULL

    在Mysql中很多表都包含可为NULL(空值)的列,即使应用程序并不需要保存NULL也是如此,这是因为可为NULL是列的默认属性.但我们常在一些Mysql性能优化的书或者一些博客中看到观点:在数据列中 ...

  8. spring 主从表_听听京东架构师浅谈,MySQL binlog 主从同步

    一.binlog 的基础知识 1,binlog 的概念 Server 层的日志系统(归档日志),binlog 中跟踪对其数据库的所有更改操作.是逻辑日志,以追加日志的形式记录. 2,binLog 的三 ...

  9. 【MySQL】浅谈一致性读

    一 前言 MySQL 在不同的事务隔离级别下提供两种读模式 一致性读(非加锁), 当前读(加锁读).当前读比较简单,本文主要研究一致性读取. 二 原理概念 官方概念 "A consisten ...

最新文章

  1. 2021《程序员》数字科技企业研发实力榜TOP50
  2. The Text Splitting (将字符串分成若干份,每份长度为p或q)
  3. 使用Xcode和Instruments调试解决iOS内存泄露【转】
  4. UBUNTU安装 Rabbitvsc可视化版本控制客户端软件
  5. 转: 理解RESTful架构
  6. cucumber测试_如何在Cucumber中进行后端测试
  7. 爬取了10W条数据,我们整理出了这份北上广深租房图鉴
  8. MATLAB图片的保存与导出
  9. Linux tcpdump
  10. 红外接收头图片_常见红外接收头引脚型号及测量代换
  11. Java中Minio基础使用
  12. [转]取本页URL地址的方法是(总结):
  13. C++ typename 的双重含义
  14. Python让繁琐工作自动化——chapter12 处理Excel电子表格
  15. FileZilla Server目录显示失败的处理方法
  16. 如何在Tomcat中配置二级域名
  17. PTA 数据结构与算法题目集(中文)7-38 寻找大富翁(25 分)快排或堆排序
  18. springboot绑定邮箱激活发邮件
  19. 【计算机网络】思科实验(3):使用三层交换机实现跨VLAN间的通信
  20. 百度wenku的下载

热门文章

  1. PHP多线程(Pthread初探)
  2. java web开发中会遇到的异步执行方案
  3. win10 + python3.6.1 + tensorflow1.10 + cuda9.0 + cudnn7.2
  4. Change Jenkins time zone
  5. HDU - 2122 Ice_cream’s world III
  6. vue-cli 中stylus写样式莫名报错?
  7. html 13 背景
  8. 《Cracking the Coding Interview》——第10章:可扩展性和存储空间限制——题目1
  9. 【Linux】关于Linux操作系统的基本操作
  10. 使用抓包工具fiddler和apipost进行接口测试