环境搭建(一主两从):
macat: 192.168.8.30
master:192.168.8.31
slave1: 192.168.8.32
slave2: 192.168.8.33
工具包:
java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64
Mycat-server-1.6.6.1-release-20181031195535-linux.tar.gz
一、安装JDK和MyCat
系统已安装JDK,查看安装路径
[root@mycat ~]# java -version openjdk version "1.8.0_161" OpenJDK Runtime Environment (build 1.8.0_161-b14) OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
[root@mycat ~]# ls -l /usr/bin/java lrwxrwxrwx. 1 root root 22 Oct 22 10:30 /usr/bin/java -> /etc/alternatives/java
[root@mycat ~]# ls -l /etc/alternatives/java lrwxrwxrwx. 1 root root 71 Oct 22 10:30 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64/jre/bin/java
安装MyCat
cd /software tar zxvf Mycat-server-1.6.6.1-release-20181031195535-linux.tar.gz cp -r mycat /usr/local/
配置环境变量
[root@mycat ~]# cat ~/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64 export JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64/jre export MYCAT_HOME=/usr/local/mycat PATH=$PATH:/mysql/app/mysql/bin:/mysql/app/xtrabackup/bin:$HOME/bin:/usr/bin:/sbin:/bin:$MYCAT_HOME/bin:$JAVA_HOME/bin export PATH
二、创建测试库
master创建,slave同步
create database testdb1; create table testdb1.t11(name1 varchar(40),name2 varchar(40),name3 varchar(40)); create database testdb2; create table testdb2.t21(name1 varchar(40),name2 varchar(40),name3 varchar(40)); create database testdb3; create table testdb3.t31(name1 varchar(40),name2 varchar(40),name3 varchar(40));
三、配置schema.xml
<?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/"> <schema name="mycatdb1" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn1"></schema> <schema name="mycatdb2" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn2"></schema> <schema name="mycatdb3" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn3"></schema> <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743" /> --> <dataNode name="dn1" dataHost="localhost1" database="testdb1" /> <dataNode name="dn2" dataHost="localhost1" database="testdb2" /> <dataNode name="dn3" dataHost="localhost1" database="testdb3" /> <!--<dataNode name="dn4" dataHost="sequoiadb1" database="SAMPLE" /> <dataNode name="jdbc_dn1" dataHost="jdbchost" d