mycat 自带了一个简单的监控工具 mycat eye(自带了 jetty 的一个web 应用)。可以支持 mycat 环境参数、mycat 运行状态、 mysql 同步状态、高瓶 sql 等数据的实时查询。相对于mycat server来说,mycat web 发展的非常缓慢,目前可以定义为是mycat运行情况的辅助查询工具,可以替代少数 9066 管理端口做的事务。
mycat web 使用了 zookeeper 命名服务功能,把相关的mycat 配置信息存放到 zk 一部分,另一部分存放在mycat web本地的sql lite中,估计是当初设计不充分~~~
mycat web 下载地址
github 入口
另外有四个相对重要的文件
文件 | 用处 |
---|---|
mycat_home\bin\xml_to_yaml.sh | 根据mycat配置生成 zookeeper yaml 配置工具 |
mycat_home\bin\init_zk_data.sh | 将生成的yaml配置文件导入远程zookeeper |
mycat_home\conf\myid.properties | zookeeper 路径配置参数信息 |
mycat_home\conf\zk-create.yaml | 自动生成的zk配置 |
安装顺序
1)确认安装好zookeeper 环境(此步略,网上教程一大把)。
2)启动mycat服务,确认本地服务一切正常。
3)执行xml_to_yaml.sh脚本(确认本地配置过 JAVA_HOME 和 MYCAT_HOME环境变量,没有的话参考下文)
/etc/profile配置
export JAVA_HOME=/usr/java/jdk1.7.0_79/
export CLASSPATH=.:%JAVA_HOME%/lib/dt.jar:%JAVA_HOME%/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
export MYCAT_HOME=/usr/local/mycat/mycat-server-1.5/
4)查看yaml配置是否正确(基本看不出问题,因为配置有点重杂了~~)
zkURL: 127.0.0.1:2181
mycat-mysqlgroup:
host_183:
name: host_183
repType: '0'
zone: fz
servers:
- host_183
cur-write-server: host_183
auto-write-switch: true
heartbeatSQL: select user()
host_185:
name: host_185
repType: '0'
zone: fz
servers:
- host_185
cur-write-server: host_185
auto-write-switch: true
heartbeatSQL: select user()
mycat-mysqls:
host_183:
name: host_183
ip: 192.168.13.191
port: '3307'
user: root
password: root123
hostId: host
zone: fz
host_185:
name: host_185
ip: 192.168.13.185
port: '3307'
user: root
password: root123
hostId: host
zone: fz
mycat-cluster:
mycat-cluster-1:
user:
test:
name: test
password: test
schemas:
- TESTDB
user:
name: user
password: user
schemas:
- TESTDB
readOnly: 'true'
rule:
sharding-by-date:
name: partbymonth
functionName: org.opencloudb.route.function.PartitionByMonth
column: date_str
dateFormat: yyyy-MM-dd
sBeginDate: '2015-01-01'
rule1:
name: func1
functionName: org.opencloudb.route.function.PartitionByLong
column: id
partitionCount: '8'
partitionLength: '128'
rule2:
name: func1
functionName: org.opencloudb.route.function.PartitionByLong
column: user_id
partitionCount: '8'
partitionLength: '128'
sharding-by-intfile:
name: hash-int
functionName: org.opencloudb.route.function.PartitionByFileMap
column: sharding_id
config:
'10000': '0'
'10010': '1'
auto-sharding-long:
name: rang-long
functionName: org.opencloudb.route.function.AutoPartitionByLong
column: id
config:
0-500M: '0'
500M-1000M: '1'
1000M-1500M: '2'
mod-long-userId:
name: mod-long
functionName: org.opencloudb.route.function.PartitionByMod
column: user_id
count: '3'
mod-long:
name: mod-long
functionName: org.opencloudb.route.function.PartitionByMod
column: id
count: '3'
sharding-by-murmur:
name: murmur
functionName: org.opencloudb.route.function.PartitionByMurmurHash
column: id
seed: '0'
count: '2'
virtualBucketTimes: '160'
sharding-by-month:
name: partbymonth
functionName: org.opencloudb.route.function.PartitionByMonth
column: create_date
dateFormat: yyyy-MM-dd
sBeginDate: '2015-01-01'
latest-month-calldate:
name: latestMonth
functionName: org.opencloudb.route.function.LatestMonthPartion
column: calldate
splitOneDay: '24'
auto-sharding-rang-mod:
name: rang-mod
functionName: org.opencloudb.route.function.PartitionByRangeMod
column: id
config:
0-200M: '5'
200M1-400M: '1'
400M1-600M: '4'
600M1-800M: '4'
800M1-1000M: '6'
jch:
name: jump-consistent-hash
functionName: org.opencloudb.route.function.PartitionByJumpConsistentHash
column: id
totalBuckets: '3'
mod-sharding-long:
name: mod-long
functionName: org.opencloudb.route.function.PartitionByMod
column: sharding_mod_id
count: '3'
schema:
TESTDB:
name: TESTDB
checkSQLSchema: true
defaultMaxLimit: 100
new_table:
name: new_table
datanode: dn1,dn2,dn3,dn4,dn5,dn6,dn7,dn8,dn9,dn10,dn11,dn12
ruleName: sharding-by-date
t_user:
name: t_user
datanode: dn1,dn2,dn3
ruleName: mod-long-userId
t_order:
name: t_order
datanode: dn1,dn2,dn3
ruleName: mod-long-userId
t_order_fee:
name: t_order_fee
datanode: dn1,dn2,dn3
ruleName: mod-long-userId
datanode:
dn1:
name: dn1
database: ds1
dataHost: '13_183'
dn2:
name: dn2
database: ds2
dataHost: '13_183'
dn3:
name: dn3
database: ds3
dataHost: '13_183'
dn4:
name: dn4
database: ds4
dataHost: '13_183'
dn5:
name: dn5
database: ds5
dataHost: '13_183'
dn6:
name: dn6
database: ds6
dataHost: '13_183'
dn7:
name: dn7
database: ds7
dataHost: '13_183'
dn8:
name: dn8
database: ds8
dataHost: '13_183'
dn9:
name: dn9
database: ds9
dataHost: '13_183'
dn10:
name: dn10
database: ds10
dataHost: '13_183'
dn11:
name: dn11
database: ds11
dataHost: '13_185'
dn12:
name: dn12
database: ds12
dataHost: '13_185'
datahost:
'13_183':
name: '13_183'
balance: 0
maxcon: 1000
mincon: 10
dbtype: mysql
dbDriver: native
writeType: 0
switchType: 1
slaveThreshold: 100
heartbeatSQL: select user()
mysqlGroup: host_183
'13_185':
name: '13_185'
balance: 0
maxcon: 1000
mincon: 10
dbtype: mysql
dbDriver: native
writeType: 0
switchType: 1
slaveThreshold: 100
heartbeatSQL: select user()
mysqlGroup: host_185
mycat-nodes:
mycat_fz_01:
name: mycat_fz_01
cluster: mycat-cluster-1
systemParams:
defaultSqlParser: druidparser
5 ) 执行 init_zk_data.sh 脚本 , 注意下默认情况下脚本会将zookeeper定位在同一台服务器上面,如有需要可以调整下 ZK 的 IP : PORT
demo.catlets.ZkCreate
public static void main(String[] args) {
String url;
if (args != null && args.length > 0) {
ZK_CONFIG_FILE_NAME = args[0];
url = args[1];
} else {
url = zkConfig.containsKey(CONFIG_URL_KEY) ?
(String) zkConfig.get(CONFIG_URL_KEY) :
"127.0.0.1:2181"; ----- 这里居然写死掉了 ^=^
}
zkConfig = loadZkConfig();
framework = createConnection(url);
createConfig(MYCAT_HOST_KEY, false, MYCAT_HOST_KEY);
createConfig(MYCAT_ZONE_KEY, false, MYCAT_ZONE_KEY);
createConfig(MYCAT_NODES_KEY, false, MYCAT_NODES_KEY);
createConfig(MYCAT_CLUSTER_KEY, true, MYCAT_CLUSTER_KEY);
createConfig(MYCAT_MYSQLS_KEY, true, MYCAT_MYSQLS_KEY);
createConfig(MYCAT_MYSQL_GROUP_KEY, true, MYCAT_MYSQL_GROUP_KEY);
createConfig(MYCAT_LBS, true, MYCAT_LBS);
}
6 ) 配置 mycat-web 中 zk 的地址
/usr/local/mycat/mycat-web/mycat-web/WEB-INF/classes
#
#Mon Jan 16 15:37:36 CST 2012
show.period=3000000
zookeeper=192.168.13.185:2181
##sql\u4E0A\u7EBF\u76F8\u5173\u914D\u7F6E
sqlonline.server=192.168.13.187
sqlonline.user=root
sqlonline.passwd=123456
7 ) 启动 mycat web ,这里为了方便查询日志就直接通脚本启动
java -Xms1024m -Xmx1024m -Xmn128m -XX:PermSize=64m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0 -XX:CMSInitiatingOccupancyFraction=70 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar start.jar
为了看下mycat web的效果,压了100万条记录,可以比较真观的看到所有SQL的执行情况和较慢的SQL的运行时长,不能算是太鸡肋吧,但要全面运维一个服务来说,mycat web 还有比较长的路需要走。
OK,今天就先到这里~~