kingshard實踐02-實現(xiàn)讀寫分離

安裝kingshard

1. 安裝Go語言環(huán)境(請使用最新版),具體步驟請Google。
    2. git clone https://github.com/flike/kingshard.git $GOPATH/src/github.com/flike/kingshard
    3. cd src/github.com/flike/kingshard
    4. source ./dev.sh
    5. make
    6. 設(shè)置配置文件
    7. 運(yùn)行kingshard。./bin/kingshard -config=etc/ks.yaml

修改kingshard/etc/unshard.yaml配置,修改master和slave和log_path

# 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 : kingshard

    # master represents a real mysql master server
    master : 127.0.0.1:3307 # 主

    # slave represents a real mysql salve server,and the number after '@' is
    # read load weight of this slave.
    slave : 127.0.0.1:3308 # 主
    #down_after_noalive : 32

運(yùn)行kingshard

mysql -h127.0.0.1 -ukingshard -pkingshard -P9696;

執(zhí)行sql,查看log,已實現(xiàn)讀寫分離

?  log git:(master) ? tail -f sql.log
2019/03/04 17:50:42 - OK - 26.2ms - 127.0.0.1:56193->127.0.0.1:3308:show databases
2019/03/04 17:50:42 - OK - 5.5ms - 127.0.0.1:56193->127.0.0.1:3308:show tables
2019/03/04 17:51:03 - OK - 3.9ms - 127.0.0.1:56193->127.0.0.1:3308:select * from user
2019/03/04 17:52:08 - OK - 6.7ms - 127.0.0.1:56193->127.0.0.1:3307:insert into user(id,age,name) values(2,10,"zhangsan")
2019/03/04 17:52:47 - OK - 4.7ms - 127.0.0.1:56193->127.0.0.1:3308:select * from user where id = 2
2019/03/04 17:59:27 - OK - 6.4ms - 127.0.0.1:56193->127.0.0.1:3307:update user set age = 18 where id = 2
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容