工作很忙,但是邮件,qq等来咨询的人比较多,所以在这里再发一个阉割后生产的配置供大家参考
首先核心配置就三个文件server.xml,schema.xml,rule.xml,还有hsb.properties,用于对应用服务器配置
hsb的目录结构如下:
heisenberg
/bin 启动脚本所在目录
/conf classpath所在目录
默认配置文件所在 对应的hsb.properties和log4j.xml必须要在conf下
server.xml,schema.xml,rule.xml 这三个默认在下面
/lib
/logs 默认日志所在目录
startup.sh -h可以显示对应的参数
startup.sh -c 可以指定对应的配置folder,比如有几套系统,-l 可以指定输出日志目录,和之前一样
server.xml
<?xml version="1.0" encoding="UTF-8"?> <heisenberg:server xmlns:heisenberg="https://github.com/brucexx/heisenberg"> <!-- 系统参数定义,服务端口、管理端口,处理器个数、线程池等。 --> <system> <property name="serverPort">4320</property> <property name="managerPort">4321</property> <property name="initExecutor">16</property> <property name="timerExecutor">4</property> <property name="managerExecutor">4</property> <property name="processors">8</property> <property name="processorHandler">16</property> <property name="processorExecutor">16</property> <property name="clusterHeartbeatUser">_HEARTBEAT_USER_</property> <property name="clusterHeartbeatPass">_HEARTBEAT_PASS_</property> <property name="dataNodeHeartbeatPeriod">15000</property> </system> <!--用户名密码等 --> <user name="pay"> <property name="password">brucexx</property> <property name="schemas">wms_shard</property> </user> <!-- <user name="pay"> <property name="needEncrypt">true</property> <property name="password">lTrRlcGA0jOuucx8z4pCKj1Qg4GuqQNj2FDT2x9B4P4TEO/O5kj9TxPgzT2JgqY6jo8XsVSvzVqZ4W5DJc1gCA==</property> <property name="schemas">wms_shard</property> </user> --> </heisenberg:server>
其实加密密码是动态的,大家可根据自己的安全级别来设定,但是要指定hsb.properties里的公钥
publicKey=xxxxx
大家如果要使用,可以下载源码 查看EncryptGen这个文件去生成对应的密文,加密方法RSA 位数512,至于如何生成对应的密钥对,我这里就不说了
schema.xml
<?xml version="1.0" encoding="UTF-8"?> <heisenberg:schema xmlns:heisenberg="https://github.com/brucexx/heisenberg"> <schema name="wms_shard"> <table name="t_asset_deal_type" dataNode="wmsDN$0-99" rule="rule1" /> <table name="t_supplier_account_info" dataNode="wmsDN$0-99" rule="rule1" /> <table name="t_user_account_info" dataNode="wmsDN$0-99" rule="rule1" /> <table name="t_user_bank_sign_request_info" dataNode="wmsDN$0-99" rule="rule2" /> <table name="t_user_bind_bank_info" dataNode="wmsDN$0-99" rule="rule1" /> <table name="t_user_fund_sign_request_info" dataNode="wmsDN$0-99" rule="rule2" /> <table name="t_user_id_map" dataNode="wmsDN$0-99" rule="rule3" /> <table name="t_user_investment_info" dataNode="wmsDN$0-99" rule="rule4" /> <table name="t_cert_info_upload_log" dataNode="wmsDN_Single" rule="rule5" /> <table name="t_cert_file_upload_summary_info" dataNode="wmsDN_Single" rule="rule6" /> <table name="t_user_bind_card_replace_info" dataNode="wmsDN_Single" rule="rule7" /> <table name="t_province_city_info" dataNode="wmsDN_Single" rule="rule7" /> </schema> <dataNode name="wmsDN"> <property name="dataSource"> <dataSourceRef>wmsDS$0-99</dataSourceRef> </property> <property name="poolSize">256</property> <property name="heartbeatSQL">select user()</property> </dataNode> <dataSource name="wmsDS" type="mysql"> <property name="location"> <location>127.0.0.1:5506/wms_db_$00-99</location> </property> <property name="user">work_pay</property> <property name="password">123456</property> </dataSource> <!-- 单库的 --> <dataNode name="wmsDN_Single"> <property name="dataSource"> <dataSourceRef>wmsDS_Single</dataSourceRef> </property> <property name="poolSize">256</property> <property name="heartbeatSQL">select user()</property> </dataNode> <dataSource name="wmsDS_Single" type="mysql"> <property name="location"> <location>127.0.0.1:5506/wms_db</location> </property> <property name="user">work_pay</property> <property name="password">123456</property> </dataSource> </heisenberg:schema>
里面的密码也是支持加密的,和server.xml里一样,加个neeEncrypt,这里不再累述
rule.xml
<?xml version="1.0" encoding="UTF-8"?> <rule> <tableRule name="rule1"> <columns>F_USER_ID</columns> <dbRuleList> <dbRule><![CDATA[ #set($sub_str=$F_USER_ID%1000+"") $!stringUtil.substring($stringUtil.alignRights($sub_str,3,"0"),0,2)]]> </dbRule> </dbRuleList> <tbRuleList> <tbRule><![CDATA[ #set($sub_str=$F_USER_ID%1000+"") #set($sub_str=$stringUtil.alignRights($sub_str,3,"0")) #set($db_flag=$stringUtil.substring($sub_str,0,2)) #set($tb_flag=$stringUtil.substring($sub_str,2)) #set($prefix="_"+$db_flag+"_"+$tb_flag)## $!prefix]]> </tbRule> </tbRuleList> <tbPrefix> <![CDATA[ def map = [:]; for (int i=0; i<100; i++) { def list = []; for (int j=0; j<10; j++) { def k=i<10?"0"+i:i; list.add("_"+k+"_"+j); } map.put(i,list); }; return map; ]]> </tbPrefix> </tableRule> <tableRule name="rule2"> <columns>F_APPLICATION_NO</columns> <dbRuleList> <dbRule><![CDATA[ $!stringUtil.substring($F_APPLICATION_NO,-3,-1)]]> </dbRule> </dbRuleList> <tbRuleList> <tbRule><![CDATA[ #set($db_flag=$!stringUtil.substring($F_APPLICATION_NO,-3,-1)) #set($tb_flag=$!stringUtil.substring($F_APPLICATION_NO,-1)) #set($prefix="_"+$db_flag+"_"+$tb_flag)## $!prefix]]> </tbRule> </tbRuleList> <tbPrefix> <![CDATA[ def map = [:]; for (int i=0; i<100; i++) { def list = []; for (int j=0; j<10; j++) { def k=i<10?"0"+i:i; list.add("_"+k+"_"+j); } map.put(i,list); }; return map; ]]> </tbPrefix> </tableRule> <tableRule name="rule3"> <columns>F_UID</columns> <dbRuleList> <dbRule><![CDATA[ #set($sub_str=$F_UID%1000+"") $!stringUtil.substring($stringUtil.alignRights($sub_str,3,"0"),0,2)]]> </dbRule> </dbRuleList> <tbRuleList> <tbRule><![CDATA[ #set($sub_str=$F_UID%1000+"") #set($sub_str=$stringUtil.alignRights($sub_str,3,"0")) #set($db_flag=$stringUtil.substring($sub_str,0,2)) #set($tb_flag=$stringUtil.substring($sub_str,2)) #set($prefix="_"+$db_flag+"_"+$tb_flag)## $!prefix]]> </tbRule> </tbRuleList> <tbPrefix> <![CDATA[ def map = [:]; for (int i=0; i<100; i++) { def list = []; for (int j=0; j<10; j++) { def k=i<10?"0"+i:i; list.add("_"+k+"_"+j); } map.put(i,list); }; return map; ]]> </tbPrefix> </tableRule> <tableRule name="rule4"> <columns>F_CERTIFICATE_CODE</columns> <dbRuleList> <dbRule><![CDATA[ #set($db_flag=$!stringUtil.crc32($F_CERTIFICATE_CODE)) $!stringUtil.substring($db_flag,-3,-1)]]> </dbRule> </dbRuleList> <tbRuleList> <tbRule><![CDATA[ #set($sub_str=$!stringUtil.crc32($F_CERTIFICATE_CODE)) #set($db_flag=$!stringUtil.substring($sub_str,-3,-1)) #set($tb_flag=$!stringUtil.substring($sub_str,-1)) #set($prefix="_"+$db_flag+"_"+$tb_flag)## $!prefix]]> </tbRule> </tbRuleList> <tbPrefix> <![CDATA[ def map = [:]; for (int i=0; i<100; i++) { def list = []; for (int j=0; j<10; j++) { def k=i<10?"0"+i:i; list.add("_"+k+"_"+j); } map.put(i,list); }; return map; ]]> </tbPrefix> </tableRule> <tableRule name="rule5"> <columns>F_SP_ID</columns> <dbRuleList> <dbRule><![CDATA[0]]> </dbRule> </dbRuleList> <tbRuleList> <tbRule><![CDATA[ #set($tb_flag=$F_SP_ID+"") #set($prefix="_"+$tb_flag)## $!prefix]]> </tbRule> </tbRuleList> <tbPrefix> <![CDATA[ def map = [:]; def list = []; for (int i=0; i<100; i++) { list.add("_"+i); }; map.put(0,list); return map; ]]> </tbPrefix> </tableRule> <tableRule name="rule6"> <columns>F_USER_ID</columns> <dbRuleList> <dbRule><![CDATA[ #set($sub_str=$F_USER_ID%1000+"") $!stringUtil.substring($stringUtil.alignRights($sub_str,3,"0"),0,2)]]> </dbRule> </dbRuleList> <tbRuleList> <tbRule><![CDATA[$!prefix]]> </tbRule> </tbRuleList> <tbPrefix> </tbPrefix> </tableRule> <tableRule name="rule7"> <columns>F_FAKE_PARTITION_ID</columns> <dbRuleList> <dbRule><![CDATA[ #set($sub_str=$F_FAKE_PARTITION_ID%1000+"") $!stringUtil.substring($stringUtil.alignRights($sub_str,3,"0"),0,2)]]> </dbRule> </dbRuleList> <tbRuleList> <tbRule><![CDATA[$!prefix]]> </tbRule> </tbRuleList> <tbPrefix> </tbPrefix> </tableRule> </rule>
大家对号入坐,自己看
然后一个表里有多个字段想命中,
<tableRule name="rule1" forceHit="true"> <columns>F_TRANS_ID,F_BUYER_USER_ID</columns> <dbRuleList> <dbRule><![CDATA[$!stringUtil.substring($F_TRANS_ID,-3,-1)]]></dbRule> <dbRule><![CDATA[ #set($sub_str=$F_BUYER_USER_ID%1000+"") $!stringUtil.substring($stringUtil.alignRights($sub_str,3,"0"),0,2)]]> </dbRule> </dbRuleList> <tbRuleList> <tbRule><![CDATA[ #set($db_flag=$!stringUtil.substring($F_TRANS_ID,-3,-1)) #set($tb_flag=$!stringUtil.substring($F_TRANS_ID,-1)) #set($prefix="_"+$db_flag+"_"+$tb_flag)## $!prefix]]> </tbRule> <tbRule><![CDATA[ #set($sub_str=$F_BUYER_USER_ID%1000+"") #set($sub_str=$stringUtil.alignRights($sub_str,3,"0")) #set($db_flag=$stringUtil.substring($sub_str,0,2)) #set($tb_flag=$stringUtil.substring($sub_str,2)) #set($prefix="_"+$db_flag+"_"+$tb_flag)## $!prefix]]> </tbRule> </tbRuleList> <tbPrefix> <![CDATA[ def map = [:]; for (int i=0; i<100; i++) { def list = []; for (int j=0; j<10; j++) { def k=i<10?"0"+i:i; list.add("_"+k+"_"+j); } map.put(i,list); }; return map; ]]> </tbPrefix> </tableRule>
时间: 2024-10-28 20:28:09