MySQL Middleware Kingshard installation

Source: Internet
Author: User
Tags install go mysql in git clone

1, install Go language environment, (go version requires more than 1.3)

wget https://storage.googleapis.com/golang/go1.6.3.linux-amd64.tar.gz

Tar-c/usr/local/-xzf go1.6.3.linux-amd64.tar.gz

Configure the environment variables to include the following settings in/etc/profile:

Export Goroot=/usr/local/go

Export path= $GOROOT/bin: $PATH

Create the workspace/usr/local/go/work (your own directory) and add the following settings to the/etc/profile:

Export Gopath=/usr/local/go/work

2, install Git

Yum install-y git


3, install Kingshard

git clone https://github.com/flike/kingshard.git Src/github.com/flike/kingshard

CD Src/github.com/flike/kingshard

source./dev.sh

Make


4, setting the configuration file

The ETC directory has two profile templates, corresponding to Shard and non-shard versions, which can be freely selected on demand.

Cat Unshard.yaml

addr:0.0.0.0:9696

User:kingshard

Password:kingshard

Log_level:warn


Nodes:

-

Name:node1

Max_conns_limit:32

User:kingshard

Password:kingshard


master:172.31.18.104:3306

Slave:172.31.18.105:[email Protected],172.31.38.150:[email protected]

Down_after_noalive:32


Schema:

Db:kingshard

Nodes: [Node1]

Default:node1

Shard

-


5, the user authorization according to the settings in the configuration file

GRANT all privileges on * * to ' kingshard ' @ ' 172.31.38.151 ' identified by ' Kingshard ';



7. Run Kingshard.

./bin/kingshard-config=etc/unshard.yaml

Ps-ef | grep Kingshard

Root 6942 26963 0 02:44 pts/2 00:00:00./bin/kingshard-config=etc/unshard.yaml



8. Configuration file Parameter description

# Kingshard Address and Port

addr:0.0.0.0:9696


# Connect Kingshard user name and password

User:kingshard

Password:kingshard


# log level, [Debug|info|warn|error], default is Error

Log_level:debug

# Open SQL log, set to on; Turn off SQL log, set to OFF

Log_sql:on

#如果设置了该项, only SQL logs with SQL execution time exceeding slow_log_time (in milliseconds) are output and all SQL logs are output without setting

slow_log_time:100

#日志文件路径, if not configured, it is output to the terminal.

Log_path:/users/flike/log


# SQL blacklist file path

# All SQL in this file will be Kingshard refused to forward

#blacklist_sql_file:/users/flike/blacklist


# only allow the following IP list to connect to Kingshard, if not configured, do not limit the IP connection to Kingshard.

allow_ips:127.0.0.1


# Kingshard The character set used, and if this option is not set, Kingshard uses UTF8 as the default character set

#proxy_charset: UTF8MB4


A node node represents a data shard for a MySQL cluster, including a master multi-slave (can not be configured from the library)

Nodes:

-

#node节点名字

Name:node1


# The maximum number of idle connections in the connection pool, that is, a maximum of max_conns_limit connections to the back-end DB

Max_conns_limit:16


# Kingshard connect the username and password of MySQL in this node, the user name and password of master and slave must be consistent

User:kingshard

Password:kingshard


# Master's address and port

master:127.0.0.1:3306


# Slave's address, port, and read weight, followed by the read weight of the slave. Don't configure Slave

#slave: [Email protected],[email protected]

#kingshard在300秒内都连接不上mysql, Kingshard will be offline for the MySQL

down_after_noalive:300

-

Name:node2

Max_conns_limit:16

User:kingshard

Password:kingshard


master:192.168.59.103:3307

Slave:

down_after_noalive:100


# Rules of the table

Schema:

#分表使用的db, all the sub-tables must be in this db, the DB is used by default if no database is specified when the KS is connected.

Db:kingshard

#分表分布的node名字

Nodes: [Node1,node2]

#所有未分表的SQL, it will be sent to the default node.

Default:node1

Shard

-

#分表名字

Table:test_shard_hash

#分表字段

Key:id

#分表分布的node

Nodes: [Node1, Node2]

#分表类型

Type:hash

#子表个数分布, indicating that Node1 has 4 sub-tables,

#node2有4个子表.

Locations: [+]


-

#分表名字

Table:test_shard_range

#分表字段

Key:id

#分表类型

Type:range

#分表分布的node

Nodes: [Node1, Node2]

#子表个数分布, indicating that Node1 has 4 sub-tables,

#node2有4个子表.

Locations: [+]

#表示每个子表包含的最大记录数, which means that every

#个子表最多包好10000条记录. That is, the child table 1 corresponds to the ID [0,10000), the child table 2[10000,20000) ....

table_row_limit:10000



Kingshard uses the YAML parsing configuration file, it is important to note that the YAML configuration file does not allow the TAB key, and that a space followed by a colon is required. After the configuration file has been written, you can verify the format error on the YAML Lint Web site


Reference: HTTPS://GITHUB.COM/FLIKE/KINGSHARD/BLOB/MASTER/DOC/KINGDOC/KINGSHARD_INSTALL_DOCUMENT.MD

MySQL Middleware Kingshard installation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.