淺談 Kingshard MySQL 中介軟體

來源:互聯網
上載者:User

淺談 Kingshard MySQL 中介軟體

實現功能:

可以實現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

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.