KingShard 中间件分表

Dockerfile

$ vim Dockfile
FROM golang:1.15-alpine3.12 as builder

ARG goproxy

COPY . /go/src/github.com/flike/kingshard
RUN cd /go/src/github.com/flike/kingshard \
  && GO111MODULE=off GOPROXY=$goproxy GOOS=linux CGO_ENABLED=0 go install -v ./vendor/golang.org/x/tools/cmd/goyacc \
  && /go/bin/goyacc -o ./sqlparser/sql.go ./sqlparser/sql.y \
  && GO111MODULE=off GOPROXY=$goproxy GOOS=linux CGO_ENABLED=0 go install -v ./cmd/kingshard

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
  && apk --update add --no-cache tzdata git

FROM scratch

COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /etc/passwd /etc/
COPY --from=builder /go/bin/kingshard /bin/

WORKDIR /

# server listen addr
EXPOSE 3306
# the web api server
EXPOSE 9797

USER nobody

ENTRYPOINT ["/bin/kingshard"]

构建镜像

$  git clone -b 1.6 https://github.com/flike/kingshard.git

$ docker build . \
  --force-rm \
  --build-arg goproxy=https://goproxy.io \
   -t kingshard:1.6

KingShard 配置文件

$ vim ks.yaml
# server listen addr
addr : 0.0.0.0:3306

# prometheus server listen addr
#prometheus_addr : 0.0.0.0:7080

# server user and password
user_list:
  -
    user :  root
    password : 123456

# the web api server
web_addr : 0.0.0.0:9797
#HTTP Basic Auth
web_user : admin
web_password : admin

# 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 : /Users/flike/log

# 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
# support ip and ip segment
#allow_ips : 127.0.0.1,192.168.15.0/24

# the charset of kingshard, if you don't set this item
# the default charset of kingshard is utf8.
#proxy_charset: utf8

# node is an agenda for real remote mysql server.
nodes :
  -
    name : node1

    # default max conns for mysql server
    max_conns_limit : 200

    # all mysql in a node must have the same user and password
    user :  root
    password : 123456

    # master represents a real mysql master server
    master: 192.168.2.115:3306

    # slave represents a real mysql salve server
    slave:

    # slave represents a real mysql salve server,and the number after '@' is
    # read load weight of this slave.
    #slave : 192.168.59.101:3307@2,192.168.59.101:3307@3
    down_after_noalive : 32

# schema defines sharding rules, the db is the sharding table database.
schema_list :
  -
    user: root
    nodes: [node1]
    default: node1
    shard:
      -
        db : demo
        table: demo_table
        key: sound_id
        nodes: [node1]
        # https://github.com/doumadou/kingshard/blob/master/doc/KingDoc/kingshard_sharding_introduce.md
        type: hash
        locations: [4]

运行 KingShard

$ docker run --rm -it -p 3306:3306 -p 9797:9797 -v $PWD/ks.yaml:/etc/ks.yaml kingshard:1.6

参考

  • https://github.com/flike/kingshard.git
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈挨踢

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值