mysql分表二使用kingshard(支持Innodb、MyISAM分表)

下载地址https://github.com/flike/kingshard

Install

1. Install Go

2. git clone https://github.com/flike/kingshard.git src/github.com/flike/kingshard

3. cd src/github.com/flike/kingshard #(进入go目录下的src目录/usr/local/go/src/github.com/flike/kingshard)

4. source ./dev.sh

5. make

6. set the config file (etc/ks.yaml) 设置配置文件

7. run kingshard (./bin/kingshard -config=etc/ks.yaml) 运行kingshard

一般服务器都有go,第一步可以省略

 

Kingshard的配置如下:

addr : 0.0.0.0:9697 #端口,可自定义

user_list:

-

    user :  root   #mysql user

    password : root  #mysql pwd

web_addr : 0.0.0.0:9797  #web配置,不使用可默认

web_user : admin

web_password : admin

log_path : /mnt

log_level : debug

log_sql: on

allow_ips : 127.0.0.1,122.226.211.*** #绑定ip, 本机和***可访问

nodes :

-

    name : node1

    max_conns_limit : 32 #允许的最大连接数据,启动时默认创建该值的1/2个mysql连接

    user :  root  #mysql user

    password : root #mysql pwd

    master : 127.0.0.1:3306  #mysql端口

    down_after_noalive : 32

schema_list :

-

    user: root

    nodes: [node1]

    default: node1

    shard:

    -   

        db : test #数据库名称

        table: admin_test  #要分表的表名

        key: str #分表所依据的字段名

        nodes: [node1]

        type: hash #hash分表

        locations: [100] #分100张表

    -   

        db : test

        table: admin_test1

        key: name

        nodes: [node1]

        type: hash

        locations: [10]

 

配置ks.yaml分表规则时,需要在原数据库创建同数量的表,如下:

table_name_0000,table_name_0001,table_name_0002,table_name_0003,table_name_0004;

注意ks.yaml文件里的空格与换行

方法1:安装supervisord 管理后台进程

supervisord -c /etc/supervisord.conf   启动

停止  supervisord  需要以下两个步骤

  1. /usr/bin/supervisorctl stop all  

2、ps -ef |grep supervi    kill -9 6449   kill掉端口  才能完全停止

 

supervisorctl status  查看后台运行的进程

supervisorctl restart kingshard    重载kingshard进程

 

方法2:或者使用nohup实现后台运行

nohup /usr/local/go/src/github.com/flike/kingshard/bin/kingshard --config=/usr/local/go/src/github.com/flike/kingshard/ks.yaml &

猜你喜欢

转载自blog.csdn.net/lctmei/article/details/86519817
今日推荐