阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

浅谈 Kingshard MySQL 中间件

146次阅读
没有评论

共计 2878 个字符,预计需要花费 8 分钟才能阅读完成。

实现功能:

可以实现 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

浅谈 Kingshard MySQL 中间件

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-04/130850.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-22发表,共计2878字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中