配置my.cnf
修改mycat/conf/server.xml文件,具体修改如下在底部对应部分加上
<user name="root">
<property name="password">root</property>
<property name="schemas">TESTDB</property>
<!-- 表级 DML 权限设置 -->
<!--
<privileges check="false">
<schema name="TESTDB" dml="0110" >
<table name="tb01" dml="0000"></table>
<table name="tb02" dml="1111"></table>
</schema>
</privileges>
-->
</user>
<user name="user">
<property name="password">root</property>
<property name="schemas">TESTDB</property>
<property name="readOnly">true</property>
</user>
修改mycat/conf/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">
<table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" />
<table name="company" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" />
<table name="goods" primaryKey="ID" type="global" dataNode="dn1,dn2" />
<!-- random sharding using mod sharind rule -->
<table name="hotnews" primaryKey="ID" dataNode="dn1,dn2,dn3"
rule="mod-long" />
<!-- <table name="dual" primaryKey="ID" dataNode="dnx,dnoracle2" type="global"
rule="mod-long" /> -->
<table name="employee" primaryKey="ID" dataNode="dn1,dn2"
rule="sharding-by-intfile" />
<table name="customer" primaryKey="ID" dataNode="dn1,dn2"
rule="sharding-by-intfile">
<childTable name="orders" primaryKey="ID" joinKey="customer_id"
parentKey="id">
<childTable name="order_items" joinKey="order_id"
parentKey="id" />
</childTable>
<childTable name="customer_addr" primaryKey="ID" joinKey="customer_id"
parentKey="id" />
</table>
<!-- <table name="oc_call" primaryKey="ID" dataNode="dn1$0-743" rule="latest-month-calldate"
/> -->
</schema>
<!-- <dataNode name="dn1$0-743" dataHost="master" database="db$0-743"
/> -->
<dataNode name="dn1" dataHost="master" database="db1" />
<dataNode name="dn2" dataHost="master" database="db2" />
<dataNode name="dn3" dataHost="master" database="db3" />
<dataHost name="master" maxCon="1000" minCon="10" balance="2"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="173.16.80.70:3307" user="root"
password="root">
<!-- can have multi read hosts -->
</writeHost>
<writeHost host="host1M1" url="173.16.80.70:3305" user="root"
password="root"/>
<writeHost host="host2M1" url="173.16.80.104:3307" user="root"
password="root">
<!-- can have multi read hosts -->
</writeHost>
<writeHost host="host3M1" url="173.16.80.104:3305" user="root"
password="root"/>
<!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
</dataHost>
</mycat:schema>
修改mycat/conf/wrapper.conf文件,具体修改如下
[html] view plain copy
- 找到wrapper.java.command=java 将其改为wrapper.java.command=%JAVA_HOME%/bin/java
sudo yum install haproxy
一般在/etc/haproxy
编辑配置文件 sudo vi haproxy.cfg
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user root
group root
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
defaults
log global
mode http
option http-keep-alive
option httplog
timeout connect 5000ms
timeout client 10000ms
timeout server 50000ms
timeout http-request 20000ms
balance roundrobin
listen stats
mode http
log 127.0.0.1 local0 err
bind 0.0.0.0:1088
stats enable
stats hide-version
stats uri /stats
stats refresh 30s
stats auth admin:admin
stats admin if TRUE
listen tomcat
bind 0.0.0.0:5222
mode http
maxconn 300
log 127.0.0.1 local0 debug
balance roundrobin
server static1 173.16.80.104:3020 check inter 2000 fall 3 weight 30
server static2 173.16.80.70:8090 check inter 2000 fall 3 weight 30
/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
1191330156@qq.com
}
notification_email_from chenwb #配置发件人
smtp_server 127.0.0.1 #配置邮件服务器
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_haproxy {
script"/etc/keepalived/chk_haproxy.sh"
interval 1
weight -10
#fall 3
}
vrrp_instance VI_1 {
state MASTER #BACKUP配置模式
interface ens33
virtual_router_id 55
priority 100#优先级
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
173.16.80.247#虚拟IP地址
}
track_script {
chk_haproxy
}
}