第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

KingShard MySQL中間件快速入門

標(biāo)簽:
MySQL

kingshard 是一个由Go开发高性能MySQL Proxy项目.

功能简介:

  • 读写分离
  • 分库分表
  • 数据库扩容

具体功能查看官方文档,这次主要是自己动手搭建基于Kingshard的MySQL集群。

环境

  • Docker
  • Go
  • CentOS 7

过程

  1. 安装Go语言

    yum install golang -y
  2. 安装Kingshard
    git clone https://github.com/flike/kingshard.git src/github.com/flike/kingshard
    cd src/github.com/flike/kingshard
    source ./dev.sh
    make

至此已经算安装了Kingshard,其配置文件等会再做修改

  1. 拉取MysqL镜像,并启动两台MySQL实例

    docker pull mysql:5.6
    docker run --name mysql1 -d -p3307:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6
    docker run --name mysql2 -d -p3308:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6
  2. 初始化两台MySQL数据库,创建测试所需的表

这个语句比较枯燥,粘贴就好了

create database kingshard;
use kingshard;

CREATE TABLE `test_shard_hash_0000` (
  `id` bigint(64) unsigned NOT NULL,
  `str` varchar(256) DEFAULT NULL,
  `f` double DEFAULT NULL,
  `e` enum('test1','test2') DEFAULT NULL,
  `u` tinyint(3) unsigned DEFAULT NULL,
  `i` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `test_shard_hash_0001` (
  `id` bigint(64) unsigned NOT NULL,
  `str` varchar(256) DEFAULT NULL,
  `f` double DEFAULT NULL,
  `e` enum('test1','test2') DEFAULT NULL,
  `u` tinyint(3) unsigned DEFAULT NULL,
  `i` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `test_shard_hash_0002` (
  `id` bigint(64) unsigned NOT NULL,
  `str` varchar(256) DEFAULT NULL,
  `f` double DEFAULT NULL,
  `e` enum('test1','test2') DEFAULT NULL,
  `u` tinyint(3) unsigned DEFAULT NULL,
  `i` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `test_shard_hash_0003` (
  `id` bigint(64) unsigned NOT NULL,
  `str` varchar(256) DEFAULT NULL,
  `f` double DEFAULT NULL,
  `e` enum('test1','test2') DEFAULT NULL,
  `u` tinyint(3) unsigned DEFAULT NULL,
  `i` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `test_shard_hash_0004` (
  `id` bigint(64) unsigned NOT NULL,
  `str` varchar(256) DEFAULT NULL,
  `f` double DEFAULT NULL,
  `e` enum('test1','test2') DEFAULT NULL,
  `u` tinyint(3) unsigned DEFAULT NULL,
  `i` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `test_shard_hash_0005` (
  `id` bigint(64) unsigned NOT NULL,
  `str` varchar(256) DEFAULT NULL,
  `f` double DEFAULT NULL,
  `e` enum('test1','test2') DEFAULT NULL,
  `u` tinyint(3) unsigned DEFAULT NULL,
  `i` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `test_shard_hash_0006` (
  `id` bigint(64) unsigned NOT NULL,
  `str` varchar(256) DEFAULT NULL,
  `f` double DEFAULT NULL,
  `e` enum('test1','test2') DEFAULT NULL,
  `u` tinyint(3) unsigned DEFAULT NULL,
  `i` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `test_shard_hash_0007` (
  `id` bigint(64) unsigned NOT NULL,
  `str` varchar(256) DEFAULT NULL,
  `f` double DEFAULT NULL,
  `e` enum('test1','test2') DEFAULT NULL,
  `u` tinyint(3) unsigned DEFAULT NULL,
  `i` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  1. 配置Kingshard的配置文件,这次只配置Kingshard的hash shard功能
    
    # server listen addr
    addr : 0.0.0.0:9696
user_list:
user :  root
password : 123456

web_addr : 0.0.0.0:9797

web_user : admin
web_password : admin

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

nodes :
name : node1
max_conns_limit : 32
user :  root
password : 123456
master : 127.0.0.1:3307
down_after_noalive : 32

-
name : node2
max_conns_limit : 32
user : root
password : 123456
master : 127.0.0.1:3308
down_after_noalive: 32

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

schema_list :

-
user: root
nodes: [node1,node2]
default: node1
shard:
    db : kingshard
    table: test_shard_hash
    key: id
    nodes: [node1, node2]
    type: hash
    locations: [4,4]

6. 启动Kingshard

./bin/kingshard -config=etc/ks.yaml

![image.png](https://upload-images.jianshu.io/upload_images/426671-f130292240e82acc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

7. 连接Kingshard,测试操作

mysql -h127.0.0.1 -P9696 -p -c

执行相关的SQL语句
insert into test_shard_hash(id,str,f,e,u,i) values(15,"flike",3.14,'test2',2,3);
insert into test_shard_hash(id,str,f,e,u,i) values(7,"chen",2.1,'test1',32,3);
insert into test_shard_hash(id,str,f,e,u,i) values(17,"github",2.5,'test1',32,3);
insert into test_shard_hash(id,str,f,e,u,i) values(18,"kingshard",7.3,'test1',32,3);
select from test_shard_hash where id < 18;
select
from test_shard_hash where id = 18;
/node2/show tables;



![image.png](https://upload-images.jianshu.io/upload_images/426671-62e5b20c433444a0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

在控制台我们都可以看到对应的输出信息

### 问题
1. ks.yml文件中配置的userList都要被使用才行
2. 如果想让非本机访问,ks.yml需要开启一些白名单
3. mysql命令行中的-c功能启用注释

### 最后
绝知此事要躬行,学东西不能光看,亲自动手才知道问题所在。有助于自己更好的理解

### 参考
- [Kingshard文档](https://github.com/flike/kingshard/blob/master/README_ZH.md)
點(diǎn)擊查看更多內(nèi)容
4人點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
JAVA開發(fā)工程師
手記
粉絲
1.1萬
獲贊與收藏
1545

關(guān)注作者,訂閱最新文章

閱讀免費(fèi)教程

感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報(bào)

0/150
提交
取消