#############脚本#####################
#!/bin/bash
####此脚本分片数量为2!! ###修改schema配置文件 cat > /usr/local/mycat/conf/ schema.xml <<EOF <?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="oldliu" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
####取模分片 <table name="t4" dataNode="dn1,dn2" rule="mod-long" /> </schema> <dataNode name="dn1" dataHost="localhost1" database="taobao" /> <dataNode name="dn2" dataHost="localhost2" database="taobao" />
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1" > <heartbeat>select user()</heartbeat> <writeHost host="mysql7" url="192.168.100.10:3307" user="root" password="123"> <readHost host="mysql9" url="192.168.100.10:3309" user="root" password="123"/> </writeHost> <writeHost host="mysql17" url="192.168.100.15:3307" user="root" password="123"> <readHost host="mysql19" url="192.168.100.15:3309" user="root" password="123"/> </writeHost> </dataHost> <dataHost name="localhost2" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1" > <heartbeat>select user()</heartbeat> <writeHost host="mysql8" url="192.168.100.10:3308" user="root" password="123"> <readHost host="mysql10" url="192.168.100.10:3310" user="root" password="123"/> </writeHost> <writeHost host="mysql18" url="192.168.100.15:3308" user="root" password="123"> <readHost host="mysql20" url="192.168.100.15:3310" user="root" password="123"/> </writeHost> </dataHost> </mycat:schema> EOF ###修改rule配置文件 ###节点数量 data-nodes=2 sed -i '/<!-- how many data nodes -->/,/<\/function>/ s/[0-9]/$data-nodes/'
/usr/local/mycat/conf/rule.xml
mycat start netstat -nplt | grep -o "[0-9]\{2\}66" > /dev/null if [[ $? -eq 0 ]] then echo -e "\033[32m成功\033[0m" else echo -e "\033[31m失败,请检查环境后重试\033[0m" fi
相关语句解读
schema文件配置
rule配置文件
?
?检查性启动
mycat console
?可以后ctrl+c结束,采用mycat start方式启动
|