mycat 单机安装

安装mycat

cd /usr/local

mkdir mycat 

chmod 0777 mycat

 cp Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz /usr/local/mycat

 tar -zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz 

cd mycat



配置mycat:



schema.xml

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">


        <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
                <!-- auto sharding by id (long) -->
                <table name="file_data_lct_1" dataNode="dn1,dn2" primaryKey="id"  rule="sharding-by-murmur" autoIncrement="true" needAddLimit="true"/>
                <table name="mycat_sequence" primaryKey="name" dataNode="dn1" />
        </schema>


        <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743"
                /> -->
        <dataNode name="dn1" dataHost="localhost1" database="resource" />
        <dataNode name="dn2" dataHost="localhost2" database="crmdktest2"/>


        <dataHost name="localhost1" maxCon="1000" minCon="10" balance="3"
                           writeType="0"   dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
                <heartbeat>select user()</heartbeat>
                <!-- can have multi write hosts -->
                <writeHost host="hostM1" url="10.100.19.210:3306" user="public"
                                   password="123456">
                        <readHost host="hostS1" url="10.100.19.210:3306" user="public" password="123456" />
                        <readHost host="hostS2" url="10.100.19.210:3306" user="public" password="123456" />
                        <readHost host="hostS3" url="10.100.19.210:3306" user="public" password="123456" />

                </writeHost>

                <writeHost host="hostM2" url="10.100.19.210:3306" user="public"
                           password="123456">
                        <readHost host="hostS4" url="10.100.19.210:3306" user="public" password="123456" />
                </writeHost>
        </dataHost>


          <dataHost name="localhost2" maxCon="1000" minCon="10" balance="3"
                           writeType="0"   dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
                <heartbeat>select user()</heartbeat>
                
                <!-- can have multi write hosts -->
                <writeHost host="hostM3" url="10.100.13.238:3306" user="crmdk_admin"
                                   password="crmdkadmin123!@#">
                        <readHost host="hostS5" url="10.100.13.238:3306" user="crmdk_admin" password="crmdkadmin123!@#" />


                </writeHost>


        </dataHost>

</mycat:schema>


rule.xml


修改tableRule

1修改columns为具体的分片字段名。

<tableRule name="sharding-by-murmur">
                <rule>
                        <columns>main_id</columns>
                        <algorithm>murmur</algorithm>
                </rule>

</tableRule>


2 修改属性count 为具体的分片个数。

 <function name="murmur"
                class="io.mycat.route.function.PartitionByMurmurHash">
                <property name="seed">0</property><!-- 默认是0 -->
                <property name="count">2</property><!-- 要分片的数据库节点数量,必须指定,否则没法分片 -->
                <property name="virtualBucketTimes">160</property><!-- 一个实际的数据库节点被映射为这么多虚拟节点,默认是160倍,也就是虚拟节点数是物理节点数的160倍 -->
                <!-- <property name="weightMapFile">weightMapFile</property> 节点的权重,没有指定权重的节点默认是1。以properties文件的格式填写,以从0开始到count-1的整数值也就是节点索引为key,以节点权重值为值。所有权重值必须是正整数,否则以1代替 -->
                <!-- <property name="bucketMapPath">/etc/mycat/bucketMapPath</property> 
                        用于测试时观察各物理节点与虚拟节点的分布情况,如果指定了这个属性,会把虚拟节点的murmur hash值与物理节点的映射按行输出到这个文件,没有默认值,如果不指定,就不会输出任何东西 -->
</function>



3 设置全局序列号。



然后进入bin 目录 ./mycat start 就可以启动mycat了。

通过命令登陆服务器:
mysql -h127.0.0.1 -utest -ptest -DTESTDB -P8066

插入数据


insert into `file_data_lct_1`(
old_name,
file_type,
file_size,
file_dir,
file_name,
is_picture,
is_delete,
delete_uid,
delete_time,
main_id,
sub_id,
host_port,
sort,
create_token_time,
middle_file_name,
small_file_name,
create_time
)
VALUES ( '1213123', '', '0', '', '', '0', '0', '0', null, '0', '100', '0', '', '0', '0', '', '');



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值