• MyCAT+MySQL 搭建高可用企业级数据库集群——第2章 MyCat入门


    • 2-1 章节综述
    • 2-2 什么是MyCat
    • 2-3 什么是数据库中间层
    • 2-4 MyCat的主要作用
    • 2-5 MyCat基本元素
    • 2-6 MyCat的安装

    2-1 章节综述

    1、掌握Mycat的基础概念、功能及适用场景;

    2、掌握Mycat的安装和启动;

    2-2 什么是MyCat

    1、不同的工种对Mycat的不同理解;

    • 研发人员;

    • 架构师;

    2、实现“读写分离”的两种方式;

    • 从程序的角度实现,配置两套数据源;
    • 通过中间件的角度实现,比如Mycat;

    2-3 什么是数据库中间层

    1、数据库中间层初识;

    2-4 MyCat的主要作用

    1、作为分布式数据库中间层使用(关系型与菲关系型均可);

    2、实现后端数据库的读写分离及负载均衡;

    3、在数据库中,一般读请求操作远高于写请求操作;

    4、改下图所示的,仅适用于“一主一从”的MySQL数据库架构;

    5、实现“一主多从”的MySQL高可用,需要通过MHA或者3M的方式实现;

    6、对业务数据库进行垂直切分;

    7、使用Mycat的好处,将后端对应的真实数据库,作为一个“逻辑库”;

    8、对业务数据库进行水平切分(分库分表);

    9、切分逻辑,通过Mycat;

    10、控制数据库连接的数量;

    • 当连接数占满后,所有新请求将无法再连接,影响业务;
    • 通过Mycat中间件,建立一个公共的“数据库连接池”;

     

    2-5 MyCat基本元素

    1、逻辑库&逻辑表概念回顾;

    2、逻辑表的分类;

    • 分片表
    • 全局表
    • ER关系表

    2-6 MyCat的安装

    1、下载并解压Mycat;

    wget http://dl.mycat.io/1.6.5/Mycat-server-1.6.5-release-20180122220033-linux.tar.gz

    2、安装JAVA运行环境JDK1.7或之上版本;

    wget http://download.oracle.com/otn/java/jdk/7u80-b15/jdk-7u80-linux-x64.tar.gz?AuthParam=1527933488_83c1bdc9836fadfe600eceed8afc9a1c

    3、新建Mycat运行系统账号;

    useradd mycat

    chown -R mycat:mycat /usr/local/mycat

    4、配置系统环境变量;

    vim /etc/profile#修改系统环境变量;

    export MyCAT_HOME=/usr/local/mycat
    export JAVA_HOME=/usr/local/jdk1.7.0_80
    export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib
    export PATH=$MyCAT_HOME/bin:$JAVA_HOME/bin:$PATH

    source /etc/profile

    5、修改mycat启动参数;

    vim /usr/local/mycat/conf/wrapper.conf#调整mycat内存大小;

     日志:

    [BEGIN] 2018/6/2 17:55:10
    [root@iZqmo9i3j77p7eZ ~]# cd /usr/local/src/
    [root@iZqmo9i3j77p7eZ src]# wget http://dl.mycat.io/1.6.5/Mycat-server-1.6.5-release-20180122220033-linux.tar.gz
    --2018-06-02 17:55:20--  http://dl.mycat.io/1.6.5/Mycat-server-1.6.5-release-20180122220033-linux.tar.gz
    Resolving dl.mycat.io (dl.mycat.io)... 210.51.26.184
    Connecting to dl.mycat.io (dl.mycat.io)|210.51.26.184|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 17480035 (17M) [application/octet-stream]
    Saving to: ‘Mycat-server-1.6.5-release-20180122220033-linux.tar.gz’
    
    100%[====================================================================================================================================================================================================================================>] 17,480,035   507KB/s   in 34s    
    
    2018-06-02 17:55:55 (502 KB/s) - ‘Mycat-server-1.6.5-release-20180122220033-linux.tar.gz’ saved [17480035/17480035]
    [root@iZqmo9i3j77p7eZ src]# wget http://download.oracle.com/otn/java/jdk/7u80-b15/jdk-7u80-linux-x64.tar.gz?AuthParam=1527933488_83c1bdc9836fadfe600eceed8afc9a1c
    --2018-06-02 17:56:35--  http://download.oracle.com/otn/java/jdk/7u80-b15/jdk-7u80-linux-x64.tar.gz?AuthParam=1527933488_83c1bdc9836fadfe600eceed8afc9a1c
    Resolving download.oracle.com (download.oracle.com)... 23.218.25.93
    Connecting to download.oracle.com (download.oracle.com)|23.218.25.93|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 153530841 (146M) [application/x-gzip]
    Saving to: ‘jdk-7u80-linux-x64.tar.gz?AuthParam=1527933488_83c1bdc9836fadfe600eceed8afc9a1c’
    
    100%[====================================================================================================================================================================================================================================>] 153,530,841 5.96MB/s   in 24s    
    
    2018-06-02 17:57:00 (6.08 MB/s) - ‘jdk-7u80-linux-x64.tar.gz?AuthParam=1527933488_83c1bdc9836fadfe600eceed8afc9a1c’ saved [153530841/153530841]
    
    [root@iZqmo9i3j77p7eZ src]# rpm -qa|grep java
    [root@iZqmo9i3j77p7eZ src]# ll
    total 167008
    -rw-r--r-- 1 root root 153530841 Jul  8  2015 jdk-7u80-linux-x64.tar.gz?AuthParam=1527933488_83c1bdc9836fadfe600eceed8afc9a1c
    -rw-r--r-- 1 root root  17480035 Jan 22 22:07 Mycat-server-1.6.5-release-20180122220033-linux.tar.gz
    [root@iZqmo9i3j77p7eZ src]# mv jdk-7u80-linux-x64.tar.gz?AuthParam=1527933488_83c1bdc9836fadfe600eceed8afc9a1c jdk-7u80-linux-x64.tar.gz
    [root@iZqmo9i3j77p7eZ src]# tar zxf jdk-7u80-linux-x64.tar.gz -C /usr/local/
    [root@iZqmo9i3j77p7eZ src]# vim /etc/profile
    [root@iZqmo9i3j77p7eZ src]# source /etc/profile
    [root@iZqmo9i3j77p7eZ src]# java
    Usage: java [-options] class [args...]
               (to execute a class)
       or  java [-options] -jar jarfile [args...]
               (to execute a jar file)
    where options include:
        -d32      use a 32-bit data model if available
        -d64      use a 64-bit data model if available
        -server      to select the "server" VM
                      The default VM is server.
    
        -cp <class search path of directories and zip/jar files>
        -classpath <class search path of directories and zip/jar files>
                      A : separated list of directories, JAR archives,
                      and ZIP archives to search for class files.
        -D<name>=<value>
                      set a system property
        -verbose:[class|gc|jni]
                      enable verbose output
        -version      print product version and exit
        -version:<value>
                      require the specified version to run
        -showversion  print product version and continue
        -jre-restrict-search | -no-jre-restrict-search
                      include/exclude user private JREs in the version search
        -? -help      print this help message
        -X            print help on non-standard options
        -ea[:<packagename>...|:<classname>]
        -enableassertions[:<packagename>...|:<classname>]
                      enable assertions with specified granularity
        -da[:<packagename>...|:<classname>]
        -disableassertions[:<packagename>...|:<classname>]
                      disable assertions with specified granularity
        -esa | -enablesystemassertions
                      enable system assertions
        -dsa | -disablesystemassertions
                      disable system assertions
        -agentlib:<libname>[=<options>]
                      load native agent library <libname>, e.g. -agentlib:hprof
                      see also, -agentlib:jdwp=help and -agentlib:hprof=help
        -agentpath:<pathname>[=<options>]
                      load native agent library by full pathname
        -javaagent:<jarpath>[=<options>]
                      load Java programming language agent, see java.lang.instrument
        -splash:<imagepath>
                      show splash screen with specified image
    See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
    [root@iZqmo9i3j77p7eZ src]# javac
    Usage: javac <options> <source files>
    where possible options include:
      -g                         Generate all debugging info
      -g:none                    Generate no debugging info
      -g:{lines,vars,source}     Generate only some debugging info
      -nowarn                    Generate no warnings
      -verbose                   Output messages about what the compiler is doing
      -deprecation               Output source locations where deprecated APIs are used
      -classpath <path>          Specify where to find user class files and annotation processors
      -cp <path>                 Specify where to find user class files and annotation processors
      -sourcepath <path>         Specify where to find input source files
      -bootclasspath <path>      Override location of bootstrap class files
      -extdirs <dirs>            Override location of installed extensions
      -endorseddirs <dirs>       Override location of endorsed standards path
      -proc:{none,only}          Control whether annotation processing and/or compilation is done.
      -processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
      -processorpath <path>      Specify where to find annotation processors
      -d <directory>             Specify where to place generated class files
      -s <directory>             Specify where to place generated source files
      -implicit:{none,class}     Specify whether or not to generate class files for implicitly referenced files
      -encoding <encoding>       Specify character encoding used by source files
      -source <release>          Provide source compatibility with specified release
      -target <release>          Generate class files for specific VM version
      -version                   Version information
      -help                      Print a synopsis of standard options
      -Akey[=value]              Options to pass to annotation processors
      -X                         Print a synopsis of nonstandard options
      -J<flag>                   Pass <flag> directly to the runtime system
      -Werror                    Terminate compilation if warnings occur
      @<filename>                Read options and filenames from file
    
    [root@iZqmo9i3j77p7eZ src]# java -version
    java version "1.7.0_80"
    Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
    [root@iZqmo9i3j77p7eZ src]# ll
    total 167008
    -rw-r--r-- 1 root root 153530841 Jul  8  2015 jdk-7u80-linux-x64.tar.gz
    -rw-r--r-- 1 root root  17480035 Jan 22 22:07 Mycat-server-1.6.5-release-20180122220033-linux.tar.gz
    [root@iZqmo9i3j77p7eZ src]# tar xf  Mycat-server-1.6.5-release-20180122220033-linux.tar.gz -C /usr/local/
    [root@iZqmo9i3j77p7eZ src]# cd /usr/local/
    [root@iZqmo9i3j77p7eZ local]# ls
    aegis  bin  etc  games  include  jdk1.7.0_80  lib  lib64  libexec  mycat  sbin  share  src
    [root@iZqmo9i3j77p7eZ local]# ll
    total 52
    drwxr-xr-x  6 root root 4096 May 30 10:25 aegis
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 bin
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 etc
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 games
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 include
    drwxr-xr-x  8   10  143 4096 Apr 11  2015 jdk1.7.0_80
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 lib
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 lib64
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 libexec
    drwxr-xr-x  7 root root 4096 Jun  2 17:58 mycat
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 sbin
    drwxr-xr-x. 6 root root 4096 May 26 11:18 share
    drwxr-xr-x. 2 root root 4096 Jun  2 17:57 src
    [root@iZqmo9i3j77p7eZ local]# useradd mycat
    [root@iZqmo9i3j77p7eZ local]# ll
    total 52
    drwxr-xr-x  6 root root 4096 May 30 10:25 aegis
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 bin
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 etc
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 games
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 include
    drwxr-xr-x  8   10  143 4096 Apr 11  2015 jdk1.7.0_80
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 lib
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 lib64
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 libexec
    drwxr-xr-x  7 root root 4096 Jun  2 17:58 mycat
    drwxr-xr-x. 2 root root 4096 Nov  5  2016 sbin
    drwxr-xr-x. 6 root root 4096 May 26 11:18 share
    drwxr-xr-x. 2 root root 4096 Jun  2 17:57 src
    [root@iZqmo9i3j77p7eZ local]# chown -R mycat:mycat mycat/
    [root@iZqmo9i3j77p7eZ local]# cd mycat/
    [root@iZqmo9i3j77p7eZ mycat]# ls -l
    total 24
    drwxr-xr-x 2 mycat mycat 4096 Jun  2 17:58 bin
    drwxrwxrwx 2 mycat mycat 4096 Mar  1  2016 catlet
    drwxrwxrwx 4 mycat mycat 4096 Jun  2 17:58 conf
    drwxr-xr-x 2 mycat mycat 4096 Jun  2 17:58 lib
    drwxrwxrwx 2 mycat mycat 4096 Jan 22 22:01 logs
    -rwxrwxrwx 1 mycat mycat  219 Jan 22 22:00 version.txt
    [root@iZqmo9i3j77p7eZ mycat]# cd bin/
    [root@iZqmo9i3j77p7eZ bin]# ls
    dataMigrate.sh  init_zk_data.sh  mycat  rehash.sh  startup_nowrap.sh  wrapper-linux-ppc-64  wrapper-linux-x86-32  wrapper-linux-x86-64
    [root@iZqmo9i3j77p7eZ bin]# cd /usr/local/mycat/conf/
    [root@iZqmo9i3j77p7eZ conf]# ls -l
    total 108
    -rwxrwxrwx 1 mycat mycat   88 Jan 22 22:00 autopartition-long.txt
    -rwxrwxrwx 1 mycat mycat   48 Jan 22 22:00 auto-sharding-long.txt
    -rwxrwxrwx 1 mycat mycat   62 Jan 22 22:00 auto-sharding-rang-mod.txt
    -rwxrwxrwx 1 mycat mycat  334 Jan 22 22:00 cacheservice.properties
    -rwxrwxrwx 1 mycat mycat 3244 Jan 22 22:00 dbseq.sql
    -rwxrwxrwx 1 mycat mycat  439 Jan 22 22:00 ehcache.xml
    -rwxrwxrwx 1 mycat mycat 2132 Jan 22 22:00 index_to_charset.properties
    -rwxrwxrwx 1 mycat mycat 1253 Dec  1  2016 log4j2.xml
    -rwxrwxrwx 1 mycat mycat  178 Jan 22 22:00 migrateTables.properties
    -rwxrwxrwx 1 mycat mycat  262 Jan 22 22:00 myid.properties
    -rwxrwxrwx 1 mycat mycat   15 Jan 22 22:00 partition-hash-int.txt
    -rwxrwxrwx 1 mycat mycat  102 Jan 22 22:00 partition-range-mod.txt
    -rwxrwxrwx 1 mycat mycat 4794 Jan 22 22:00 rule.xml
    -rwxrwxrwx 1 mycat mycat 4219 Jan 22 22:00 schema.xml
    -rwxrwxrwx 1 mycat mycat  413 Jan 22 22:00 sequence_conf.properties
    -rwxrwxrwx 1 mycat mycat   75 Jan 22 22:00 sequence_db_conf.properties
    -rwxrwxrwx 1 mycat mycat   27 Jan 22 22:00 sequence_distributed_conf.properties
    -rwxrwxrwx 1 mycat mycat   51 Jan 22 22:00 sequence_time_conf.properties
    -rwxrwxrwx 1 mycat mycat 4623 Jan 22 22:00 server.xml
    -rwxrwxrwx 1 mycat mycat   16 Jan 22 22:00 sharding-by-enum.txt
    -rwxrwxrwx 1 mycat mycat 4186 Jan 22 22:05 wrapper.conf
    drwxrwxrwx 2 mycat mycat 4096 Jun  2 17:58 zkconf
    drwxrwxrwx 2 mycat mycat 4096 Jun  2 17:58 zkdownload
    [root@iZqmo9i3j77p7eZ conf]# vim wrapper.conf 
    -rwxrwxrwx 1 mycat mycat 4623 Jan 22 22:00 server.xml
    -rwxrwxrwx 1 mycat mycat   16 Jan 22 22:00 sharding-by-enum.txt
    -rwxrwxrwx 1 mycat mycat 4186 Jan 22 22:05 wrapper.conf
    drwxrwxrwx 2 mycat mycat 4096 Jun  2 17:58 zkconf
    drwxrwxrwx 2 mycat mycat 4096 Jun  2 17:58 zkdownload
    [root@iZqmo9i3j77p7eZ bin]# vim /etc/profile
    [root@iZqmo9i3j77p7eZ bin]# source /etc/profile
    [root@iZqmo9i3j77p7eZ bin]# mycat
    Usage: /usr/local/mycat/bin/mycat { console | start | stop | restart | status | dump }
    [root@iZqmo9i3j77p7eZ bin]# mycat status
    Mycat-server is not running.
    [root@iZqmo9i3j77p7eZ bin]# mycat start
    Starting Mycat-server...
    View Code
  • 相关阅读:
    不错的电影(先收藏着)
    getchar() getch() getche() gets() puts() scanf()的用法及区别
    java反射获取字段的属性值,以及为字段赋值等方法
    oracle将查询结果横转纵
    关于MySQL 的LEFT JOIN ON的问题
    MySQL表名和数据库关键字相同解决办法
    ajax 后台正常执行 错误类型却是404
    BIT 树状数组 详解 及 例题
    HDU 2689 Sort it (树状数组)
    HDU Cow Sorting (树状数组)
  • 原文地址:https://www.cnblogs.com/tqtl911/p/9101305.html
Copyright © 2020-2023  润新知