可以实现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 ##密钥
}
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 中间件
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://www.heiqu.com/378cc8503ff4a8b1c52eef4a6e235510.html