时间:2021-07-01 10:21:17 帮助过:22人阅读
保存并退出
因为我们就两个mysql节点,且分片规则使用的是:rule="mod-long",所以需要修改此文件内容,将mod-long默认的3个节点修改成2个,不然mycat无法启动。
既然启动失败,那么在后面的连接mycat的步骤会报以下错误:
ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘192.168.1.70‘ (111)
我曾在这里卡了一段时间,最终通过查看mycat的wrapper.log日志文件才找到原因的。
[root@localhost conf]# vi rule.xml
如下图:
----------------------------------------------------------------------------------
下面这段是日志文件里的错误信息,可以不看,写出来的原因是方便自己以后理解
STATUS | wrapper | 2017/08/19 20:13:36 | TERM trapped. Shutting down. STATUS | wrapper | 2017/08/19 20:13:37 | <-- Wrapper Stopped STATUS | wrapper | 2017/08/19 20:13:41 | --> Wrapper Started as Daemon STATUS | wrapper | 2017/08/19 20:13:41 | Launching a JVM... INFO | jvm 1 | 2017/08/19 20:13:41 | Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=64M; support was removed in 8.0 INFO | jvm 1 | 2017/08/19 20:13:41 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org INFO | jvm 1 | 2017/08/19 20:13:41 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved. INFO | jvm 1 | 2017/08/19 20:13:41 | INFO | jvm 1 | 2017/08/19 20:13:42 | INFO | jvm 1 | 2017/08/19 20:13:42 | WrapperSimpleApp: Encountered an error running main: java.lang.ExceptionInInitializerError INFO | jvm 1 | 2017/08/19 20:13:42 | java.lang.ExceptionInInitializerError INFO | jvm 1 | 2017/08/19 20:13:42 | at io.mycat.MycatStartup.main(MycatStartup.java:53) INFO | jvm 1 | 2017/08/19 20:13:42 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) INFO | jvm 1 | 2017/08/19 20:13:42 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) INFO | jvm 1 | 2017/08/19 20:13:42 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) INFO | jvm 1 | 2017/08/19 20:13:42 | at java.lang.reflect.Method.invoke(Method.java:498) INFO | jvm 1 | 2017/08/19 20:13:42 | at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240) INFO | jvm 1 | 2017/08/19 20:13:42 | at java.lang.Thread.run(Thread.java:745) INFO | jvm 1 | 2017/08/19 20:13:42 | Caused by: io.mycat.config.util.ConfigException: Illegal table conf : table [ BLOG ] rule function [ mod-long ] partition size : 3 > table datanode size : 2, please make sure table datanode size = function partition size INFO | jvm 1 | 2017/08/19 20:13:42 | at io.mycat.config.loader.xml.XMLSchemaLoader.checkRuleSuitTable(XMLSchemaLoader.java:563) INFO | jvm 1 | 2017/08/19 20:13:42 | at io.mycat.config.loader.xml.XMLSchemaLoader.loadTables(XMLSchemaLoader.java:396) INFO | jvm 1 | 2017/08/19 20:13:42 | at io.mycat.config.loader.xml.XMLSchemaLoader.loadSchemas(XMLSchemaLoader.java:173) INFO | jvm 1 | 2017/08/19 20:13:42 | at io.mycat.config.loader.xml.XMLSchemaLoader.load(XMLSchemaLoader.java:122) INFO | jvm 1 | 2017/08/19 20:13:42 | at io.mycat.config.loader.xml.XMLSchemaLoader.<init>(XMLSchemaLoader.java:83) INFO | jvm 1 | 2017/08/19 20:13:42 | at io.mycat.config.loader.xml.XMLSchemaLoader.<init>(XMLSchemaLoader.java:87) INFO | jvm 1 | 2017/08/19 20:13:42 | at io.mycat.config.ConfigInitializer.<init>(ConfigInitializer.java:74) INFO | jvm 1 | 2017/08/19 20:13:42 | at io.mycat.config.MycatConfig.<init>(MycatConfig.java:72) INFO | jvm 1 | 2017/08/19 20:13:42 | at io.mycat.MycatServer.<init>(MycatServer.java:144) INFO | jvm 1 | 2017/08/19 20:13:42 | at io.mycat.MycatServer.<clinit>(MycatServer.java:96) INFO | jvm 1 | 2017/08/19 20:13:42 | ... 7 more STATUS | wrapper | 2017/08/19 20:13:44 | <-- Wrapper StoppedView Code
192.168.1.70对应的mysql服务器创建数据库:db1
[root@localhost soft]# /usr/local/mysql/bin/mysql -uroot -p123456
mysql> create database db1;
----------------------------------------------------------------------------------
192.168.1.71对应的mysql服务器创建数据库:db2
[root@localhost soft]# /usr/local/mysql/bin/mysql -uroot -p123456
mysql> create database db2;
[root@localhost ~]# mycat start
[root@localhost mycat]# /usr/local/mysql/bin/mysql -u root -p -P 8066 -h 192.168.1.70
如上图,表示逻辑数据库连接成功
说明:这里连接的就是逻辑数据库了
1、 建表
选择逻辑数据库
mysql> use TESTDB;
CREATE TABLE blog ( id int(11) NOT NULL, title varchar(20) NOT NULL, author varchar(30), PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
执行完上面的sql语句,会看到
192.168.1.70 db1下有了blog表
192.168.1.71 db2下也有了blog表
2、插入数据
insert into blog(id,title) values(1,‘test‘); insert into blog(id,title) values(2,‘test‘); insert into blog(id,title) values(3,‘test‘); insert into blog(id,title) values(4,‘test‘); insert into blog(id,title) values(5,‘test‘); insert into blog(id,title) values(6,‘test‘); insert into blog(id,title) values(7,‘test‘); insert into blog(id,title) values(8,‘test‘); insert into blog(id,title) values(9,‘test‘); insert into blog(id,title) values(10,‘test‘); insert into blog(id,title) values(11,‘test‘); insert into blog(id,title) values(12,‘test‘); insert into blog(id,title) values(13,‘test‘); insert into blog(id,title) values(14,‘test‘);
3、查询
Select * from blog;
分别在server_1和server_2上执行查询语句
server_1返回的结果是:
server_2返回的结果是:
如果查询TESTDB逻辑数据库的话,出现的结果是:
好,到此大功告成,作为入门篇非常简单。
开启端口8066
[root@localhost ~]# firewall-cmd --zone=public --add-port=8066/tcp --permanent
重启防火墙
[root@localhost ~]# firewall-cmd –reload
Navicat for MySQL连接
http://blog.csdn.net/testcs_dn/article/details/51438216 这篇主要参考环境配置
http://maosheng.iteye.com/blog/2306937 这篇文章主要参考它的简单配置schema.xml
http://www.jb51.net/article/114290.htm 这篇文章主要参考它的简单配置schema.xml
mysql+mycat分片环境部署
标签:add-port 64位 防火墙 pass 重启 部署安装 页面 ima 好的